/** * This also verifies that we don't have leakage between keys/namespaces. * * <p>This also verifies that deleted timers don't fire. */ @Test public void testDeleteEventTimeTimers() throws Exception { @SuppressWarnings("unchecked") Triggerable<Integer, String> mockTriggerable = mock(Triggerable.class); TestKeyContext keyContext = new TestKeyContext(); TestProcessingTimeService processingTimeService = new TestProcessingTimeService(); HeapInternalTimerService<Integer, String> timerService = createTimerService( mockTriggerable, keyContext, processingTimeService, testKeyGroupRange, maxParallelism); // 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")); keyContext.setCurrentKey(key1); timerService.deleteEventTimeTimer("hello", 10); keyContext.setCurrentKey(key2); timerService.deleteEventTimeTimer("ciao", 10); assertEquals(2, timerService.numEventTimeTimers()); assertEquals(1, timerService.numEventTimeTimers("hello")); assertEquals(1, timerService.numEventTimeTimers("ciao")); timerService.advanceWatermark(10); verify(mockTriggerable, times(2)).onEventTime(anyInternalTimer()); verify(mockTriggerable, times(1)).onEventTime(eq(new InternalTimer<>(10, key1, "ciao"))); verify(mockTriggerable, times(0)).onEventTime(eq(new InternalTimer<>(10, key1, "hello"))); verify(mockTriggerable, times(0)).onEventTime(eq(new InternalTimer<>(10, key2, "ciao"))); verify(mockTriggerable, times(1)).onEventTime(eq(new InternalTimer<>(10, key2, "hello"))); assertEquals(0, timerService.numEventTimeTimers()); }