use of java.util.concurrent.ConcurrentLinkedDeque in project camel by apache.
the class DelayedMonoPublisherTest method testMultipleSubscribers.
@Test
public void testMultipleSubscribers() throws Exception {
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
ConcurrentLinkedDeque<Integer> data = new ConcurrentLinkedDeque<>();
CountDownLatch latch = new CountDownLatch(2);
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
Thread.sleep(200);
pub.setData(5);
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(2, data.size());
for (Integer n : data) {
assertEquals(5, n.intValue());
}
}
use of java.util.concurrent.ConcurrentLinkedDeque in project ignite by apache.
the class GridFutureListenPerformanceTest method main.
/**
* @param args Args.
* @throws InterruptedException If failed.
*/
public static void main(String[] args) throws InterruptedException {
final LongAdder cnt = new LongAdder();
final ConcurrentLinkedDeque<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque<>();
ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
Thread statThread = new Thread() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (!done) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
return;
}
System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5));
}
}
};
statThread.setDaemon(true);
statThread.start();
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
pool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (!done) {
for (int j = 0; j < rnd.nextInt(10); j++) {
GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
futs.add(fut);
for (int k = 1; k < rnd.nextInt(3); k++) {
fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() {
@Override
public void apply(IgniteInternalFuture<Object> t) {
try {
t.get();
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
cnt.increment();
}
});
}
}
GridFutureAdapter<Object> fut;
while ((fut = futs.poll()) != null) fut.onDone();
}
return null;
}
});
}
Thread.sleep(5 * 60 * 1000);
done = true;
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testToArray_NullArg.
/**
* toArray(null) throws NullPointerException
*/
public void testToArray_NullArg() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
try {
q.toArray(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testContainsAll.
/**
* containsAll(c) is true when c contains a subset of elements
*/
public void testContainsAll() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
ConcurrentLinkedDeque p = new ConcurrentLinkedDeque();
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(new Integer(i));
}
assertTrue(p.containsAll(q));
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testOffer.
/**
* offer(x) succeeds
*/
public void testOffer() {
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
assertTrue(q.offer(zero));
assertTrue(q.offer(one));
assertSame(zero, q.peekFirst());
assertSame(one, q.peekLast());
}
Aggregations