Search in sources :

Example 46 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testToString.

/**
     * toString contains toStrings of elements
     */
public void testToString() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    String s = q.toString();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 47 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testPut.

/**
     * all elements successfully put are contained
     */
public void testPut() throws InterruptedException {
    LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        Integer x = new Integer(i);
        q.put(x);
        assertTrue(q.contains(x));
    }
    assertEquals(0, q.remainingCapacity());
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 48 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testIterator.

/**
     * iterator iterates through all elements
     */
public void testIterator() throws InterruptedException {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
    it = q.iterator();
    for (i = 0; it.hasNext(); i++) assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
Also used : Iterator(java.util.Iterator) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 49 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testDrainToWithActivePut.

/**
     * drainTo empties full queue, unblocking a waiting put.
     */
public void testDrainToWithActivePut() throws InterruptedException {
    final LinkedBlockingQueue q = populatedQueue(SIZE);
    Thread t = new Thread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            q.put(new Integer(SIZE + 1));
        }
    });
    t.start();
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i));
    t.join();
    assertTrue(q.size() + l.size() >= SIZE);
}
Also used : ArrayList(java.util.ArrayList) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 50 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.

the class LinkedBlockingQueueTest method testDrainTo.

/**
     * drainTo(c) empties queue into another collection c
     */
public void testDrainTo() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(SIZE, l.size());
    for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i));
    q.add(zero);
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(zero));
    assertTrue(q.contains(one));
    l.clear();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(2, l.size());
    for (int i = 0; i < 2; ++i) assertEquals(l.get(i), new Integer(i));
}
Also used : ArrayList(java.util.ArrayList) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)259 Test (org.junit.Test)91 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)23 Emitter (io.socket.emitter.Emitter)19 JSONObject (org.json.JSONObject)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ThreadFactory (java.util.concurrent.ThreadFactory)16 ExecutorService (java.util.concurrent.ExecutorService)14 BlockingQueue (java.util.concurrent.BlockingQueue)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 List (java.util.List)12 URI (java.net.URI)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Intent (android.content.Intent)9 HashMap (java.util.HashMap)9 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)8 Map (java.util.Map)8 UUID (java.util.UUID)8