Search in sources :

Example 6 with BooleanSupplier

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

the class QueueDrainHelperTest method postCompleteEmpty.

@Test
public void postCompleteEmpty() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    ArrayDeque<Integer> queue = new ArrayDeque<>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    };
    ts.onSubscribe(new BooleanSubscription());
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertResult();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.rxjava3.functions.BooleanSupplier) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 7 with BooleanSupplier

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

the class QueueDrainHelperTest method postCompleteCancelled.

@Test
public void postCompleteCancelled() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    ArrayDeque<Integer> queue = new ArrayDeque<>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return ts.isCancelled();
        }
    };
    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();
    ts.cancel();
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertEmpty();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.rxjava3.functions.BooleanSupplier) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 8 with BooleanSupplier

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

the class FlowableRetryTest method noCancelPreviousRetryUntil.

@Test
public void noCancelPreviousRetryUntil() {
    final AtomicInteger counter = new AtomicInteger();
    final AtomicInteger times = new AtomicInteger();
    Flowable<Integer> source = Flowable.defer(new Supplier<Flowable<Integer>>() {

        @Override
        public Flowable<Integer> get() throws Exception {
            if (times.getAndIncrement() < 4) {
                return Flowable.error(new TestException());
            }
            return Flowable.just(1);
        }
    }).doOnCancel(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    source.retryUntil(new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    }).test().assertResult(1);
    assertEquals(0, counter.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with BooleanSupplier

use of io.reactivex.rxjava3.functions.BooleanSupplier 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 10 with BooleanSupplier

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

the class ObservableRetryTest method noCancelPreviousRetryUntil.

@Test
public void noCancelPreviousRetryUntil() {
    final AtomicInteger counter = new AtomicInteger();
    final AtomicInteger times = new AtomicInteger();
    Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> get() throws Exception {
            if (times.getAndIncrement() < 4) {
                return Observable.error(new TestException());
            }
            return Observable.just(1);
        }
    }).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    source.retryUntil(new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    }).test().assertResult(1);
    assertEquals(0, counter.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 BooleanSupplier (io.reactivex.rxjava3.functions.BooleanSupplier)6 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 TestException (io.reactivex.rxjava3.exceptions.TestException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IOException (java.io.IOException)1