use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableCacheTest method unsafeChildThrows.
@Test
@Ignore("RS subscribers should not throw")
public void unsafeChildThrows() {
final AtomicInteger count = new AtomicInteger();
Flowable<Integer> source = Flowable.range(1, 100).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
count.getAndIncrement();
}
}).cache();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
throw new TestException();
}
};
source.subscribe(ts);
Assert.assertEquals(100, count.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableDelaySubscriptionOtherTest method testNoSubscriptionIfOtherErrors.
@Test
public void testNoSubscriptionIfOtherErrors() {
PublishProcessor<Object> other = PublishProcessor.create();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Flowable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onError(new TestException());
Assert.assertEquals("Premature subscription", 0, subscribed.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableDoAfterTerminateTest method ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce.
@Test
public void ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce() throws Exception {
Action finallyAction = Mockito.mock(Action.class);
doThrow(new IllegalStateException()).when(finallyAction).run();
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
Flowable.just("value").doAfterTerminate(finallyAction).subscribe(testSubscriber);
testSubscriber.assertValue("value");
verify(finallyAction).run();
// Actual result:
// Not only IllegalStateException was swallowed
// But finallyAction was called twice!
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableOnBackpressureLatestTest method testAsynchronousDrop.
@Test
public void testAsynchronousDrop() throws InterruptedException {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1L) {
final Random rnd = new Random();
@Override
public void onNext(Integer t) {
super.onNext(t);
if (rnd.nextDouble() < 0.001) {
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
request(1);
}
};
int m = 100000;
Flowable.range(1, m).subscribeOn(Schedulers.computation()).onBackpressureLatest().observeOn(Schedulers.io()).subscribe(ts);
ts.awaitTerminalEvent(2, TimeUnit.SECONDS);
ts.assertTerminated();
int n = ts.values().size();
System.out.println("testAsynchronousDrop -> " + n);
Assert.assertTrue("All events received?", n < m);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishFunctionTest method oneStartOnly.
@Test
public void oneStartOnly() {
final AtomicInteger startCount = new AtomicInteger();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onStart() {
startCount.incrementAndGet();
}
};
PublishProcessor<Integer> ps = PublishProcessor.create();
ps.publish(new Function<Flowable<Integer>, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Flowable<Integer> o) {
return o.take(1);
}
}).subscribe(ts);
Assert.assertEquals(1, startCount.get());
}
Aggregations