Search in sources :

Example 31 with SynchronousQueue

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

the class SynchronousQueueTest method testRemove.

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

Example 32 with SynchronousQueue

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

the class SynchronousQueueTest method testRemoveAll.

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

Example 33 with SynchronousQueue

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

the class SynchronousQueueTest method testTimedPollWithOffer.

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

        public void realRun() throws InterruptedException {
            long startTime = System.nanoTime();
            assertNull(q.poll(timeoutMillis(), MILLISECONDS));
            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
            pleaseOffer.countDown();
            startTime = System.nanoTime();
            assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
            Thread.currentThread().interrupt();
            try {
                q.poll(LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            pleaseInterrupt.countDown();
            try {
                q.poll(LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
        }
    });
    await(pleaseOffer);
    long startTime = System.nanoTime();
    try {
        assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS));
    } catch (InterruptedException e) {
        threadUnexpectedException(e);
    }
    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 34 with SynchronousQueue

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

the class SynchronousQueueTest method testToArray.

public void testToArray(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    Object[] o = q.toArray();
    assertEquals(0, o.length);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

Example 35 with SynchronousQueue

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

the class SynchronousQueueTest method testToArray_null.

public void testToArray_null(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    try {
        Object[] o = q.toArray(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

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