File tree Expand file tree Collapse file tree 9 files changed +139
-42
lines changed
main/java/io/reactivex/internal/operators Expand file tree Collapse file tree 9 files changed +139
-42
lines changed Original file line number Diff line number Diff line change @@ -57,16 +57,12 @@ public void run() {
57
57
58
58
@ Override
59
59
public void onError (final Throwable e ) {
60
- if (delayError ) {
61
- set .add (scheduler .scheduleDirect (new Runnable () {
62
- @ Override
63
- public void run () {
64
- s .onError (e );
65
- }
66
- }, delay , unit ));
67
- } else {
68
- s .onError (e );
69
- }
60
+ set .add (scheduler .scheduleDirect (new Runnable () {
61
+ @ Override
62
+ public void run () {
63
+ s .onError (e );
64
+ }
65
+ }, delayError ? delay : 0 , unit ));
70
66
}
71
67
72
68
@ Override
Original file line number Diff line number Diff line change @@ -88,20 +88,16 @@ public void run() {
88
88
89
89
@ Override
90
90
public void onError (final Throwable t ) {
91
- if (delayError ) {
92
- w .schedule (new Runnable () {
93
- @ Override
94
- public void run () {
95
- try {
96
- actual .onError (t );
97
- } finally {
98
- w .dispose ();
99
- }
91
+ w .schedule (new Runnable () {
92
+ @ Override
93
+ public void run () {
94
+ try {
95
+ actual .onError (t );
96
+ } finally {
97
+ w .dispose ();
100
98
}
101
- }, delay , unit );
102
- } else {
103
- actual .onError (t );
104
- }
99
+ }
100
+ }, delayError ? delay : 0 , unit );
105
101
}
106
102
107
103
@ Override
Original file line number Diff line number Diff line change @@ -88,20 +88,16 @@ public void run() {
88
88
89
89
@ Override
90
90
public void onError (final Throwable t ) {
91
- if (delayError ) {
92
- w .schedule (new Runnable () {
93
- @ Override
94
- public void run () {
95
- try {
96
- actual .onError (t );
97
- } finally {
98
- w .dispose ();
99
- }
91
+ w .schedule (new Runnable () {
92
+ @ Override
93
+ public void run () {
94
+ try {
95
+ actual .onError (t );
96
+ } finally {
97
+ w .dispose ();
100
98
}
101
- }, delay , unit );
102
- } else {
103
- actual .onError (t );
104
- }
99
+ }
100
+ }, delayError ? delay : 0 , unit );
105
101
}
106
102
107
103
@ Override
Original file line number Diff line number Diff line change @@ -56,8 +56,13 @@ public void run() {
56
56
}
57
57
58
58
@ Override
59
- public void onError (Throwable e ) {
60
- s .onError (e );
59
+ public void onError (final Throwable e ) {
60
+ sd .replace (scheduler .scheduleDirect (new Runnable () {
61
+ @ Override
62
+ public void run () {
63
+ s .onError (e );
64
+ }
65
+ }, 0 , unit ));
61
66
}
62
67
63
68
});
Original file line number Diff line number Diff line change @@ -1602,7 +1602,8 @@ public void onComplete() {
1602
1602
1603
1603
@ Test (timeout = 1000 )
1604
1604
public void delayErrorImmediately () throws InterruptedException {
1605
- Completable c = error .completable .delay (250 , TimeUnit .MILLISECONDS );
1605
+ final TestScheduler scheduler = new TestScheduler ();
1606
+ final Completable c = error .completable .delay (250 , TimeUnit .MILLISECONDS , scheduler );
1606
1607
1607
1608
final AtomicBoolean done = new AtomicBoolean ();
1608
1609
final AtomicReference <Throwable > error = new AtomicReference <Throwable >();
@@ -1624,14 +1625,14 @@ public void onComplete() {
1624
1625
}
1625
1626
});
1626
1627
1628
+ scheduler .advanceTimeBy (100 , TimeUnit .MILLISECONDS );
1629
+
1627
1630
Assert .assertTrue (error .get ().toString (), error .get () instanceof TestException );
1628
1631
Assert .assertFalse ("Already done" , done .get ());
1629
1632
1630
- Thread . sleep (100 );
1633
+ scheduler . advanceTimeBy (100 , TimeUnit . MILLISECONDS );
1631
1634
1632
1635
Assert .assertFalse ("Already done" , done .get ());
1633
-
1634
- Thread .sleep (200 );
1635
1636
}
1636
1637
1637
1638
@ Test (timeout = 1000 )
Original file line number Diff line number Diff line change 13
13
14
14
package io .reactivex .internal .operators .completable ;
15
15
16
+ import java .util .concurrent .CountDownLatch ;
16
17
import java .util .concurrent .TimeUnit ;
18
+ import java .util .concurrent .atomic .AtomicReference ;
17
19
20
+ import io .reactivex .functions .Consumer ;
18
21
import org .junit .Test ;
19
22
20
23
import io .reactivex .Completable ;
21
24
import io .reactivex .schedulers .Schedulers ;
22
25
26
+ import static org .junit .Assert .assertNotEquals ;
27
+
23
28
public class CompletableDelayTest {
24
29
25
30
@ Test
@@ -30,4 +35,27 @@ public void delayCustomScheduler() {
30
35
.test ()
31
36
.assertResult ();
32
37
}
38
+
39
+ @ Test
40
+ public void testOnErrorCalledOnScheduler () throws Exception {
41
+ final CountDownLatch latch = new CountDownLatch (1 );
42
+ final AtomicReference <Thread > thread = new AtomicReference <Thread >();
43
+
44
+ Completable .<String >error (new Exception ())
45
+ .delay (0 , TimeUnit .MILLISECONDS , Schedulers .newThread ())
46
+ .doOnError (new Consumer <Throwable >() {
47
+ @ Override
48
+ public void accept (Throwable throwable ) throws Exception {
49
+ thread .set (Thread .currentThread ());
50
+ latch .countDown ();
51
+ }
52
+ })
53
+ .onErrorComplete ()
54
+ .subscribe ();
55
+
56
+ latch .await ();
57
+
58
+ assertNotEquals (Thread .currentThread (), thread .get ());
59
+ }
60
+
33
61
}
Original file line number Diff line number Diff line change 14
14
package io .reactivex .internal .operators .flowable ;
15
15
16
16
import static org .junit .Assert .assertEquals ;
17
+ import static org .junit .Assert .assertNotEquals ;
17
18
import static org .mockito .Matchers .*;
18
19
import static org .mockito .Mockito .*;
19
20
20
21
import java .util .*;
21
22
import java .util .concurrent .*;
22
23
import java .util .concurrent .atomic .AtomicBoolean ;
24
+ import java .util .concurrent .atomic .AtomicReference ;
23
25
24
26
import org .junit .*;
25
27
import org .mockito .InOrder ;
@@ -911,4 +913,26 @@ public void testDelaySubscriptionDisposeBeforeTime() {
911
913
verify (o , never ()).onError (any (Throwable .class ));
912
914
}
913
915
916
+ @ Test
917
+ public void testOnErrorCalledOnScheduler () throws Exception {
918
+ final CountDownLatch latch = new CountDownLatch (1 );
919
+ final AtomicReference <Thread > thread = new AtomicReference <Thread >();
920
+
921
+ Flowable .<String >error (new Exception ())
922
+ .delay (0 , TimeUnit .MILLISECONDS , Schedulers .newThread ())
923
+ .doOnError (new Consumer <Throwable >() {
924
+ @ Override
925
+ public void accept (Throwable throwable ) throws Exception {
926
+ thread .set (Thread .currentThread ());
927
+ latch .countDown ();
928
+ }
929
+ })
930
+ .onErrorResumeNext (Flowable .<String >empty ())
931
+ .subscribe ();
932
+
933
+ latch .await ();
934
+
935
+ assertNotEquals (Thread .currentThread (), thread .get ());
936
+ }
937
+
914
938
}
Original file line number Diff line number Diff line change 14
14
package io .reactivex .internal .operators .observable ;
15
15
16
16
import static org .junit .Assert .assertEquals ;
17
+ import static org .junit .Assert .assertNotEquals ;
17
18
import static org .mockito .Matchers .*;
18
19
import static org .mockito .Mockito .*;
19
20
20
21
import java .util .*;
21
22
import java .util .concurrent .*;
23
+ import java .util .concurrent .atomic .AtomicReference ;
22
24
23
25
import org .junit .*;
24
26
import org .mockito .InOrder ;
@@ -858,4 +860,27 @@ public void delayWithTimeDelayError() throws Exception {
858
860
.awaitDone (5 , TimeUnit .SECONDS )
859
861
.assertFailure (TestException .class , 1 );
860
862
}
863
+
864
+ @ Test
865
+ public void testOnErrorCalledOnScheduler () throws Exception {
866
+ final CountDownLatch latch = new CountDownLatch (1 );
867
+ final AtomicReference <Thread > thread = new AtomicReference <Thread >();
868
+
869
+ Observable .<String >error (new Exception ())
870
+ .delay (0 , TimeUnit .MILLISECONDS , Schedulers .newThread ())
871
+ .doOnError (new Consumer <Throwable >() {
872
+ @ Override
873
+ public void accept (Throwable throwable ) throws Exception {
874
+ thread .set (Thread .currentThread ());
875
+ latch .countDown ();
876
+ }
877
+ })
878
+ .onErrorResumeNext (Observable .<String >empty ())
879
+ .subscribe ();
880
+
881
+ latch .await ();
882
+
883
+ assertNotEquals (Thread .currentThread (), thread .get ());
884
+ }
885
+
861
886
}
Original file line number Diff line number Diff line change 14
14
package io .reactivex .internal .operators .single ;
15
15
16
16
import static org .junit .Assert .assertEquals ;
17
+ import static org .junit .Assert .assertNotEquals ;
17
18
19
+ import java .util .concurrent .CountDownLatch ;
18
20
import java .util .concurrent .TimeUnit ;
19
21
import java .util .concurrent .atomic .AtomicInteger ;
22
+ import java .util .concurrent .atomic .AtomicReference ;
20
23
24
+ import io .reactivex .functions .Consumer ;
21
25
import org .junit .Test ;
22
26
23
27
import io .reactivex .*;
@@ -103,4 +107,26 @@ public void delaySubscriptionTimeCustomScheduler() throws Exception {
103
107
.assertResult (1 );
104
108
}
105
109
110
+ @ Test
111
+ public void testOnErrorCalledOnScheduler () throws Exception {
112
+ final CountDownLatch latch = new CountDownLatch (1 );
113
+ final AtomicReference <Thread > thread = new AtomicReference <Thread >();
114
+
115
+ Single .<String >error (new Exception ())
116
+ .delay (0 , TimeUnit .MILLISECONDS , Schedulers .newThread ())
117
+ .doOnError (new Consumer <Throwable >() {
118
+ @ Override
119
+ public void accept (Throwable throwable ) throws Exception {
120
+ thread .set (Thread .currentThread ());
121
+ latch .countDown ();
122
+ }
123
+ })
124
+ .onErrorResumeNext (Single .just ("" ))
125
+ .subscribe ();
126
+
127
+ latch .await ();
128
+
129
+ assertNotEquals (Thread .currentThread (), thread .get ());
130
+ }
131
+
106
132
}
You can’t perform that action at this time.
0 commit comments