Search in sources :

Example 1 with Completable

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

the class CompletableFromRunnableTest method fromRunnableInvokesLazy.

@Test
public void fromRunnableInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromRunnable(new Runnable() {

        @Override
        public void run() {
            atomicInteger.incrementAndGet();
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Completable(io.reactivex.Completable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with Completable

use of io.reactivex.Completable in project rxjava2-jdbc by davidmoten.

the class DatabaseTest method testSelectDependsOnCompletable.

@Test
public void testSelectDependsOnCompletable() {
    Database db = db();
    Completable a = //
    db.update("update person set score=100 where name=?").parameters(//
    "FRED").counts().ignoreElements();
    //
    db.select("select score from person where name=?").parameters(//
    "FRED").dependsOn(//
    a).getAs(//
    Integer.class).test().assertValues(//
    100).assertComplete();
}
Also used : Completable(io.reactivex.Completable) Test(org.junit.Test)

Example 3 with Completable

use of io.reactivex.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());
}
Also used : Completable(io.reactivex.Completable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 4 with Completable

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

the class CompletableFromActionTest method fromActionInvokesLazy.

@Test
public void fromActionInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            atomicInteger.incrementAndGet();
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Completable(io.reactivex.Completable) Action(io.reactivex.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 5 with Completable

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

the class SchedulerWhenTest method testRaceConditions.

@Test(timeout = 1000)
public void testRaceConditions() {
    Scheduler comp = Schedulers.computation();
    Scheduler limited = comp.when(new Function<Flowable<Flowable<Completable>>, Completable>() {

        @Override
        public Completable apply(Flowable<Flowable<Completable>> t) {
            return Completable.merge(Flowable.merge(t, 10));
        }
    });
    merge(just(just(1).subscribeOn(limited).observeOn(comp)).repeat(1000)).blockingSubscribe();
}
Also used : Completable(io.reactivex.Completable) Scheduler(io.reactivex.Scheduler) TestScheduler(io.reactivex.schedulers.TestScheduler) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Aggregations

Completable (io.reactivex.Completable)6 Test (org.junit.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Flowable (io.reactivex.Flowable)1 Scheduler (io.reactivex.Scheduler)1 Action (io.reactivex.functions.Action)1 TestScheduler (io.reactivex.schedulers.TestScheduler)1