Search in sources :

Example 96 with SynchronousQueue

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

the class SynchronousQueueTest method testDrainToWithActivePut.

public void testDrainToWithActivePut(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            q.put(one);
        }
    });
    ArrayList l = new ArrayList();
    long startTime = System.nanoTime();
    while (l.isEmpty()) {
        q.drainTo(l);
        if (millisElapsedSince(startTime) > LONG_DELAY_MS)
            fail("timed out");
        Thread.yield();
    }
    assertTrue(l.size() == 1);
    assertSame(one, l.get(0));
    awaitTermination(t);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ArrayList(java.util.ArrayList)

Example 97 with SynchronousQueue

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

the class SynchronousQueueTest method testContains.

public void testContains(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    assertFalse(q.contains(zero));
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

Example 98 with SynchronousQueue

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

the class SynchronousQueueTest method testContainsAll.

public void testContainsAll(boolean fair) {
    final SynchronousQueue q = new SynchronousQueue(fair);
    Integer[] empty = new Integer[0];
    assertTrue(q.containsAll(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 99 with SynchronousQueue

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

the class SynchronousQueueTest method testPutWithTake.

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

        public void realRun() throws InterruptedException {
            pleaseTake.countDown();
            q.put(one);
            pleaseInterrupt.countDown();
            try {
                q.put(99);
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(pleaseTake);
    assertEquals(0, q.remainingCapacity());
    try {
        assertSame(one, q.take());
    } catch (InterruptedException e) {
        threadUnexpectedException(e);
    }
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
    assertEquals(0, q.remainingCapacity());
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 100 with SynchronousQueue

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

the class SynchronousQueueTest method testOffer.

public void testOffer(boolean fair) {
    SynchronousQueue q = new SynchronousQueue(fair);
    assertFalse(q.offer(one));
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)120 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 ExecutorService (java.util.concurrent.ExecutorService)21 ThreadFactory (java.util.concurrent.ThreadFactory)15 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)13 ArrayList (java.util.ArrayList)12 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)10 IOException (java.io.IOException)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