use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableAllTest method predicateThrows.
@Test
public void predicateThrows() {
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.onNext(2);
observer.onError(new TestException());
observer.onComplete();
}
}.all(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).toFlowable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableDistinctUntilChangedTest method ignoreCancel.
@Test
public void ignoreCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onNext(3);
s.onError(new IOException());
s.onComplete();
}
}.distinctUntilChanged(new BiPredicate<Integer, Integer>() {
@Override
public boolean test(Integer a, Integer b) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class, 1);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableRetryWithPredicateTest method testRetryTwiceAndGiveUp.
@Test
public void testRetryTwiceAndGiveUp() {
Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> t1) {
t1.onSubscribe(new BooleanSubscription());
t1.onNext(0);
t1.onNext(1);
t1.onError(new TestException());
}
});
@SuppressWarnings("unchecked") DefaultSubscriber<Integer> o = mock(DefaultSubscriber.class);
InOrder inOrder = inOrder(o);
source.retry(retryTwice).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(0);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableRetryWithPredicateTest method testRetryTwice.
@Test
public void testRetryTwice() {
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 TestException());
return;
}
t1.onNext(2);
t1.onNext(3);
t1.onComplete();
}
});
@SuppressWarnings("unchecked") DefaultSubscriber<Integer> o = mock(DefaultSubscriber.class);
InOrder inOrder = inOrder(o);
source.retry(retryTwice).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 FlowableSampleTest method testSample.
@Test
public void testSample() {
Flowable<Long> source = Flowable.unsafeCreate(new Publisher<Long>() {
@Override
public void subscribe(final Subscriber<? super Long> observer1) {
observer1.onSubscribe(new BooleanSubscription());
innerScheduler.schedule(new Runnable() {
@Override
public void run() {
observer1.onNext(1L);
}
}, 1, TimeUnit.SECONDS);
innerScheduler.schedule(new Runnable() {
@Override
public void run() {
observer1.onNext(2L);
}
}, 2, TimeUnit.SECONDS);
innerScheduler.schedule(new Runnable() {
@Override
public void run() {
observer1.onComplete();
}
}, 3, TimeUnit.SECONDS);
}
});
Flowable<Long> sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(800L, TimeUnit.MILLISECONDS);
verify(observer, never()).onNext(any(Long.class));
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(1200L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(1L);
verify(observer, never()).onNext(2L);
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(1600L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(1L);
verify(observer, never()).onNext(2L);
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(1L);
inOrder.verify(observer, times(1)).onNext(2L);
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3000L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(1L);
inOrder.verify(observer, never()).onNext(2L);
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
Aggregations