use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableToFutureTest method testCancellationDuringFutureGet.
@Test
public void testCancellationDuringFutureGet() throws Exception {
Future<Object> future = new Future<Object>() {
private AtomicBoolean isCancelled = new AtomicBoolean(false);
private AtomicBoolean isDone = new AtomicBoolean(false);
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
isCancelled.compareAndSet(false, true);
return true;
}
@Override
public boolean isCancelled() {
return isCancelled.get();
}
@Override
public boolean isDone() {
return isCancelled() || isDone.get();
}
@Override
public Object get() throws InterruptedException, ExecutionException {
Thread.sleep(500);
isDone.compareAndSet(false, true);
return "foo";
}
@Override
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return get();
}
};
Subscriber<Object> o = TestHelper.mockSubscriber();
TestSubscriber<Object> ts = new TestSubscriber<Object>(o);
Flowable<Object> futureObservable = Flowable.fromFuture(future);
futureObservable.subscribeOn(Schedulers.computation()).subscribe(ts);
Thread.sleep(100);
ts.dispose();
ts.assertNoErrors();
ts.assertNoValues();
ts.assertNotComplete();
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableStrictTest method badRequestOnNextRace.
@Test
public void badRequestOnNextRace() {
for (int i = 0; i < 500; i++) {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final PublishProcessor<Integer> pp = PublishProcessor.create();
final StrictSubscriber<Integer> s = new StrictSubscriber<Integer>(ts);
s.onSubscribe(new BooleanSubscription());
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
s.request(0);
}
};
TestHelper.race(r1, r2);
if (ts.valueCount() == 0) {
ts.assertFailure(IllegalArgumentException.class);
} else {
ts.assertValue(1).assertNoErrors().assertNotComplete();
}
}
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> never = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onError(isA(TimeoutException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherIfOnNextNotWithinTimeout.
@Test
public void shouldSwitchToOtherIfOnNextNotWithinTimeout() {
Flowable<String> other = Flowable.just("a", "b", "c");
Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
source.subscribe(ts);
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
underlyingSubject.onNext("One");
testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
underlyingSubject.onNext("Two");
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("One");
inOrder.verify(observer, times(1)).onNext("a");
inOrder.verify(observer, times(1)).onNext("b");
inOrder.verify(observer, times(1)).onNext("c");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
ts.dispose();
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTakeUntilPredicateTest method testErrorIncludesLastValueAsCause.
@Test
public void testErrorIncludesLastValueAsCause() {
TestSubscriber<String> ts = new TestSubscriber<String>();
final TestException e = new TestException("Forced failure");
Predicate<String> predicate = new Predicate<String>() {
@Override
public boolean test(String t) {
throw e;
}
};
Flowable.just("abc").takeUntil(predicate).subscribe(ts);
ts.assertTerminated();
ts.assertNotComplete();
ts.assertError(TestException.class);
// FIXME last cause value is not saved
// assertTrue(ts.errors().get(0).getCause().getMessage().contains("abc"));
}
Aggregations