use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableIgnoreElementsTest method testErrorReceivedObservable.
@Test
public void testErrorReceivedObservable() {
TestObserver<Object> ts = new TestObserver<Object>();
TestException ex = new TestException("boo");
Observable.error(ex).ignoreElements().toObservable().subscribe(ts);
ts.assertNoValues();
ts.assertTerminated();
// FIXME no longer testable
// ts.assertUnsubscribed();
ts.assertError(TestException.class);
ts.assertErrorMessage("boo");
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableWindowWithSizeTest method testWindowUnsubscribeNonOverlapping.
@Test
public void testWindowUnsubscribeNonOverlapping() {
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger count = new AtomicInteger();
Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
count.incrementAndGet();
}
}).window(5).take(2)).subscribe(ts);
ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS);
ts.assertTerminated();
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// System.out.println(ts.getOnNextEvents());
assertEquals(10, count.get());
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableWindowWithSizeTest method testWindowUnsubscribeNonOverlappingAsyncSource.
@Test
public void testWindowUnsubscribeNonOverlappingAsyncSource() {
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger count = new AtomicInteger();
Observable.merge(Observable.range(1, 100000).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
if (count.incrementAndGet() == 500000) {
// give it a small break halfway through
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
// ignored
}
}
}
}).observeOn(Schedulers.computation()).window(5).take(2)).subscribe(ts);
ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS);
ts.assertTerminated();
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// make sure we don't emit all values ... the unsubscribe should propagate
assertTrue(count.get() < 100000);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableWindowWithSizeTest method testWindowUnsubscribeOverlappingAsyncSource.
@Test
public void testWindowUnsubscribeOverlappingAsyncSource() {
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger count = new AtomicInteger();
Observable.merge(Observable.range(1, 100000).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
count.incrementAndGet();
}
}).observeOn(Schedulers.computation()).window(5, 4).take(2), 128).subscribe(ts);
ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS);
ts.assertTerminated();
ts.assertValues(1, 2, 3, 4, 5, 5, 6, 7, 8, 9);
// make sure we don't emit all values ... the unsubscribe should propagate
// assertTrue(count.get() < 100000); // disabled: a small hiccup in the consumption may allow the source to run to completion
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored.
@Test
@Ignore("s should be considered cancelled upon executing onError and not expect downstream to call cancel")
public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Disposable s = mock(Disposable.class);
Observable<String> immediatelyError = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(s);
observer.onError(new IOException("Error"));
}
});
TestScheduler testScheduler = new TestScheduler();
Observable<String> observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Observer<String> observer = TestHelper.mockObserver();
TestObserver<String> ts = new TestObserver<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onError(isA(IOException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).dispose();
}
Aggregations