Skip to content

Commit

Permalink
test with observeOn
Browse files Browse the repository at this point in the history
  • Loading branch information
abersnaze committed Jun 1, 2016
1 parent d86bc3b commit 8f03b8e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/java/rx/internal/operators/OperatorValveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;

import rx.Observable;
import rx.Producer;
import rx.Scheduler;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;

public class OperatorValveTest {
Expand Down Expand Up @@ -131,6 +137,14 @@ public void test() {
order.verifyNoMoreInteractions();
}

@Test
public void testRequestError() {
TestSubscriber<Void> tSub = TestSubscriber.create(-1);
Exception e = new Exception();
Observable.<Void> error(e).pressureValve(Observable.<Boolean> never(), 10).subscribe(tSub);
tSub.assertError(e);
}

@Test
public void testDataError() {
TestSubscriber<Void> tSub = TestSubscriber.create();
Expand Down Expand Up @@ -160,4 +174,32 @@ public void testControlCompleteClosed() {
Observable.<Void> never().pressureValve(Observable.just(false), 10).subscribe(tSub);
tSub.assertError(IllegalStateException.class);
}

/*
@Test
public void testObserveOn() {
final AtomicLong counter = new AtomicLong();
Observable<Integer> range = Observable.range(0, Integer.MAX_VALUE);
Observable<Boolean> control = Observable.interval(1, TimeUnit.SECONDS).map(new Func1<Long, Boolean>() {
@Override
public Boolean call(Long i) {
System.out.println();
counter.set(0);
return i % 2 == 1;
}
});
long granularity = 10;
TestSubscriber<Integer> tSub = new TestSubscriber<Integer>();
range.pressureValve(control, granularity).observeOn(Schedulers.computation()).toBlocking().forEach(new Action1<Integer>() {
@Override
public void call(Integer t) {
System.out.print(counter.incrementAndGet()+ " \r");
}
});
}
public static void main(String[] args) {
new OperatorValveTest().testObserveOn();
}
*/
}

0 comments on commit 8f03b8e

Please sign in to comment.