/** * JUnit. * * @throws Exception If failed. */ public void testCollectionMethods() throws Exception { // Random queue name. String queueName = UUID.randomUUID().toString(); IgniteQueue<SameHashItem> queue = grid(0).queue(queueName, 0, config(false)); int retries = 100; // Initialize queue. for (int i = 0; i < retries; i++) queue.addAll( Arrays.asList( new SameHashItem(Integer.toString(i)), new SameHashItem(Integer.toString(i)))); // Get arrays from queue. assertEquals(retries * 2, queue.toArray().length); SameHashItem[] arr2 = new SameHashItem[retries * 3]; Object[] arr3 = queue.toArray(arr2); assertEquals(arr2, arr3); assertEquals(arr3[0], new SameHashItem("0")); // Check queue items. assertEquals(retries * 2, queue.size()); assertTrue(queue.contains(new SameHashItem(Integer.toString(14)))); assertFalse(queue.contains(new SameHashItem(Integer.toString(144)))); Collection<SameHashItem> col1 = Arrays.asList( new SameHashItem(Integer.toString(14)), new SameHashItem(Integer.toString(14)), new SameHashItem(Integer.toString(18))); assertTrue(queue.containsAll(col1)); Collection<SameHashItem> col2 = Arrays.asList( new SameHashItem(Integer.toString(245)), new SameHashItem(Integer.toString(14)), new SameHashItem(Integer.toString(18))); assertFalse(queue.containsAll(col2)); // Try to remove item. assertTrue(queue.remove(new SameHashItem(Integer.toString(14)))); assertEquals((retries * 2) - 1, queue.size()); assertTrue(queue.contains(new SameHashItem(Integer.toString(14)))); assertTrue(queue.remove(new SameHashItem(Integer.toString(14)))); assertEquals((retries - 1) * 2, queue.size()); assertFalse(queue.remove(new SameHashItem(Integer.toString(14)))); // Try to remove some items. assertTrue(queue.contains(new SameHashItem(Integer.toString(33)))); assertTrue( queue.removeAll( Arrays.asList( new SameHashItem(Integer.toString(15)), new SameHashItem(Integer.toString(14)), new SameHashItem(Integer.toString(33)), new SameHashItem(Integer.toString(1))))); assertFalse(queue.contains(new SameHashItem(Integer.toString(33)))); // Try to retain all items. assertTrue( queue.retainAll( Arrays.asList( new SameHashItem(Integer.toString(15)), new SameHashItem(Integer.toString(14)), new SameHashItem(Integer.toString(33)), new SameHashItem(Integer.toString(1))))); assertFalse(queue.contains(new SameHashItem(Integer.toString(2)))); assert queue.isEmpty(); }