Search in sources :

Example 1 with TimeWindow

use of org.apache.kafka.streams.kstream.internals.TimeWindow in project kafka by apache.

the class TimeWindowsTest method shouldComputeWindowsForHoppingWindows.

@Test
public void shouldComputeWindowsForHoppingWindows() {
    TimeWindows windows = TimeWindows.of(12L).advanceBy(5L);
    Map<Long, TimeWindow> matched = windows.windowsFor(21L);
    assertEquals(12L / 5L + 1, matched.size());
    assertEquals(new TimeWindow(10L, 22L), matched.get(10L));
    assertEquals(new TimeWindow(15L, 27L), matched.get(15L));
    assertEquals(new TimeWindow(20L, 32L), matched.get(20L));
}
Also used : TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 2 with TimeWindow

use of org.apache.kafka.streams.kstream.internals.TimeWindow in project kafka by apache.

the class CachingWindowStoreTest method shouldForwardDirtyItemsWhenFlushCalled.

@Test
public void shouldForwardDirtyItemsWhenFlushCalled() throws Exception {
    final Windowed<String> windowedKey = new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE));
    cachingStore.put("1", "a");
    cachingStore.flush();
    assertEquals("a", cacheListener.forwarded.get(windowedKey).newValue);
    assertNull(cacheListener.forwarded.get(windowedKey).oldValue);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 3 with TimeWindow

use of org.apache.kafka.streams.kstream.internals.TimeWindow in project kafka by apache.

the class CachingWindowStoreTest method shouldForwardOldValuesWhenEnabled.

@Test
public void shouldForwardOldValuesWhenEnabled() throws Exception {
    final Windowed<String> windowedKey = new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE));
    cachingStore.put("1", "a");
    cachingStore.flush();
    cachingStore.put("1", "b");
    cachingStore.flush();
    assertEquals("b", cacheListener.forwarded.get(windowedKey).newValue);
    assertEquals("a", cacheListener.forwarded.get(windowedKey).oldValue);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 4 with TimeWindow

use of org.apache.kafka.streams.kstream.internals.TimeWindow in project kafka by apache.

the class TimeWindowsTest method shouldComputeWindowsForBarelyOverlappingHoppingWindows.

@Test
public void shouldComputeWindowsForBarelyOverlappingHoppingWindows() {
    TimeWindows windows = TimeWindows.of(6L).advanceBy(5L);
    Map<Long, TimeWindow> matched = windows.windowsFor(7L);
    assertEquals(1, matched.size());
    assertEquals(new TimeWindow(5L, 11L), matched.get(5L));
}
Also used : TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 5 with TimeWindow

use of org.apache.kafka.streams.kstream.internals.TimeWindow in project kafka by apache.

the class TimeWindowsTest method shouldComputeWindowsForTumblingWindows.

@Test
public void shouldComputeWindowsForTumblingWindows() {
    TimeWindows windows = TimeWindows.of(12L);
    Map<Long, TimeWindow> matched = windows.windowsFor(21L);
    assertEquals(1, matched.size());
    assertEquals(new TimeWindow(12L, 24L), matched.get(12L));
}
Also used : TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Aggregations

TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)6 Test (org.junit.Test)5 Windowed (org.apache.kafka.streams.kstream.Windowed)2 HashMap (java.util.HashMap)1