Search in sources :

Example 51 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong 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<Integer>();
    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.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.functions.BooleanSupplier) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 52 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.

the class QueueDrainHelperTest method postCompleteEmpty.

@Test
public void postCompleteEmpty() {
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    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.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.functions.BooleanSupplier) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 53 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.

the class BackpressureHelperTest method producedMore.

@Test
public void producedMore() {
    List<Throwable> list = TestHelper.trackPluginErrors();
    try {
        AtomicLong requested = new AtomicLong(1);
        assertEquals(0, BackpressureHelper.produced(requested, 2));
        TestHelper.assertError(list, 0, IllegalStateException.class, "More produced than requested: -1");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 54 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.

the class BackpressureHelperTest method capped.

@Test
public void capped() {
    final AtomicLong requested = new AtomicLong(Long.MIN_VALUE);
    assertEquals(Long.MIN_VALUE, BackpressureHelper.addCancel(requested, 1));
    assertEquals(Long.MIN_VALUE, BackpressureHelper.addCancel(requested, Long.MAX_VALUE));
    requested.set(0);
    assertEquals(0, BackpressureHelper.addCancel(requested, Long.MAX_VALUE));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.addCancel(requested, 1));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.addCancel(requested, Long.MAX_VALUE));
    requested.set(0);
    assertEquals(0, BackpressureHelper.add(requested, Long.MAX_VALUE));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.add(requested, 1));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.add(requested, Long.MAX_VALUE));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.produced(requested, 1));
    assertEquals(Long.MAX_VALUE, BackpressureHelper.produced(requested, Long.MAX_VALUE));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 55 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.

the class BackpressureHelperTest method requestProduceRace.

@Test
public void requestProduceRace() {
    final AtomicLong requested = new AtomicLong(1);
    for (int i = 0; i < 500; i++) {
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                BackpressureHelper.produced(requested, 1);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                BackpressureHelper.add(requested, 1);
            }
        };
        TestHelper.race(r1, r2, Schedulers.single());
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)2292 Test (org.junit.Test)986 ArrayList (java.util.ArrayList)300 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)273 IOException (java.io.IOException)254 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)250 List (java.util.List)222 HashMap (java.util.HashMap)212 Map (java.util.Map)209 CountDownLatch (java.util.concurrent.CountDownLatch)185 AtomicReference (java.util.concurrent.atomic.AtomicReference)174 HashSet (java.util.HashSet)106 Arrays (java.util.Arrays)101 File (java.io.File)99 Test (org.junit.jupiter.api.Test)98 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)95 Set (java.util.Set)94 TimeUnit (java.util.concurrent.TimeUnit)91 Collections (java.util.Collections)88 Random (java.util.Random)85