use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishTest method subscribeDisconnectRace.
@Test
public void subscribeDisconnectRace() {
for (int i = 0; i < 500; i++) {
final PublishProcessor<Integer> ps = PublishProcessor.create();
final ConnectableFlowable<Integer> co = ps.publish();
final Disposable d = co.connect();
final TestSubscriber<Integer> to = new TestSubscriber<Integer>();
Runnable r1 = new Runnable() {
@Override
public void run() {
d.dispose();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
co.subscribe(to);
}
};
TestHelper.race(r1, r2);
}
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishTest method testSubscribeAfterDisconnectThenConnect.
@Test
public void testSubscribeAfterDisconnectThenConnect() {
ConnectableFlowable<Integer> source = Flowable.just(1).publish();
TestSubscriber<Integer> ts1 = new TestSubscriber<Integer>();
source.subscribe(ts1);
Disposable s = source.connect();
ts1.assertValue(1);
ts1.assertNoErrors();
ts1.assertTerminated();
TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>();
source.subscribe(ts2);
Disposable s2 = source.connect();
ts2.assertValue(1);
ts2.assertNoErrors();
ts2.assertTerminated();
System.out.println(s);
System.out.println(s2);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishTest method syncFusedObserveOn2.
@Test
public void syncFusedObserveOn2() {
ConnectableFlowable<Integer> co = Flowable.range(0, 1000).publish();
Flowable<Integer> obs = co.observeOn(ImmediateThinScheduler.INSTANCE);
for (int i = 0; i < 1000; i++) {
for (int j = 1; j < 6; j++) {
List<TestSubscriber<Integer>> tss = new ArrayList<TestSubscriber<Integer>>();
for (int k = 1; k < j; k++) {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
tss.add(ts);
obs.subscribe(ts);
}
Disposable s = co.connect();
for (TestSubscriber<Integer> ts : tss) {
ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
}
s.dispose();
}
}
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableFlatMapTest method testFlatMapSelectorMaxConcurrent.
@Test
public void testFlatMapSelectorMaxConcurrent() {
final int m = 4;
final AtomicInteger subscriptionCount = new AtomicInteger();
Flowable<Integer> source = Flowable.range(1, 10).flatMap(new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return composer(Flowable.range(t1 * 10, 2), subscriptionCount, m).subscribeOn(Schedulers.computation());
}
}, new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer t1, Integer t2) {
return t1 * 1000 + t2;
}
}, m);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
source.subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
Set<Integer> expected = new HashSet<Integer>(Arrays.asList(1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051, 6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101));
Assert.assertEquals(expected.size(), ts.valueCount());
System.out.println("--> testFlatMapSelectorMaxConcurrent: " + ts.values());
Assert.assertTrue(expected.containsAll(ts.values()));
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTimeoutTests 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 Subscription s = mock(Subscription.class);
Flowable<String> immediatelyError = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
subscriber.onError(new IOException("Error"));
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = immediatelyError.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(IOException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
Aggregations