use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class InternalTimerServiceImplTest method testRegisterEarlierProcessingTimerMovesPhysicalProcessingTimer.
/**
* Verify that registering a processing-time timer that is earlier than the existing timers
* removes the one physical timer and creates one for the earlier timestamp {@link
* ProcessingTimeService}.
*/
@Test
public void testRegisterEarlierProcessingTimerMovesPhysicalProcessingTimer() throws Exception {
@SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class);
TestKeyContext keyContext = new TestKeyContext();
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimerServiceImpl<Integer, String> timerService = createAndStartInternalTimerService(mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, createQueueFactory());
int key = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
keyContext.setCurrentKey(key);
timerService.registerProcessingTimeTimer("ciao", 20);
assertEquals(1, timerService.numProcessingTimeTimers());
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(20L));
timerService.registerProcessingTimeTimer("ciao", 10);
assertEquals(2, timerService.numProcessingTimeTimers());
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(10L));
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class InternalTimerServiceImplTest method testCurrentProcessingTime.
@Test
public void testCurrentProcessingTime() throws Exception {
@SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class);
TestKeyContext keyContext = new TestKeyContext();
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimerServiceImpl<Integer, String> timerService = createAndStartInternalTimerService(mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, createQueueFactory());
processingTimeService.setCurrentTime(17L);
assertEquals(17, timerService.currentProcessingTime());
processingTimeService.setCurrentTime(42);
assertEquals(42, timerService.currentProcessingTime());
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class InternalTimerServiceImplTest method testSetAndFireEventTimeTimers.
/**
* This also verifies that we don't have leakage between keys/namespaces.
*/
@Test
public void testSetAndFireEventTimeTimers() throws Exception {
@SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class);
TestKeyContext keyContext = new TestKeyContext();
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimerServiceImpl<Integer, String> timerService = createAndStartInternalTimerService(mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, createQueueFactory());
// get two different keys
int key1 = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
int key2 = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
while (key2 == key1) {
key2 = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
}
keyContext.setCurrentKey(key1);
timerService.registerEventTimeTimer("ciao", 10);
timerService.registerEventTimeTimer("hello", 10);
keyContext.setCurrentKey(key2);
timerService.registerEventTimeTimer("ciao", 10);
timerService.registerEventTimeTimer("hello", 10);
assertEquals(4, timerService.numEventTimeTimers());
assertEquals(2, timerService.numEventTimeTimers("hello"));
assertEquals(2, timerService.numEventTimeTimers("ciao"));
timerService.advanceWatermark(10);
verify(mockTriggerable, times(4)).onEventTime(anyInternalTimer());
verify(mockTriggerable, times(1)).onEventTime(eq(new TimerHeapInternalTimer<>(10, key1, "ciao")));
verify(mockTriggerable, times(1)).onEventTime(eq(new TimerHeapInternalTimer<>(10, key1, "hello")));
verify(mockTriggerable, times(1)).onEventTime(eq(new TimerHeapInternalTimer<>(10, key2, "ciao")));
verify(mockTriggerable, times(1)).onEventTime(eq(new TimerHeapInternalTimer<>(10, key2, "hello")));
assertEquals(0, timerService.numEventTimeTimers());
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class InternalTimerServiceImplTest method testRegisteringProcessingTimeTimerInOnProcessingTimeDoesNotLeakPhysicalTimers.
/**
*/
@Test
public void testRegisteringProcessingTimeTimerInOnProcessingTimeDoesNotLeakPhysicalTimers() throws Exception {
@SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class);
TestKeyContext keyContext = new TestKeyContext();
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
final InternalTimerServiceImpl<Integer, String> timerService = createAndStartInternalTimerService(mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, createQueueFactory());
int key = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
keyContext.setCurrentKey(key);
timerService.registerProcessingTimeTimer("ciao", 10);
assertEquals(1, timerService.numProcessingTimeTimers());
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(10L));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
timerService.registerProcessingTimeTimer("ciao", 20);
return null;
}
}).when(mockTriggerable).onProcessingTime(anyInternalTimer());
processingTimeService.setCurrentTime(10);
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(20L));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
timerService.registerProcessingTimeTimer("ciao", 30);
return null;
}
}).when(mockTriggerable).onProcessingTime(anyInternalTimer());
processingTimeService.setCurrentTime(20);
assertEquals(1, timerService.numProcessingTimeTimers());
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(30L));
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class InternalTimerServiceImplTest method testOnlySetsOnePhysicalProcessingTimeTimer.
/**
* Verify that we only ever have one processing-time task registered at the {@link
* ProcessingTimeService}.
*/
@Test
public void testOnlySetsOnePhysicalProcessingTimeTimer() throws Exception {
@SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class);
TestKeyContext keyContext = new TestKeyContext();
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
PriorityQueueSetFactory priorityQueueSetFactory = new HeapPriorityQueueSetFactory(testKeyGroupRange, maxParallelism, 128);
InternalTimerServiceImpl<Integer, String> timerService = createAndStartInternalTimerService(mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, priorityQueueSetFactory);
int key = getKeyInKeyGroupRange(testKeyGroupRange, maxParallelism);
keyContext.setCurrentKey(key);
timerService.registerProcessingTimeTimer("ciao", 10);
timerService.registerProcessingTimeTimer("ciao", 20);
timerService.registerProcessingTimeTimer("ciao", 30);
timerService.registerProcessingTimeTimer("hello", 10);
timerService.registerProcessingTimeTimer("hello", 20);
assertEquals(5, timerService.numProcessingTimeTimers());
assertEquals(2, timerService.numProcessingTimeTimers("hello"));
assertEquals(3, timerService.numProcessingTimeTimers("ciao"));
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(10L));
processingTimeService.setCurrentTime(10);
assertEquals(3, timerService.numProcessingTimeTimers());
assertEquals(1, timerService.numProcessingTimeTimers("hello"));
assertEquals(2, timerService.numProcessingTimeTimers("ciao"));
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(20L));
processingTimeService.setCurrentTime(20);
assertEquals(1, timerService.numProcessingTimeTimers());
assertEquals(0, timerService.numProcessingTimeTimers("hello"));
assertEquals(1, timerService.numProcessingTimeTimers("ciao"));
assertEquals(1, processingTimeService.getNumActiveTimers());
assertThat(processingTimeService.getActiveTimerTimestamps(), containsInAnyOrder(30L));
processingTimeService.setCurrentTime(30);
assertEquals(0, timerService.numProcessingTimeTimers());
assertEquals(0, processingTimeService.getNumActiveTimers());
timerService.registerProcessingTimeTimer("ciao", 40);
assertEquals(1, processingTimeService.getNumActiveTimers());
}
Aggregations