use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method testSwitchWithSubsequenceComplete.
@Test
public void testSwitchWithSubsequenceComplete() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, "one");
publishNext(observer, 100, "two");
}
}));
publishNext(observer, 130, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishCompleted(observer, 0);
}
}));
publishNext(observer, 150, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, "three");
}
}));
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyString());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("three");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class NotificationLiteTest method subscriptionNotification.
@Test
public void subscriptionNotification() {
Object o = NotificationLite.subscription(new BooleanSubscription());
assertEquals("NotificationLite.Subscription[BooleanSubscription(cancelled=false)]", o.toString());
assertFalse(NotificationLite.isError(o));
assertFalse(NotificationLite.isComplete(o));
assertFalse(NotificationLite.isDisposable(o));
assertTrue(NotificationLite.isSubscription(o));
assertNotNull(NotificationLite.getSubscription(o));
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class MaybeDelaySubscriptionTest method withPublisherCallAfterTerminalEvent.
@Test
public void withPublisherCallAfterTerminalEvent() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable<Integer> f = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onNext(1);
observer.onError(new TestException());
observer.onComplete();
observer.onNext(2);
}
};
Maybe.just(1).delaySubscription(f).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 ObservableRetryTest method testSourceObservableCallsUnsubscribe.
@Test
public void testSourceObservableCallsUnsubscribe() throws InterruptedException {
final AtomicInteger subsCount = new AtomicInteger(0);
final TestObserver<String> ts = new TestObserver<String>();
ObservableSource<String> onSubscribe = new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> s) {
BooleanSubscription bs = new BooleanSubscription();
// https://github.com/ReactiveX/RxJava/issues/1024
if (!bs.isCancelled()) {
subsCount.incrementAndGet();
s.onError(new RuntimeException("failed"));
// it unsubscribes the child directly
// this simulates various error/completion scenarios that could occur
// or just a source that proactively triggers cleanup
// FIXME can't unsubscribe child
// s.unsubscribe();
bs.cancel();
} else {
s.onError(new RuntimeException());
}
}
};
Observable.unsafeCreate(onSubscribe).retry(3).subscribe(ts);
// 1 + 3 retries
assertEquals(4, subsCount.get());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class EmptyComponentTest method normal.
@Test
public void normal() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestHelper.checkEnum(EmptyComponent.class);
EmptyComponent c = EmptyComponent.INSTANCE;
assertTrue(c.isDisposed());
c.request(10);
c.request(-10);
Disposable d = Disposables.empty();
c.onSubscribe(d);
assertTrue(d.isDisposed());
BooleanSubscription s = new BooleanSubscription();
c.onSubscribe(s);
assertTrue(s.isCancelled());
c.onNext(null);
c.onNext(1);
c.onComplete();
c.onError(new TestException());
c.onSuccess(2);
c.cancel();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations