Java Code Examples for java.util.concurrent.DelayQueue#drainTo()
The following examples show how to use
java.util.concurrent.DelayQueue#drainTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * drainTo(c) empties queue into another collection c */ public void testDrainTo() { DelayQueue q = new DelayQueue(); PDelay[] elems = new PDelay[SIZE]; for (int i = 0; i < SIZE; ++i) { elems[i] = new PDelay(i); q.add(elems[i]); } ArrayList l = new ArrayList(); q.drainTo(l); assertEquals(0, q.size()); for (int i = 0; i < SIZE; ++i) assertEquals(elems[i], l.get(i)); q.add(elems[0]); q.add(elems[1]); assertFalse(q.isEmpty()); assertTrue(q.contains(elems[0])); assertTrue(q.contains(elems[1])); l.clear(); q.drainTo(l); assertEquals(0, q.size()); assertEquals(2, l.size()); for (int i = 0; i < 2; ++i) assertEquals(elems[i], l.get(i)); }
Example 2
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * drainTo(c) empties queue into another collection c */ public void testDrainTo() { DelayQueue q = new DelayQueue(); PDelay[] elems = new PDelay[SIZE]; for (int i = 0; i < SIZE; ++i) { elems[i] = new PDelay(i); q.add(elems[i]); } ArrayList l = new ArrayList(); q.drainTo(l); assertEquals(0, q.size()); for (int i = 0; i < SIZE; ++i) assertEquals(elems[i], l.get(i)); q.add(elems[0]); q.add(elems[1]); assertFalse(q.isEmpty()); assertTrue(q.contains(elems[0])); assertTrue(q.contains(elems[1])); l.clear(); q.drainTo(l); assertEquals(0, q.size()); assertEquals(2, l.size()); for (int i = 0; i < 2; ++i) assertEquals(elems[i], l.get(i)); }
Example 3
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * drainTo empties queue */ public void testDrainToWithActivePut() throws InterruptedException { final DelayQueue q = populatedQueue(SIZE); Thread t = new Thread(new CheckedRunnable() { public void realRun() { q.put(new PDelay(SIZE + 1)); }}); t.start(); ArrayList l = new ArrayList(); q.drainTo(l); assertTrue(l.size() >= SIZE); t.join(); assertTrue(q.size() + l.size() >= SIZE); }
Example 4
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * drainTo(c, n) empties first min(n, size) elements of queue into c */ public void testDrainToN() { for (int i = 0; i < SIZE + 2; ++i) { DelayQueue q = populatedQueue(SIZE); ArrayList l = new ArrayList(); q.drainTo(l, i); int k = (i < SIZE) ? i : SIZE; assertEquals(SIZE - k, q.size()); assertEquals(k, l.size()); } }
Example 5
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * drainTo empties queue */ public void testDrainToWithActivePut() throws InterruptedException { final DelayQueue q = populatedQueue(SIZE); Thread t = new Thread(new CheckedRunnable() { public void realRun() { q.put(new PDelay(SIZE + 1)); }}); t.start(); ArrayList l = new ArrayList(); q.drainTo(l); assertTrue(l.size() >= SIZE); t.join(); assertTrue(q.size() + l.size() >= SIZE); }
Example 6
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * drainTo(c, n) empties first min(n, size) elements of queue into c */ public void testDrainToN() { for (int i = 0; i < SIZE + 2; ++i) { DelayQueue q = populatedQueue(SIZE); ArrayList l = new ArrayList(); q.drainTo(l, i); int k = (i < SIZE) ? i : SIZE; assertEquals(SIZE - k, q.size()); assertEquals(k, l.size()); } }