File tree Expand file tree Collapse file tree 3 files changed +64
-12
lines changed
main/java/io/reactivex/internal/operators/flowable
test/java/io/reactivex/internal/operators/flowable Expand file tree Collapse file tree 3 files changed +64
-12
lines changed Original file line number Diff line number Diff line change @@ -411,7 +411,10 @@ public void clear() {
411
411
@ Override
412
412
public boolean isEmpty () {
413
413
Iterator <? extends R > it = current ;
414
- return (it != null && !it .hasNext ()) || queue .isEmpty ();
414
+ if (it == null ) {
415
+ return queue .isEmpty ();
416
+ }
417
+ return !it .hasNext ();
415
418
}
416
419
417
420
@ Nullable
Original file line number Diff line number Diff line change @@ -863,4 +863,55 @@ public void remove() {
863
863
864
864
ts .assertResult (1 );
865
865
}
866
+
867
+ @ Test
868
+ public void doubleShare () {
869
+ Iterable <Integer > it = Flowable .range (1 , 300 ).blockingIterable ();
870
+ Flowable .just (it , it )
871
+ .flatMapIterable (Functions .<Iterable <Integer >>identity ())
872
+ .share ()
873
+ .share ()
874
+ .count ()
875
+ .test ()
876
+ .assertResult (600L );
877
+ }
878
+
879
+ @ Test
880
+ public void multiShare () {
881
+ Iterable <Integer > it = Flowable .range (1 , 300 ).blockingIterable ();
882
+ for (int i = 0 ; i < 5 ; i ++) {
883
+ Flowable <Integer > f = Flowable .just (it , it )
884
+ .flatMapIterable (Functions .<Iterable <Integer >>identity ());
885
+
886
+ for (int j = 0 ; j < i ; j ++) {
887
+ f = f .share ();
888
+ }
889
+
890
+ f
891
+ .count ()
892
+ .test ()
893
+ .withTag ("Share: " + i )
894
+ .assertResult (600L );
895
+ }
896
+ }
897
+
898
+ @ Test
899
+ public void multiShareHidden () {
900
+ Iterable <Integer > it = Flowable .range (1 , 300 ).blockingIterable ();
901
+ for (int i = 0 ; i < 5 ; i ++) {
902
+ Flowable <Integer > f = Flowable .just (it , it )
903
+ .flatMapIterable (Functions .<Iterable <Integer >>identity ())
904
+ .hide ();
905
+
906
+ for (int j = 0 ; j < i ; j ++) {
907
+ f = f .share ();
908
+ }
909
+
910
+ f
911
+ .count ()
912
+ .test ()
913
+ .withTag ("Share: " + i )
914
+ .assertResult (600L );
915
+ }
916
+ }
866
917
}
Original file line number Diff line number Diff line change @@ -395,7 +395,7 @@ public void onNextCancelRace() {
395
395
for (int i = 0 ; i < 1000 ; i ++) {
396
396
final PublishProcessor <Integer > pp = PublishProcessor .create ();
397
397
final TestObserver <List <Integer >> ts = pp .toList ().test ();
398
-
398
+
399
399
Runnable r1 = new Runnable () {
400
400
@ Override
401
401
public void run () {
@@ -408,18 +408,17 @@ public void run() {
408
408
ts .cancel ();
409
409
}
410
410
};
411
-
411
+
412
412
TestHelper .race (r1 , r2 );
413
413
}
414
-
415
414
}
416
415
417
416
@ Test
418
417
public void onNextCancelRaceFlowable () {
419
418
for (int i = 0 ; i < 1000 ; i ++) {
420
419
final PublishProcessor <Integer > pp = PublishProcessor .create ();
421
420
final TestSubscriber <List <Integer >> ts = pp .toList ().toFlowable ().test ();
422
-
421
+
423
422
Runnable r1 = new Runnable () {
424
423
@ Override
425
424
public void run () {
@@ -432,20 +431,20 @@ public void run() {
432
431
ts .cancel ();
433
432
}
434
433
};
435
-
434
+
436
435
TestHelper .race (r1 , r2 );
437
436
}
438
-
437
+
439
438
}
440
439
441
440
@ Test
442
441
public void onCompleteCancelRaceFlowable () {
443
442
for (int i = 0 ; i < 1000 ; i ++) {
444
443
final PublishProcessor <Integer > pp = PublishProcessor .create ();
445
444
final TestSubscriber <List <Integer >> ts = pp .toList ().toFlowable ().test ();
446
-
445
+
447
446
pp .onNext (1 );
448
-
447
+
449
448
Runnable r1 = new Runnable () {
450
449
@ Override
451
450
public void run () {
@@ -458,14 +457,13 @@ public void run() {
458
457
ts .cancel ();
459
458
}
460
459
};
461
-
460
+
462
461
TestHelper .race (r1 , r2 );
463
-
462
+
464
463
if (ts .valueCount () != 0 ) {
465
464
ts .assertValue (Arrays .asList (1 ))
466
465
.assertNoErrors ();
467
466
}
468
467
}
469
-
470
468
}
471
469
}
You can’t perform that action at this time.
0 commit comments