/** @throws Exception If failed. */ public void testPoll() throws Exception { ConcurrentLinkedDeque8<Integer> deque = new ConcurrentLinkedDeque8<>(); deque.add(1); deque.add(2); deque.add(3); assert !deque.isEmpty(); checkSize(deque, 3); // Poll 1. assertEquals(Integer.valueOf(1), deque.poll()); assert !deque.isEmpty(); checkSize(deque, 2); // Poll 2. assertEquals(Integer.valueOf(2), deque.poll()); assert !deque.isEmpty(); checkSize(deque, 1); // Poll 3. assertEquals(Integer.valueOf(3), deque.poll()); assert deque.isEmpty(); checkSize(deque, 0); }
public void testUnlinkWithIterator() { ConcurrentLinkedDeque8<Integer> q = new ConcurrentLinkedDeque8<>(); q.add(1); Node<Integer> n2 = q.addx(2); Node<Integer> n3 = q.addx(3); Node<Integer> n4 = q.addx(4); Node<Integer> n5 = q.addx(5); q.add(6); Iterator<Integer> it = q.iterator(); assertTrue(it.hasNext()); assertEquals(1, it.next().intValue()); assertTrue(it.hasNext()); assertEquals(2, it.next().intValue()); assertTrue(it.hasNext()); assertEquals(3, it.next().intValue()); q.unlinkx(n2); q.unlinkx(n3); q.unlinkx(n4); q.unlinkx(n5); assertTrue(it.hasNext()); assertEquals(4, it.next().intValue()); assertTrue(it.hasNext()); assertEquals(6, it.next().intValue()); }
/** {@inheritDoc} */ @Override public void record(GridEvent evt) throws GridSpiException { assert evt != null; // Filter out events. if (filter == null || filter.apply(evt)) { cleanupQueue(); evts.add(evt); // Make sure to filter out metrics updates to prevent log from flooding. if (evt.type() != EVT_NODE_METRICS_UPDATED && log.isDebugEnabled()) log.debug("Event recorded: " + evt); } }
public void testUnlinkLastWithIterator() { ConcurrentLinkedDeque8<Integer> q = new ConcurrentLinkedDeque8<>(); q.add(1); q.addx(2); Node<Integer> n3 = q.addx(3); Iterator<Integer> it = q.iterator(); assertTrue(it.hasNext()); assertEquals(1, it.next().intValue()); q.unlinkx(n3); assertTrue(it.hasNext()); assertEquals(2, it.next().intValue()); assertFalse(it.hasNext()); }