Search in sources :

Example 31 with ConcurrentLinkedDeque

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());
    }
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Example 32 with ConcurrentLinkedDeque

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;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Date(java.util.Date) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LongAdder(java.util.concurrent.atomic.LongAdder) Random(java.util.Random) ExecutorService(java.util.concurrent.ExecutorService) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure)

Example 33 with ConcurrentLinkedDeque

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) {
    }
}
Also used : ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 34 with ConcurrentLinkedDeque

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));
}
Also used : ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 35 with ConcurrentLinkedDeque

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());
}
Also used : ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Aggregations

ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)209 Test (org.junit.Test)21 NoSuchElementException (java.util.NoSuchElementException)16 Iterator (java.util.Iterator)14 Random (java.util.Random)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 Deque (java.util.Deque)7 ExecutorService (java.util.concurrent.ExecutorService)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IOException (java.io.IOException)4 List (java.util.List)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 BlockIdList (alluxio.grpc.BlockIdList)3 BlockStoreLocationProto (alluxio.grpc.BlockStoreLocationProto)3 LocationBlockIdListEntry (alluxio.grpc.LocationBlockIdListEntry)3