use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class ObservableCreateTest method onErrorCrash.
@Test
public void onErrorCrash() {
Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e) throws Exception {
Disposable d = Disposable.empty();
e.setDisposable(d);
try {
e.onError(new IOException());
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(d.isDisposed());
}
}).subscribe(new Observer<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Object value) {
}
@Override
public void onError(Throwable e) {
throw new TestException();
}
@Override
public void onComplete() {
}
});
}
use of io.reactivex.rxjava3.disposables.Disposable 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.disposables.Disposable 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);
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class ObservableBufferTest method openCloseBadClose.
@Test
public void openCloseBadClose() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Observable.never().buffer(Observable.just(1).concatWith(Observable.<Integer>never()), Functions.justFunction(new Observable<Object>() {
@Override
protected void subscribeActual(Observer<? super Object> observer) {
assertFalse(((Disposable) observer).isDisposed());
Disposable bs1 = Disposable.empty();
Disposable bs2 = Disposable.empty();
observer.onSubscribe(bs1);
assertFalse(bs1.isDisposed());
assertFalse(bs2.isDisposed());
observer.onSubscribe(bs2);
assertFalse(bs1.isDisposed());
assertTrue(bs2.isDisposed());
observer.onError(new IOException());
assertTrue(((Disposable) observer).isDisposed());
observer.onComplete();
observer.onNext(1);
observer.onError(new TestException());
}
})).test().assertFailure(IOException.class);
TestHelper.assertError(errors, 0, ProtocolViolationException.class);
TestHelper.assertUndeliverable(errors, 1, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method disposeNoNeedForResetSizeBound.
@Test
public void disposeNoNeedForResetSizeBound() {
PublishProcessor<Integer> pp = PublishProcessor.create();
ConnectableFlowable<Integer> cf = pp.replay(10, true);
TestSubscriber<Integer> ts = cf.test();
Disposable d = cf.connect();
pp.onNext(1);
d.dispose();
ts = cf.test();
ts.assertEmpty();
cf.connect();
ts.assertEmpty();
pp.onNext(2);
ts.assertValuesOnly(2);
}
Aggregations