Search in sources :

Example 81 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class ObservableRepeatTest method noCancelPreviousRepeatUntil.

@Test
public void noCancelPreviousRepeatUntil() {
    final AtomicInteger counter = new AtomicInteger();
    Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    final AtomicInteger times = new AtomicInteger();
    source.repeatUntil(new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return times.getAndIncrement() == 4;
        }
    }).test().assertResult(1, 1, 1, 1, 1);
    assertEquals(0, counter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 82 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class ObservableRepeatTest method noCancelPreviousRepeatWhen.

@Test
public void noCancelPreviousRepeatWhen() {
    final AtomicInteger counter = new AtomicInteger();
    Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    final AtomicInteger times = new AtomicInteger();
    source.repeatWhen(new Function<Observable<Object>, ObservableSource<?>>() {

        @Override
        public ObservableSource<?> apply(Observable<Object> e) throws Exception {
            return e.takeWhile(new Predicate<Object>() {

                @Override
                public boolean test(Object v) throws Exception {
                    return times.getAndIncrement() < 4;
                }
            });
        }
    }).test().assertResult(1, 1, 1, 1, 1);
    assertEquals(0, counter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable) Test(org.junit.Test)

Example 83 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class ObservableMergeWithCompletableTest method normal.

@Test
public void normal() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.range(1, 5).mergeWith(Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            to.onNext(100);
        }
    })).subscribe(to);
    to.assertResult(1, 2, 3, 4, 5, 100);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 84 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class MaybeTest method observeOnCompleteThread.

@Test
public void observeOnCompleteThread() {
    String main = Thread.currentThread().getName();
    final String[] name = { null };
    Maybe.empty().observeOn(Schedulers.single()).doOnComplete(new Action() {

        @Override
        public void run() throws Exception {
            name[0] = Thread.currentThread().getName();
        }
    }).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
    assertNotEquals(main, name[0]);
}
Also used : ArgsToString(io.reactivex.rxjava3.internal.operators.flowable.FlowableZipTest.ArgsToString) Test(org.junit.Test)

Example 85 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class FlowableConcatWithCompletableTest method normal.

@Test
public void normal() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    Flowable.range(1, 5).concatWith(Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            ts.onNext(100);
        }
    })).subscribe(ts);
    ts.assertResult(1, 2, 3, 4, 5, 100);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)109 TestException (io.reactivex.rxjava3.exceptions.TestException)64 Action (io.reactivex.rxjava3.functions.Action)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)9 IOException (java.io.IOException)9 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Observable (io.reactivex.rxjava3.core.Observable)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 Flowable (io.reactivex.rxjava3.core.Flowable)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3