Пример #1
0
  /**
   * 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 testDeleteProcessingTimeTimers() 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.registerProcessingTimeTimer("ciao", 10);
    timerService.registerProcessingTimeTimer("hello", 10);

    keyContext.setCurrentKey(key2);

    timerService.registerProcessingTimeTimer("ciao", 10);
    timerService.registerProcessingTimeTimer("hello", 10);

    assertEquals(4, timerService.numProcessingTimeTimers());
    assertEquals(2, timerService.numProcessingTimeTimers("hello"));
    assertEquals(2, timerService.numProcessingTimeTimers("ciao"));

    keyContext.setCurrentKey(key1);
    timerService.deleteProcessingTimeTimer("hello", 10);

    keyContext.setCurrentKey(key2);
    timerService.deleteProcessingTimeTimer("ciao", 10);

    assertEquals(2, timerService.numProcessingTimeTimers());
    assertEquals(1, timerService.numProcessingTimeTimers("hello"));
    assertEquals(1, timerService.numProcessingTimeTimers("ciao"));

    processingTimeService.setCurrentTime(10);

    verify(mockTriggerable, times(2)).onProcessingTime(anyInternalTimer());
    verify(mockTriggerable, times(1)).onProcessingTime(eq(new InternalTimer<>(10, key1, "ciao")));
    verify(mockTriggerable, times(0)).onProcessingTime(eq(new InternalTimer<>(10, key1, "hello")));
    verify(mockTriggerable, times(0)).onProcessingTime(eq(new InternalTimer<>(10, key2, "ciao")));
    verify(mockTriggerable, times(1)).onProcessingTime(eq(new InternalTimer<>(10, key2, "hello")));

    assertEquals(0, timerService.numEventTimeTimers());
  }