38
38
import rx .functions .Func1 ;
39
39
import rx .functions .Func2 ;
40
40
import rx .internal .util .RxRingBuffer ;
41
+ import rx .observables .GroupedObservable ;
41
42
import rx .observers .TestSubscriber ;
42
43
import rx .schedulers .Schedulers ;
43
44
import rx .subjects .PublishSubject ;
@@ -405,10 +406,14 @@ public static class FuncWithErrors implements Observable.OnSubscribe<String> {
405
406
public void call (Subscriber <? super String > o ) {
406
407
o .onNext ("beginningEveryTime" );
407
408
if (count .getAndIncrement () < numFailures ) {
409
+ System .out .println ("FuncWithErrors @ " + count .get ());
408
410
o .onError (new RuntimeException ("forced failure: " + count .get ()));
409
411
} else {
412
+ System .out .println ("FuncWithErrors @ onSuccessOnly" );
410
413
o .onNext ("onSuccessOnly" );
414
+ System .out .println ("FuncWithErrors @ onCompleted" );
411
415
o .onCompleted ();
416
+ System .out .println ("FuncWithErrors !" );
412
417
}
413
418
}
414
419
}
@@ -663,7 +668,7 @@ public void testTimeoutWithRetry() {
663
668
assertEquals ("Start 6 threads, retry 5 then fail on 6" , 6 , so .efforts .get ());
664
669
}
665
670
666
- @ Test
671
+ @ Test ( timeout = 3000 )
667
672
public void testRetryWithBackpressure () {
668
673
@ SuppressWarnings ("unchecked" )
669
674
Observer <String > observer = mock (Observer .class );
@@ -684,5 +689,90 @@ public void testRetryWithBackpressure() {
684
689
inOrder .verify (observer , times (1 )).onCompleted ();
685
690
inOrder .verifyNoMoreInteractions ();
686
691
}
692
+ @ Test (timeout = 3000 )
693
+ public void testIssue1900 () throws InterruptedException {
694
+ @ SuppressWarnings ("unchecked" )
695
+ Observer <String > observer = mock (Observer .class );
696
+ final int NUM_MSG = 1034 ;
697
+ final AtomicInteger count = new AtomicInteger ();
698
+
699
+ Observable <String > origin = Observable .range (0 , NUM_MSG )
700
+ .map (new Func1 <Integer , String >() {
701
+ @ Override
702
+ public String call (Integer t1 ) {
703
+ return "msg: " + count .incrementAndGet ();
704
+ }
705
+ });
706
+
707
+ origin .retry ()
708
+ .groupBy (new Func1 <String , String >() {
709
+ @ Override
710
+ public String call (String t1 ) {
711
+ return t1 ;
712
+ }
713
+ })
714
+ .flatMap (new Func1 <GroupedObservable <String ,String >, Observable <String >>() {
715
+ @ Override
716
+ public Observable <String > call (GroupedObservable <String , String > t1 ) {
717
+ return t1 .take (1 );
718
+ }
719
+ })
720
+ .unsafeSubscribe (new TestSubscriber <String >(observer ));
721
+
722
+ InOrder inOrder = inOrder (observer );
723
+ // should show 3 attempts
724
+ inOrder .verify (observer , times (NUM_MSG )).onNext (any (java .lang .String .class ));
725
+ // // should have no errors
726
+ inOrder .verify (observer , never ()).onError (any (Throwable .class ));
727
+ // should have a single success
728
+ //inOrder.verify(observer, times(1)).onNext("onSuccessOnly");
729
+ // should have a single successful onCompleted
730
+ inOrder .verify (observer , times (1 )).onCompleted ();
731
+ inOrder .verifyNoMoreInteractions ();
732
+ }
733
+ @ Test (timeout = 3000 )
734
+ public void testIssue1900SourceNotSupportingBackpressure () {
735
+ @ SuppressWarnings ("unchecked" )
736
+ Observer <String > observer = mock (Observer .class );
737
+ final int NUM_MSG = 1034 ;
738
+ final AtomicInteger count = new AtomicInteger ();
739
+
740
+ Observable <String > origin = Observable .create (new Observable .OnSubscribe <String >() {
741
+
742
+ @ Override
743
+ public void call (Subscriber <? super String > o ) {
744
+ for (int i =0 ; i <NUM_MSG ; i ++) {
745
+ o .onNext ("msg:" + count .incrementAndGet ());
746
+ }
747
+ o .onCompleted ();
748
+ }
749
+ });
750
+
751
+ origin .retry ()
752
+ .groupBy (new Func1 <String , String >() {
753
+ @ Override
754
+ public String call (String t1 ) {
755
+ return t1 ;
756
+ }
757
+ })
758
+ .flatMap (new Func1 <GroupedObservable <String ,String >, Observable <String >>() {
759
+ @ Override
760
+ public Observable <String > call (GroupedObservable <String , String > t1 ) {
761
+ return t1 .take (1 );
762
+ }
763
+ })
764
+ .unsafeSubscribe (new TestSubscriber <String >(observer ));
765
+
766
+ InOrder inOrder = inOrder (observer );
767
+ // should show 3 attempts
768
+ inOrder .verify (observer , times (NUM_MSG )).onNext (any (java .lang .String .class ));
769
+ // // should have no errors
770
+ inOrder .verify (observer , never ()).onError (any (Throwable .class ));
771
+ // should have a single success
772
+ //inOrder.verify(observer, times(1)).onNext("onSuccessOnly");
773
+ // should have a single successful onCompleted
774
+ inOrder .verify (observer , times (1 )).onCompleted ();
775
+ inOrder .verifyNoMoreInteractions ();
776
+ }
687
777
688
778
}
0 commit comments