use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableDelaySubscriptionTest method disposeMain.
@Test
public void disposeMain() {
CompletableSubject cs = CompletableSubject.create();
TestScheduler scheduler = new TestScheduler();
TestObserver<Void> to = cs.delaySubscription(1, TimeUnit.SECONDS, scheduler).test();
assertFalse(cs.hasObservers());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertTrue(cs.hasObservers());
to.dispose();
assertFalse(cs.hasObservers());
}
use of io.reactivex.rxjava3.observers.TestObserver 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.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableTimerTest method timerInterruptible.
@Test
public void timerInterruptible() throws Exception {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
try {
for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec, true) }) {
final AtomicBoolean interrupted = new AtomicBoolean();
TestObserver<Void> to = Completable.timer(1, TimeUnit.MILLISECONDS, s).doOnComplete(new Action() {
@Override
public void run() throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
interrupted.set(true);
}
}
}).test();
Thread.sleep(500);
to.dispose();
Thread.sleep(500);
assertTrue(s.getClass().getSimpleName(), interrupted.get());
}
} finally {
exec.shutdown();
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableMergeIterableTest method errorRace.
@Test
public void errorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishSubject<Integer> ps1 = PublishSubject.create();
final PublishSubject<Integer> ps2 = PublishSubject.create();
TestObserver<Void> to = Completable.merge(Arrays.asList(ps1.ignoreElements(), ps2.ignoreElements())).test();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
ps1.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ps2.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class FlowableSwitchMapCompletableTest method innerError.
@Test
public void innerError() {
PublishProcessor<Integer> pp = PublishProcessor.create();
CompletableSubject cs = CompletableSubject.create();
TestObserver<Void> to = pp.switchMapCompletable(Functions.justFunction(cs)).test();
assertTrue(pp.hasSubscribers());
assertFalse(cs.hasObservers());
pp.onNext(1);
assertTrue(cs.hasObservers());
to.assertEmpty();
cs.onError(new TestException());
to.assertFailure(TestException.class);
assertFalse(pp.hasSubscribers());
assertFalse(cs.hasObservers());
}
Aggregations