use of java.util.concurrent.atomic.AtomicLong in project disruptor by LMAX-Exchange.
the class WorkerPoolTest method shouldProcessOnlyOnceItHasBeenPublished.
@SuppressWarnings("unchecked")
@Test
public void shouldProcessOnlyOnceItHasBeenPublished() throws Exception {
Executor executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE);
WorkerPool<AtomicLong> pool = new WorkerPool<AtomicLong>(new AtomicLongEventFactory(), new FatalExceptionHandler(), new AtomicLongWorkHandler(), new AtomicLongWorkHandler());
RingBuffer<AtomicLong> ringBuffer = pool.start(executor);
ringBuffer.next();
ringBuffer.next();
Thread.sleep(1000);
assertThat(ringBuffer.get(0).get(), is(0L));
assertThat(ringBuffer.get(1).get(), is(0L));
}
use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.
the class CompletableTimerTest method timer.
@Test
public void timer() {
final TestScheduler testScheduler = new TestScheduler();
final AtomicLong atomicLong = new AtomicLong();
Completable.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Action() {
@Override
public void run() throws Exception {
atomicLong.incrementAndGet();
}
});
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(1, atomicLong.get());
}
use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.
the class FlowableAmbTest method testProducerRequestThroughAmb.
@SuppressWarnings("unchecked")
@Test
public void testProducerRequestThroughAmb() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);
ts.request(3);
final AtomicLong requested1 = new AtomicLong();
final AtomicLong requested2 = new AtomicLong();
Flowable<Integer> o1 = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
System.out.println("1-requested: " + n);
requested1.set(n);
}
@Override
public void cancel() {
}
});
}
});
Flowable<Integer> o2 = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
System.out.println("2-requested: " + n);
requested2.set(n);
}
@Override
public void cancel() {
}
});
}
});
Flowable.ambArray(o1, o2).subscribe(ts);
assertEquals(3, requested1.get());
assertEquals(3, requested2.get());
}
use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.
the class FlowableAmbTest method testSubscriptionOnlyHappensOnce.
@SuppressWarnings("unchecked")
@Test
public void testSubscriptionOnlyHappensOnce() throws InterruptedException {
final AtomicLong count = new AtomicLong();
Consumer<Subscription> incrementer = new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
count.incrementAndGet();
}
};
//this aync stream should emit first
Flowable<Integer> o1 = Flowable.just(1).doOnSubscribe(incrementer).delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation());
//this stream emits second
Flowable<Integer> o2 = Flowable.just(1).doOnSubscribe(incrementer).delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation());
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Flowable.ambArray(o1, o2).subscribe(ts);
ts.request(1);
ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
ts.assertNoErrors();
assertEquals(2, count.get());
}
use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.
the class FlowableSkipTest method testBackpressureMultipleSmallAsyncRequests.
@Test
public void testBackpressureMultipleSmallAsyncRequests() throws InterruptedException {
final AtomicLong requests = new AtomicLong(0);
TestSubscriber<Long> ts = new TestSubscriber<Long>(0L);
Flowable.interval(100, TimeUnit.MILLISECONDS).doOnRequest(new LongConsumer() {
@Override
public void accept(long n) {
requests.addAndGet(n);
}
}).skip(4).subscribe(ts);
Thread.sleep(100);
ts.request(1);
ts.request(1);
Thread.sleep(100);
ts.dispose();
// FIXME not assertable anymore
// ts.assertUnsubscribed();
ts.assertNoErrors();
assertEquals(6, requests.get());
}
Aggregations