Search in sources :

Example 41 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class CompletableDelaySubscriptionTest method timestepError.

@Test
public void timestepError() {
    TestScheduler scheduler = new TestScheduler();
    final AtomicInteger counter = new AtomicInteger();
    Completable result = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            counter.incrementAndGet();
            throw new TestException();
        }
    }).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
    TestObserver<Void> to = result.test();
    scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
    to.assertFailure(TestException.class);
    assertEquals(1, counter.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 42 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class CompletableDelaySubscriptionTest method disposeBeforeTime.

@Test
public void disposeBeforeTime() {
    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();
    to.assertEmpty();
    scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
    to.dispose();
    scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    assertEquals(0, counter.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 43 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class RxJavaPluginsTest method completableCreate.

@Test
public void completableCreate() {
    try {
        RxJavaPlugins.setOnCompletableAssembly(new Function<Completable, Completable>() {

            @Override
            public Completable apply(Completable t) {
                return new CompletableError(new TestException());
            }
        });
        Completable.complete().test().assertNoValues().assertNotComplete().assertError(TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    // make sure the reset worked
    Completable.complete().test().assertNoValues().assertNoErrors().assertComplete();
}
Also used : CompletableError(io.reactivex.rxjava3.internal.operators.completable.CompletableError) Test(org.junit.Test)

Example 44 with Completable

use of io.reactivex.rxjava3.core.Completable in project redisson by redisson.

the class RedissonRemoteServiceTest method testRx.

@Test
public void testRx() {
    RedissonRxClient r1 = Redisson.create(createConfig()).rxJava();
    r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
    RedissonRxClient r2 = Redisson.create(createConfig()).rxJava();
    RemoteInterfaceRx ri = r2.getRemoteService().get(RemoteInterfaceRx.class);
    Completable f = ri.voidMethod("someName", 100L);
    f.blockingAwait();
    Single<Long> resFuture = ri.resultMethod(100L);
    assertThat(resFuture.blockingGet()).isEqualTo(200);
    r1.shutdown();
    r2.shutdown();
}
Also used : Completable(io.reactivex.rxjava3.core.Completable) RedissonRxClient(org.redisson.api.RedissonRxClient) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)36 TestException (io.reactivex.rxjava3.exceptions.TestException)21 Action (io.reactivex.rxjava3.functions.Action)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 IOException (java.io.IOException)4 Completable (io.reactivex.rxjava3.core.Completable)3 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)3 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)3 Flowable (io.reactivex.rxjava3.core.Flowable)2 TestObserver (io.reactivex.rxjava3.observers.TestObserver)2 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Pattern (java.util.regex.Pattern)2 InOrder (org.mockito.InOrder)2 ConverterTest (io.reactivex.rxjava3.core.ConverterTest)1 Observable (io.reactivex.rxjava3.core.Observable)1 Observer (io.reactivex.rxjava3.core.Observer)1 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)1