Search in sources :

Example 16 with TestScheduler

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();
    }
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 17 with TestScheduler

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();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 18 with TestScheduler

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();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 19 with TestScheduler

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();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 20 with TestScheduler

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();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Aggregations

TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)92 Test (org.junit.Test)84 TestException (io.reactivex.rxjava3.exceptions.TestException)38 InOrder (org.mockito.InOrder)30 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)7 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestObserver (io.reactivex.rxjava3.observers.TestObserver)6 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 Action (io.reactivex.rxjava3.functions.Action)5 SchedulerWhen (io.reactivex.rxjava3.internal.schedulers.SchedulerWhen)4 Observable (io.reactivex.rxjava3.core.Observable)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 BaseObserveOnSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber)1 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)1 IOException (java.io.IOException)1