use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
observer.onError(new IOException());
observer.onComplete();
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verifyNoMoreInteractions();
assertTrue(d.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertUndeliverable(errors, 1, IOException.class);
});
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableTakeUntilTest method otherErrorLate.
@Test
public void otherErrorLate() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final AtomicReference<CompletableObserver> ref = new AtomicReference<>();
Completable.complete().takeUntil(new Completable() {
@Override
protected void subscribeActual(CompletableObserver observer) {
observer.onSubscribe(Disposable.empty());
ref.set(observer);
}
}).test().assertResult();
ref.get().onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method timestep.
@Test
public void timestep() {
TestScheduler scheduler = new TestScheduler();
final AtomicInteger counter = new AtomicInteger();
Completable result = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
TestObserver<Void> to = result.test();
scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
to.assertEmpty();
scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
to.assertResult();
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableDetachTest method errorDetaches.
@Test
public void errorDetaches() throws Exception {
Disposable d = Disposable.empty();
final WeakReference<Disposable> wr = new WeakReference<>(d);
TestObserver<Void> to = new Completable() {
@Override
protected void subscribeActual(CompletableObserver observer) {
observer.onSubscribe(wr.get());
observer.onError(new TestException());
observer.onError(new IOException());
}
}.onTerminateDetach().test();
d = null;
System.gc();
Thread.sleep(200);
to.assertFailure(TestException.class);
assertNull(wr.get());
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableFromCallableTest method fromCallableInvokesLazy.
@Test
public void fromCallableInvokesLazy() {
final AtomicInteger atomicInteger = new AtomicInteger();
Completable completable = Completable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
atomicInteger.incrementAndGet();
return null;
}
});
assertEquals(0, atomicInteger.get());
completable.test().assertResult();
assertEquals(1, atomicInteger.get());
}
Aggregations