use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableDebounceTest method testDebounceNeverEmits.
@Test
public void testDebounceNeverEmits() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
// all should be skipped since they are happening faster than the 200ms timeout
// Should be skipped
publishNext(observer, 100, "a");
// Should be skipped
publishNext(observer, 200, "b");
// Should be skipped
publishNext(observer, 300, "c");
// Should be skipped
publishNext(observer, 400, "d");
// Should be skipped
publishNext(observer, 500, "e");
// Should be skipped
publishNext(observer, 600, "f");
// Should be skipped
publishNext(observer, 700, "g");
// Should be skipped
publishNext(observer, 800, "h");
// Should be published as soon as the timeout expires.
publishCompleted(observer, 900);
}
});
Flowable<String> sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(0)).onNext(anyString());
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableDebounceTest method testDebounceWithError.
@Test
public void testDebounceWithError() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
Exception error = new TestException();
// Should be published since "two" will arrive after the timeout expires.
publishNext(observer, 100, "one");
// Should be skipped since onError will arrive before the timeout expires.
publishNext(observer, 600, "two");
// Should be published as soon as the timeout expires.
publishError(observer, 700, error);
}
});
Flowable<String> sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
// 100 + 400 means it triggers at 500
scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onNext("one");
scheduler.advanceTimeTo(701, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class CompletableConcatTest method overflowReported.
@Test
public void overflowReported() {
Completable.concat(Flowable.fromPublisher(new Publisher<Completable>() {
@Override
public void subscribe(Subscriber<? super Completable> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(Completable.never());
s.onNext(Completable.never());
s.onNext(Completable.never());
s.onNext(Completable.never());
s.onComplete();
}
}), 1).test().assertFailure(MissingBackpressureException.class);
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableDoOnEachTest method ignoreCancel.
@Test
public void ignoreCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Object>() {
@Override
public void subscribe(Subscriber<? super Object> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).doOnNext(new Consumer<Object>() {
@Override
public void accept(Object e) 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 FlowableDematerializeTest method eventsAfterDematerializedTerminal.
@Test
public void eventsAfterDematerializedTerminal() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Object>() {
@Override
protected void subscribeActual(Subscriber<? super Object> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onNext(Notification.createOnComplete());
observer.onNext(Notification.createOnNext(1));
observer.onNext(Notification.createOnError(new TestException("First")));
observer.onError(new TestException("Second"));
}
}.dematerialize().test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
TestHelper.assertUndeliverable(errors, 1, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
Aggregations