use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class TestSchedulerTest method immediateUnsubscribes.
@Test
public final void immediateUnsubscribes() {
TestScheduler s = new TestScheduler();
final Scheduler.Worker inner = s.createWorker();
final AtomicInteger counter = new AtomicInteger(0);
try {
inner.schedule(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
System.out.println("counter: " + counter.get());
inner.schedule(this);
}
});
inner.dispose();
assertEquals(0, counter.get());
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class TestSchedulerTest method immediateUnsubscribes2.
@Test
public final void immediateUnsubscribes2() {
TestScheduler s = new TestScheduler();
final Scheduler.Worker inner = s.createWorker();
try {
final AtomicInteger counter = new AtomicInteger(0);
final Disposable subscription = inner.schedule(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
System.out.println("counter: " + counter.get());
inner.schedule(this);
}
});
subscription.dispose();
assertEquals(0, counter.get());
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableDebounceTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onComplete();
observer.onNext(1);
observer.onError(new TestException());
observer.onComplete();
}
}.debounce(1, TimeUnit.SECONDS, new TestScheduler()).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableDebounceTest method debounceWithTimeBackpressure.
@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
TestObserverEx<Integer> observer = new TestObserverEx<>();
Observable.merge(Observable.just(1), Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(observer);
scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
observer.assertValue(2);
observer.assertTerminated();
observer.assertNoErrors();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableDebounceTest method before.
@Before
public void before() {
scheduler = new TestScheduler();
observer = TestHelper.mockObserver();
innerScheduler = scheduler.createWorker();
}
Aggregations