@Test public void testOfferPoll() throws IOException, InterruptedException { final IQueue q = client.getQueue(queueForTestOfferPoll); for (int i = 0; i < 10; i++) { boolean result = q.offer("item"); if (i < maxSizeForQueue) { assertTrue(result); } else { assertFalse(result); } } assertEquals(maxSizeForQueue, q.size()); final Thread t1 = new Thread() { public void run() { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } q.poll(); } }; t1.start(); boolean result = q.offer("item", 5, TimeUnit.SECONDS); assertTrue(result); for (int i = 0; i < 10; i++) { Object o = q.poll(); if (i < maxSizeForQueue) { assertNotNull(o); } else { assertNull(o); } } assertEquals(0, q.size()); final Thread t2 = new Thread() { public void run() { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } q.offer("item1"); } }; t2.start(); Object o = q.poll(5, TimeUnit.SECONDS); assertEquals("item1", o); t1.join(10000); t2.join(10000); }
@Test public void testClear() { final int maxItems = 123; final IQueue q = client.getQueue(randomString()); for (int i = 0; i < maxItems; i++) { q.add(i); } assertEquals(maxItems, q.size()); q.clear(); assertEquals(0, q.size()); }
@Test public void testPeak() throws InterruptedException { final IQueue q = client.getQueue(randomString()); q.offer(1); assertEquals(1, q.peek()); assertEquals(1, q.peek()); assertEquals(1, q.size()); }
@Test public void testRetainEmptyList() throws IOException { final int maxItems = 131; final IQueue q = client.getQueue(randomString()); for (int i = 0; i < maxItems; i++) { q.add(i); } List retain = new LinkedList(); assertTrue(q.retainAll(retain)); assertEquals(0, q.size()); }
@Test public void testAddAll() throws IOException { final int maxItems = 13; final IQueue q = client.getQueue(randomString()); Collection coll = new ArrayList(maxItems); for (int i = 0; i < maxItems; i++) { coll.add(i); } assertTrue(q.addAll(coll)); assertEquals(coll.size(), q.size()); }
@Test public void testRemoveList_whereNotFound() throws IOException { final int maxItems = 131; final IQueue q = client.getQueue(randomString()); List removeList = new LinkedList(); for (int i = 0; i < maxItems; i++) { q.add(i); } removeList.add(maxItems + 1); removeList.add(maxItems + 2); assertFalse(q.removeAll(removeList)); assertEquals(maxItems, q.size()); }
@Test public void testadd() { final IQueue q = client.getQueue(randomString()); assertTrue(q.add(1)); assertEquals(1, q.size()); }