@@ -483,7 +483,19 @@ public Integer call(Integer i) {
483
483
@ Override
484
484
public Observable <Integer > call (GroupedObservable <Integer , Integer > group ) {
485
485
if (group .getKey () == 0 ) {
486
- return group .observeOn (Schedulers .newThread ()).delay (200 , TimeUnit .MILLISECONDS );
486
+ return group .observeOn (Schedulers .newThread ()).map (new Func1 <Integer , Integer >() {
487
+
488
+ @ Override
489
+ public Integer call (Integer t ) {
490
+ try {
491
+ Thread .sleep (2 );
492
+ } catch (InterruptedException e ) {
493
+ e .printStackTrace ();
494
+ }
495
+ return t * 10 ;
496
+ }
497
+
498
+ });
487
499
} else {
488
500
return group .observeOn (Schedulers .newThread ());
489
501
}
@@ -493,6 +505,7 @@ public Observable<Integer> call(GroupedObservable<Integer, Integer> group) {
493
505
494
506
@ Override
495
507
public void onCompleted () {
508
+ System .out .println ("=> onCompleted" );
496
509
latch .countDown ();
497
510
}
498
511
@@ -516,6 +529,43 @@ public void onNext(Integer s) {
516
529
assertEquals (100 , eventCounter .get ());
517
530
}
518
531
532
+ @ Test
533
+ public void testCompletionIfInnerNotSubscribed () throws InterruptedException {
534
+ final CountDownLatch latch = new CountDownLatch (1 );
535
+ final AtomicInteger eventCounter = new AtomicInteger ();
536
+ Observable .range (0 , 100 )
537
+ .groupBy (new Func1 <Integer , Integer >() {
538
+
539
+ @ Override
540
+ public Integer call (Integer i ) {
541
+ return i % 2 ;
542
+ }
543
+ })
544
+ .subscribe (new Observer <GroupedObservable <Integer , Integer >>() {
545
+
546
+ @ Override
547
+ public void onCompleted () {
548
+ latch .countDown ();
549
+ }
550
+
551
+ @ Override
552
+ public void onError (Throwable e ) {
553
+ e .printStackTrace ();
554
+ latch .countDown ();
555
+ }
556
+
557
+ @ Override
558
+ public void onNext (GroupedObservable <Integer , Integer > s ) {
559
+ eventCounter .incrementAndGet ();
560
+ System .out .println ("=> " + s );
561
+ }
562
+ });
563
+ if (!latch .await (500 , TimeUnit .MILLISECONDS )) {
564
+ fail ("timed out - never got completion" );
565
+ }
566
+ assertEquals (2 , eventCounter .get ());
567
+ }
568
+
519
569
private static class Event {
520
570
int source ;
521
571
String message ;
0 commit comments