24
24
import static org .mockito .Mockito .never ;
25
25
import static org .mockito .Mockito .times ;
26
26
27
- import java .util .concurrent .CountDownLatch ;
28
- import java .util .concurrent .TimeUnit ;
29
- import java .util .concurrent .atomic .AtomicBoolean ;
30
- import java .util .concurrent .atomic .AtomicInteger ;
31
-
32
27
import org .junit .Test ;
33
28
import org .mockito .InOrder ;
34
29
import org .mockito .Mockito ;
35
30
36
31
import rx .Observable ;
37
32
import rx .Observable .OnSubscribe ;
38
- import rx .Notification ;
39
33
import rx .Observer ;
40
34
import rx .Subscriber ;
41
35
import rx .Subscription ;
49
43
import rx .subjects .PublishSubject ;
50
44
import rx .subscriptions .Subscriptions ;
51
45
46
+ import java .util .concurrent .CountDownLatch ;
47
+ import java .util .concurrent .TimeUnit ;
48
+ import java .util .concurrent .atomic .AtomicBoolean ;
49
+ import java .util .concurrent .atomic .AtomicInteger ;
50
+
52
51
public class OperatorRetryTest {
53
52
54
53
@ Test
@@ -73,15 +72,15 @@ public void call(Subscriber<? super String> t1) {
73
72
74
73
});
75
74
TestSubscriber <String > ts = new TestSubscriber <String >(consumer );
76
- producer .retryWhen (new Func1 <Observable <? extends Notification <?> >, Observable <?>>() {
75
+ producer .retryWhen (new Func1 <Observable <? extends Throwable >, Observable <?>>() {
77
76
78
77
@ Override
79
- public Observable <?> call (Observable <? extends Notification <?> > attempts ) {
78
+ public Observable <?> call (Observable <? extends Throwable > attempts ) {
80
79
// Worker w = Schedulers.computation().createWorker();
81
80
return attempts
82
- .map (new Func1 <Notification <?> , Tuple >() {
81
+ .map (new Func1 <Throwable , Tuple >() {
83
82
@ Override
84
- public Tuple call (Notification <?> n ) {
83
+ public Tuple call (Throwable n ) {
85
84
return new Tuple (new Long (1 ), n );
86
85
}})
87
86
.scan (new Func2 <Tuple , Tuple , Tuple >(){
@@ -94,7 +93,7 @@ public Tuple call(Tuple t, Tuple n) {
94
93
public Observable <Long > call (Tuple t ) {
95
94
System .out .println ("Retry # " +t .count );
96
95
return t .count > 20 ?
97
- Observable .<Long >error (t .n . getThrowable () ) :
96
+ Observable .<Long >error (t .n ) :
98
97
Observable .timer (t .count *1L , TimeUnit .MILLISECONDS );
99
98
}});
100
99
}
@@ -112,9 +111,9 @@ public Observable<Long> call(Tuple t) {
112
111
113
112
public static class Tuple {
114
113
Long count ;
115
- Notification <?> n ;
114
+ Throwable n ;
116
115
117
- Tuple (Long c , Notification <?> n ) {
116
+ Tuple (Long c , Throwable n ) {
118
117
count = c ;
119
118
this .n = n ;
120
119
}
@@ -147,15 +146,15 @@ public void testSchedulingNotificationHandler() {
147
146
int NUM_RETRIES = 2 ;
148
147
Observable <String > origin = Observable .create (new FuncWithErrors (NUM_RETRIES ));
149
148
TestSubscriber <String > subscriber = new TestSubscriber <String >(observer );
150
- origin .retryWhen (new Func1 <Observable <? extends Notification <?>> , Observable <? extends Notification <?> >>() {
149
+ origin .retryWhen (new Func1 <Observable <? extends Throwable > , Observable <?>>() {
151
150
@ Override
152
- public Observable <? extends Notification <?>> call (Observable <? extends Notification <?> > t1 ) {
153
- return t1 .observeOn (Schedulers .computation ()).map (new Func1 <Notification <?>, Notification <?> >() {
151
+ public Observable <?> call (Observable <? extends Throwable > t1 ) {
152
+ return t1 .observeOn (Schedulers .computation ()).map (new Func1 <Throwable , Void >() {
154
153
@ Override
155
- public Notification <?> call (Notification <?> t1 ) {
156
- return Notification . createOnNext ( null ) ;
154
+ public Void call (Throwable t1 ) {
155
+ return null ;
157
156
}
158
- }).startWith (Notification . createOnNext ( null ) );
157
+ }).startWith (( Void ) null );
159
158
}
160
159
}).subscribe (subscriber );
161
160
@@ -178,16 +177,16 @@ public void testOnNextFromNotificationHandler() {
178
177
Observer <String > observer = mock (Observer .class );
179
178
int NUM_RETRIES = 2 ;
180
179
Observable <String > origin = Observable .create (new FuncWithErrors (NUM_RETRIES ));
181
- origin .retryWhen (new Func1 <Observable <? extends Notification <?>> , Observable <? extends Notification <?> >>() {
180
+ origin .retryWhen (new Func1 <Observable <? extends Throwable > , Observable <?>>() {
182
181
@ Override
183
- public Observable <? extends Notification <?>> call (Observable <? extends Notification <?> > t1 ) {
184
- return t1 .map (new Func1 <Notification <?>, Notification <?> >() {
182
+ public Observable <?> call (Observable <? extends Throwable > t1 ) {
183
+ return t1 .map (new Func1 <Throwable , Void >() {
185
184
186
185
@ Override
187
- public Notification <?> call (Notification <?> t1 ) {
188
- return Notification . createOnNext ( null ) ;
186
+ public Void call (Throwable t1 ) {
187
+ return null ;
189
188
}
190
- }).startWith (Notification . createOnNext ( null ) );
189
+ }).startWith (( Void ) null );
191
190
}
192
191
}).subscribe (observer );
193
192
@@ -209,9 +208,9 @@ public void testOnCompletedFromNotificationHandler() {
209
208
Observer <String > observer = mock (Observer .class );
210
209
Observable <String > origin = Observable .create (new FuncWithErrors (1 ));
211
210
TestSubscriber <String > subscriber = new TestSubscriber <String >(observer );
212
- origin .retryWhen (new Func1 <Observable <? extends Notification <?>> , Observable <? extends Notification <?> >>() {
211
+ origin .retryWhen (new Func1 <Observable <? extends Throwable > , Observable <?>>() {
213
212
@ Override
214
- public Observable <? extends Notification <?>> call (Observable <? extends Notification <?> > t1 ) {
213
+ public Observable <?> call (Observable <? extends Throwable > t1 ) {
215
214
return Observable .empty ();
216
215
}
217
216
}).subscribe (subscriber );
@@ -229,9 +228,9 @@ public void testOnErrorFromNotificationHandler() {
229
228
@ SuppressWarnings ("unchecked" )
230
229
Observer <String > observer = mock (Observer .class );
231
230
Observable <String > origin = Observable .create (new FuncWithErrors (2 ));
232
- origin .retryWhen (new Func1 <Observable <? extends Notification <?>> , Observable <? extends Notification <?> >>() {
231
+ origin .retryWhen (new Func1 <Observable <? extends Throwable > , Observable <?>>() {
233
232
@ Override
234
- public Observable <? extends Notification <?>> call (Observable <? extends Notification <?> > t1 ) {
233
+ public Observable <?> call (Observable <? extends Throwable > t1 ) {
235
234
return Observable .error (new RuntimeException ());
236
235
}
237
236
}).subscribe (observer );
0 commit comments