|
19 | 19 | import static org.mockito.Mockito.inOrder;
|
20 | 20 | import static org.mockito.Mockito.mock;
|
21 | 21 |
|
| 22 | +import java.util.concurrent.TimeUnit; |
| 23 | +import java.util.concurrent.atomic.AtomicLong; |
| 24 | + |
22 | 25 | import org.junit.Test;
|
23 | 26 | import org.mockito.ArgumentCaptor;
|
24 | 27 | import org.mockito.InOrder;
|
25 | 28 |
|
26 | 29 | import rx.Observable;
|
27 | 30 | import rx.Producer;
|
| 31 | +import rx.Scheduler; |
28 | 32 | import rx.Subscriber;
|
29 | 33 | import rx.functions.Action1;
|
| 34 | +import rx.functions.Func1; |
30 | 35 | import rx.observers.TestSubscriber;
|
| 36 | +import rx.schedulers.Schedulers; |
31 | 37 | import rx.subjects.PublishSubject;
|
32 | 38 |
|
33 | 39 | public class OperatorValveTest {
|
@@ -131,6 +137,14 @@ public void test() {
|
131 | 137 | order.verifyNoMoreInteractions();
|
132 | 138 | }
|
133 | 139 |
|
| 140 | + @Test |
| 141 | + public void testRequestError() { |
| 142 | + TestSubscriber<Void> tSub = TestSubscriber.create(-1); |
| 143 | + Exception e = new Exception(); |
| 144 | + Observable.<Void> error(e).pressureValve(Observable.<Boolean> never(), 10).subscribe(tSub); |
| 145 | + tSub.assertError(e); |
| 146 | + } |
| 147 | + |
134 | 148 | @Test
|
135 | 149 | public void testDataError() {
|
136 | 150 | TestSubscriber<Void> tSub = TestSubscriber.create();
|
@@ -160,4 +174,32 @@ public void testControlCompleteClosed() {
|
160 | 174 | Observable.<Void> never().pressureValve(Observable.just(false), 10).subscribe(tSub);
|
161 | 175 | tSub.assertError(IllegalStateException.class);
|
162 | 176 | }
|
| 177 | + |
| 178 | + /* |
| 179 | + @Test |
| 180 | + public void testObserveOn() { |
| 181 | + final AtomicLong counter = new AtomicLong(); |
| 182 | + Observable<Integer> range = Observable.range(0, Integer.MAX_VALUE); |
| 183 | + Observable<Boolean> control = Observable.interval(1, TimeUnit.SECONDS).map(new Func1<Long, Boolean>() { |
| 184 | + @Override |
| 185 | + public Boolean call(Long i) { |
| 186 | + System.out.println(); |
| 187 | + counter.set(0); |
| 188 | + return i % 2 == 1; |
| 189 | + } |
| 190 | + }); |
| 191 | + long granularity = 10; |
| 192 | + TestSubscriber<Integer> tSub = new TestSubscriber<Integer>(); |
| 193 | + range.pressureValve(control, granularity).observeOn(Schedulers.computation()).toBlocking().forEach(new Action1<Integer>() { |
| 194 | + @Override |
| 195 | + public void call(Integer t) { |
| 196 | + System.out.print(counter.incrementAndGet()+ " \r"); |
| 197 | + } |
| 198 | + }); |
| 199 | + } |
| 200 | + |
| 201 | + public static void main(String[] args) { |
| 202 | + new OperatorValveTest().testObserveOn(); |
| 203 | + } |
| 204 | + */ |
163 | 205 | }
|
0 commit comments