Search in sources :

Example 51 with ConcurrentLinkedQueue

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

the class ConcurrentLinkedQueueTest method testPeek.

/**
     * peek returns next element, or null if empty
     */
public void testPeek() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.peek());
        assertEquals(i, q.poll());
        assertTrue(q.peek() == null || !q.peek().equals(i));
    }
    assertNull(q.peek());
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 52 with ConcurrentLinkedQueue

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

the class ConcurrentLinkedQueueTest method testToArray.

/**
     * toArray contains all elements in FIFO order
     */
public void testToArray() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    Object[] o = q.toArray();
    for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll());
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 53 with ConcurrentLinkedQueue

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

the class ConcurrentLinkedQueueTest method testRemoveElement.

/**
     * remove(x) removes x and returns true if present
     */
public void testRemoveElement() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 1; i < SIZE; i += 2) {
        assertTrue(q.contains(i));
        assertTrue(q.remove(i));
        assertFalse(q.contains(i));
        assertTrue(q.contains(i - 1));
    }
    for (int i = 0; i < SIZE; i += 2) {
        assertTrue(q.contains(i));
        assertTrue(q.remove(i));
        assertFalse(q.contains(i));
        assertFalse(q.remove(i + 1));
        assertFalse(q.contains(i + 1));
    }
    assertTrue(q.isEmpty());
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 54 with ConcurrentLinkedQueue

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

the class ConcurrentLinkedQueueTest method testRemove.

/**
     * remove removes next element, or throws NSEE if empty
     */
public void testRemove() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) NoSuchElementException(java.util.NoSuchElementException)

Example 55 with ConcurrentLinkedQueue

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

the class ConcurrentLinkedQueueTest method testIterator.

/**
     * iterator iterates through all elements
     */
public void testIterator() {
    ConcurrentLinkedQueue 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);
}
Also used : Iterator(java.util.Iterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Aggregations

ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)236 Test (org.junit.Test)102 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)56 Watermark (org.apache.flink.streaming.api.watermark.Watermark)52 KeyedOneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)43 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)40 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)40 CountDownLatch (java.util.concurrent.CountDownLatch)37 ArrayList (java.util.ArrayList)31 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)28 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)18 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)17 IOException (java.io.IOException)15 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)15 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)14 ExecutionException (java.util.concurrent.ExecutionException)13 ExecutorService (java.util.concurrent.ExecutorService)13 Map (java.util.Map)12 OperatorStateHandles (org.apache.flink.streaming.runtime.tasks.OperatorStateHandles)12 Iterator (java.util.Iterator)11