Search in sources :

Example 1 with BooleanSupplier

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

the class QueueDrainHelperTest method postCompleteWithRequest.

@Test
public void postCompleteWithRequest() {
    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());
    queue.offer(1);
    state.getAndIncrement();
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertResult(1);
}
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 2 with BooleanSupplier

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

the class QueueDrainHelperTest method completeRequestRace.

@Test
public void completeRequestRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<>();
        final ArrayDeque<Integer> queue = new ArrayDeque<>();
        final AtomicLong state = new AtomicLong();
        final BooleanSupplier isCancelled = new BooleanSupplier() {

            @Override
            public boolean getAsBoolean() throws Exception {
                return false;
            }
        };
        ts.onSubscribe(new BooleanSubscription());
        queue.offer(1);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                QueueDrainHelper.postCompleteRequest(1, ts, queue, state, isCancelled);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
            }
        };
        TestHelper.race(r1, r2);
        ts.assertResult(1);
    }
}
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 3 with BooleanSupplier

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

the class QueueDrainHelperTest method postCompleteAlreadyComplete.

@Test
public void postCompleteAlreadyComplete() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    Queue<Integer> q = new ArrayDeque<>();
    q.offer(1);
    AtomicLong state = new AtomicLong(QueueDrainHelper.COMPLETED_MASK);
    QueueDrainHelper.postComplete(ts, q, state, new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    });
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.rxjava3.functions.BooleanSupplier) IOException(java.io.IOException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 4 with BooleanSupplier

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

the class FlowableRepeatTest method noCancelPreviousRepeatUntil.

@Test
public void noCancelPreviousRepeatUntil() {
    final AtomicInteger counter = new AtomicInteger();
    Flowable<Integer> source = Flowable.just(1).doOnCancel(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 5 with BooleanSupplier

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

the class QueueDrainHelperTest method postCompleteCancelledAfterOne.

@Test
public void postCompleteCancelledAfterOne() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            cancel();
        }
    };
    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();
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertValue(1).assertNoErrors().assertNotComplete();
}
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)

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