use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableRetryWithPredicateTest method testRetryOnSpecificException.
@Test
public void testRetryOnSpecificException() {
Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {
int count;
@Override
public void subscribe(Subscriber<? super Integer> t1) {
t1.onSubscribe(new BooleanSubscription());
count++;
t1.onNext(0);
t1.onNext(1);
if (count == 1) {
t1.onError(new IOException());
return;
}
t1.onNext(2);
t1.onNext(3);
t1.onComplete();
}
});
@SuppressWarnings("unchecked") DefaultSubscriber<Integer> o = mock(DefaultSubscriber.class);
InOrder inOrder = inOrder(o);
source.retry(retryOnTestException).subscribe(o);
inOrder.verify(o).onNext(0);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(0);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(2);
inOrder.verify(o).onNext(3);
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableMapTest method sourceIgnoresCancel.
@Test
public void sourceIgnoresCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowablePublishTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onNext(1);
observer.onComplete();
observer.onNext(2);
observer.onError(new TestException());
observer.onComplete();
}
}.publish().autoConnect().test().assertResult(1);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method testThrottlingWithCompleted.
@Test
public void testThrottlingWithCompleted() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
// publish as it's first
publishNext(observer, 100, "one");
// skip as it's last within the first 400
publishNext(observer, 300, "two");
// publish
publishNext(observer, 900, "three");
// skip
publishNext(observer, 905, "four");
// Should be published as soon as the timeout expires.
publishCompleted(observer, 1000);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(0)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(0)).onNext("four");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout.
@Test
public void shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout() throws InterruptedException {
final CountDownLatch exit = new CountDownLatch(1);
final CountDownLatch timeoutSetuped = new CountDownLatch(1);
final Subscriber<String> observer = TestHelper.mockSubscriber();
final TestSubscriber<String> ts = new TestSubscriber<String>(observer);
new Thread(new Runnable() {
@Override
public void run() {
Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
try {
timeoutSetuped.countDown();
exit.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
subscriber.onNext("a");
subscriber.onComplete();
}
}).timeout(1, TimeUnit.SECONDS, testScheduler).subscribe(ts);
}
}).start();
timeoutSetuped.await();
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onError(isA(TimeoutException.class));
inOrder.verifyNoMoreInteractions();
// exit the thread
exit.countDown();
}
Aggregations