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();
}
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();
}
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();
}
}
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));
}
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());
}
}
Aggregations