use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SingleSubscribeTest method biConsumerDispose.
@Test
public void biConsumerDispose() {
PublishSubject<Integer> ps = PublishSubject.create();
Disposable d = ps.single(-99).subscribe(new BiConsumer<Object, Object>() {
@Override
public void accept(Object t1, Object t2) throws Exception {
}
});
assertFalse(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
assertFalse(ps.hasObservers());
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SingleCacheTest method crossCancelOnError.
@Test
public void crossCancelOnError() {
PublishSubject<Integer> ps = PublishSubject.create();
Single<Integer> cache = ps.single(-99).cache();
final TestSubscriber<Integer> ts1 = new TestSubscriber<>();
TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>() {
@Override
public void onError(Throwable t) {
super.onError(t);
ts1.cancel();
}
};
cache.toFlowable().subscribe(ts2);
cache.toFlowable().subscribe(ts1);
ps.onError(new TestException());
ts1.assertNoValues().assertNoErrors().assertNotComplete();
ts2.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class PublishSubjectTest method currentStateMethodsError.
@Test
public void currentStateMethodsError() {
PublishSubject<Object> as = PublishSubject.create();
assertFalse(as.hasThrowable());
assertFalse(as.hasComplete());
assertNull(as.getThrowable());
as.onError(new TestException());
assertTrue(as.hasThrowable());
assertFalse(as.hasComplete());
assertTrue(as.getThrowable() instanceof TestException);
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method noPrematureSubscription.
@Test
public void noPrematureSubscription() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> to = new TestObserver<>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.just(1).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(to);
to.assertNotComplete();
to.assertNoErrors();
to.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onNext(1);
Assert.assertEquals("No subscription", 1, subscribed.get());
to.assertValue(1);
to.assertNoErrors();
to.assertComplete();
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method noPrematureSubscriptionToError.
@Test
public void noPrematureSubscriptionToError() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> to = new TestObserver<>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(to);
to.assertNotComplete();
to.assertNoErrors();
to.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onComplete();
Assert.assertEquals("No subscription", 1, subscribed.get());
to.assertNoValues();
to.assertNotComplete();
to.assertError(TestException.class);
}
Aggregations