Search in sources :

Example 36 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project j2objc by google.

the class SynchronousQueueTest method testRetainAll.

public void testRetainAll(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    Integer[] empty = new Integer[0];
    assertFalse(q.retainAll(Arrays.asList(empty)));
    Integer[] ints = new Integer[1];
    ints[0] = zero;
    assertFalse(q.retainAll(Arrays.asList(ints)));
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

Example 37 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project j2objc by google.

the class SynchronousQueueTest method testOfferInExecutor.

public void testOfferInExecutor(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                assertFalse(q.offer(one));
                threadsStarted.await();
                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }
        });
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }
        });
    }
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService)

Example 38 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project j2objc by google.

the class SynchronousQueueTest method testTimedOffer.

public void testTimedOffer(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            long startTime = System.nanoTime();
            assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
            pleaseInterrupt.countDown();
            try {
                q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (InterruptedException success) {
            }
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 39 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project j2objc by google.

the class SynchronousQueueTest method testPeek.

public void testPeek(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    assertNull(q.peek());
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

Example 40 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project j2objc by google.

the class SynchronousQueueTest method testElement.

public void testElement(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    try {
        q.element();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)117 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)61 ExecutorService (java.util.concurrent.ExecutorService)20 ThreadFactory (java.util.concurrent.ThreadFactory)14 ArrayList (java.util.ArrayList)12 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)12 IOException (java.io.IOException)9 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)9 Test (org.junit.Test)9 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 BlockingQueue (java.util.concurrent.BlockingQueue)7 XMPPException (org.jivesoftware.smack.XMPPException)7 Future (java.util.concurrent.Future)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 List (java.util.List)4