@@ -399,8 +399,9 @@ public void call(final Subscriber<? super String> o) {
399
399
public void request (long n ) {
400
400
if (n == Long .MAX_VALUE ) {
401
401
o .onNext ("beginningEveryTime" );
402
- if (count .getAndIncrement () < numFailures ) {
403
- o .onError (new RuntimeException ("forced failure: " + count .get ()));
402
+ int i = count .getAndIncrement ();
403
+ if (i < numFailures ) {
404
+ o .onError (new RuntimeException ("forced failure: " + (i + 1 )));
404
405
} else {
405
406
o .onNext ("onSuccessOnly" );
406
407
o .onCompleted ();
@@ -411,8 +412,7 @@ public void request(long n) {
411
412
int i = count .getAndIncrement ();
412
413
if (i < numFailures ) {
413
414
o .onNext ("beginningEveryTime" );
414
- o .onError (new RuntimeException ("forced failure: " + count .get ()));
415
- req .decrementAndGet ();
415
+ o .onError (new RuntimeException ("forced failure: " + (i + 1 )));
416
416
} else {
417
417
do {
418
418
if (i == numFailures ) {
@@ -705,17 +705,18 @@ public void testRetryWithBackpressure() throws InterruptedException {
705
705
inOrder .verifyNoMoreInteractions ();
706
706
}
707
707
}
708
+
708
709
@ Test (timeout = 15000 )
709
710
public void testRetryWithBackpressureParallel () throws InterruptedException {
710
711
final int NUM_RETRIES = RxRingBuffer .SIZE * 2 ;
711
712
int ncpu = Runtime .getRuntime ().availableProcessors ();
712
- ExecutorService exec = Executors .newFixedThreadPool (Math .max (ncpu / 2 , 1 ));
713
+ ExecutorService exec = Executors .newFixedThreadPool (Math .max (ncpu / 2 , 2 ));
713
714
final AtomicInteger timeouts = new AtomicInteger ();
714
715
final Map <Integer , List <String >> data = new ConcurrentHashMap <Integer , List <String >>();
715
716
final Map <Integer , List <Throwable >> exceptions = new ConcurrentHashMap <Integer , List <Throwable >>();
716
717
final Map <Integer , Integer > completions = new ConcurrentHashMap <Integer , Integer >();
717
718
718
- int m = 2000 ;
719
+ int m = 5000 ;
719
720
final CountDownLatch cdl = new CountDownLatch (m );
720
721
for (int i = 0 ; i < m ; i ++) {
721
722
final int j = i ;
@@ -726,16 +727,17 @@ public void run() {
726
727
try {
727
728
Observable <String > origin = Observable .create (new FuncWithErrors (NUM_RETRIES ));
728
729
TestSubscriber <String > ts = new TestSubscriber <String >();
729
- origin .retry ().observeOn (Schedulers .computation ()).unsafeSubscribe (ts );
730
- ts .awaitTerminalEvent (2 , TimeUnit .SECONDS );
731
- if (ts .getOnNextEvents ().size () != NUM_RETRIES + 2 ) {
732
- data .put (j , ts .getOnNextEvents ());
730
+ origin .retry ()
731
+ .observeOn (Schedulers .computation ()).unsafeSubscribe (ts );
732
+ ts .awaitTerminalEvent (2500 , TimeUnit .MILLISECONDS );
733
+ if (ts .getOnCompletedEvents ().size () != 1 ) {
734
+ completions .put (j , ts .getOnCompletedEvents ().size ());
733
735
}
734
736
if (ts .getOnErrorEvents ().size () != 0 ) {
735
737
exceptions .put (j , ts .getOnErrorEvents ());
736
738
}
737
- if (ts .getOnCompletedEvents ().size () != 1 ) {
738
- completions .put (j , ts .getOnCompletedEvents (). size ());
739
+ if (ts .getOnNextEvents ().size () != NUM_RETRIES + 2 ) {
740
+ data .put (j , ts .getOnNextEvents ());
739
741
}
740
742
} catch (Throwable t ) {
741
743
timeouts .incrementAndGet ();
@@ -749,7 +751,16 @@ public void run() {
749
751
cdl .await ();
750
752
assertEquals (0 , timeouts .get ());
751
753
if (data .size () > 0 ) {
752
- fail ("Data content mismatch: " + data );
754
+ System .out .println (allSequenceFrequency (data ));
755
+ }
756
+ if (exceptions .size () > 0 ) {
757
+ System .out .println (exceptions );
758
+ }
759
+ if (completions .size () > 0 ) {
760
+ System .out .println (completions );
761
+ }
762
+ if (data .size () > 0 ) {
763
+ fail ("Data content mismatch: " + allSequenceFrequency (data ));
753
764
}
754
765
if (exceptions .size () > 0 ) {
755
766
fail ("Exceptions received: " + exceptions );
@@ -758,6 +769,45 @@ public void run() {
758
769
fail ("Multiple completions received: " + completions );
759
770
}
760
771
}
772
+ static <T > StringBuilder allSequenceFrequency (Map <Integer , List <T >> its ) {
773
+ StringBuilder b = new StringBuilder ();
774
+ for (Map .Entry <Integer , List <T >> e : its .entrySet ()) {
775
+ if (b .length () > 0 ) {
776
+ b .append (", " );
777
+ }
778
+ b .append (e .getKey ()).append ("={" );
779
+ b .append (sequenceFrequency (e .getValue ()));
780
+ b .append ("}" );
781
+ }
782
+ return b ;
783
+ }
784
+ static <T > StringBuilder sequenceFrequency (Iterable <T > it ) {
785
+ StringBuilder sb = new StringBuilder ();
786
+
787
+ Object prev = null ;
788
+ int cnt = 0 ;
789
+
790
+ for (Object curr : it ) {
791
+ if (sb .length () > 0 ) {
792
+ if (!curr .equals (prev )) {
793
+ if (cnt > 1 ) {
794
+ sb .append (" x " ).append (cnt );
795
+ cnt = 1 ;
796
+ }
797
+ sb .append (", " );
798
+ sb .append (curr );
799
+ } else {
800
+ cnt ++;
801
+ }
802
+ } else {
803
+ sb .append (curr );
804
+ cnt ++;
805
+ }
806
+ prev = curr ;
807
+ }
808
+
809
+ return sb ;
810
+ }
761
811
@ Test (timeout = 3000 )
762
812
public void testIssue1900 () throws InterruptedException {
763
813
@ SuppressWarnings ("unchecked" )
0 commit comments