private void testEmittingFromWindowFunction(TimeDomainAdaptor timeAdaptor) throws Exception { WindowAssigner<Integer, TimeWindow> mockAssigner = mockTimeWindowAssigner(); Trigger<Integer, TimeWindow> mockTrigger = mockTrigger(); InternalWindowFunction<Iterable<Integer>, String, Integer, TimeWindow> mockWindowFunction = mockWindowFunction(); KeyedOneInputStreamOperatorTestHarness<Integer, Integer, String> testHarness = createWindowOperator(mockAssigner, mockTrigger, 0L, mockWindowFunction); testHarness.open(); when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext())) .thenReturn(Collections.singletonList(new TimeWindow(0, 2))); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Collector<String> out = invocation.getArgument(4); out.collect("Hallo"); out.collect("Ciao"); return null; } }).when(mockWindowFunction).process(eq(0), eq(new TimeWindow(0, 2)), anyInternalWindowContext(), intIterable(0), WindowOperatorContractTest.<String>anyCollector()); timeAdaptor.shouldRegisterTimerOnElement(mockTrigger, 1); testHarness.processElement(new StreamRecord<>(0, 0L)); verify(mockWindowFunction, never()).process(anyInt(), anyTimeWindow(), anyInternalWindowContext(), anyIntIterable(), WindowOperatorContractTest.<String>anyCollector()); assertTrue(testHarness.extractOutputStreamRecords().isEmpty()); timeAdaptor.shouldFireOnTime(mockTrigger); timeAdaptor.advanceTime(testHarness, 1L); verify(mockWindowFunction, times(1)).process(eq(0), eq(new TimeWindow(0, 2)), anyInternalWindowContext(), intIterable(0), WindowOperatorContractTest.<String>anyCollector()); assertThat(testHarness.extractOutputStreamRecords(), contains(isStreamRecord("Hallo", 1L), isStreamRecord("Ciao", 1L))); }
assertThat(testHarness.extractOutputStreamRecords(), contains(isStreamRecord("Hallo", 1L), isStreamRecord("Ciao", 1L)));
assertTrue(testHarness.extractOutputStreamRecords().isEmpty());
.thenReturn(Arrays.asList(new TimeWindow(2, 4), new TimeWindow(0, 2))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
.thenReturn(Arrays.asList(new TimeWindow(2, 4), new TimeWindow(0, 2))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
.thenReturn(Arrays.asList(new TimeWindow(2, 4))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
.thenReturn(Arrays.asList(new TimeWindow(2, 4))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
.thenReturn(Arrays.asList(new TimeWindow(2, 4), new TimeWindow(4, 6))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries()); assertEquals(0, testHarness.extractOutputStreamRecords().size());
testHarness.open(); assertEquals(0, testHarness.extractOutputStreamRecords().size());
.thenReturn(Arrays.asList(new TimeWindow(2, 4), new TimeWindow(0, 2))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries()); assertEquals(0, testHarness.extractOutputStreamRecords().size());
.thenReturn(Arrays.asList(new TimeWindow(2, 4))); assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
@Test public void testLateWindowDropping() throws Exception { WindowAssigner<Integer, TimeWindow> mockAssigner = mockTimeWindowAssigner(); Trigger<Integer, TimeWindow> mockTrigger = mockTrigger(); InternalWindowFunction<Iterable<Integer>, Void, Integer, TimeWindow> mockWindowFunction = mockWindowFunction(); KeyedOneInputStreamOperatorTestHarness<Integer, Integer, Void> testHarness = createWindowOperator(mockAssigner, mockTrigger, 20L, mockWindowFunction); testHarness.open(); when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext())) .thenReturn(Arrays.asList(new TimeWindow(0, 2))); assertEquals(0, testHarness.getOutput().size()); assertEquals(0, testHarness.numKeyedStateEntries()); shouldFireOnElement(mockTrigger); // window.maxTime() == 1 plus 20L of allowed lateness testHarness.processWatermark(new Watermark(21)); testHarness.processElement(new StreamRecord<>(0, 0L)); // there should be nothing assertEquals(0, testHarness.numKeyedStateEntries()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numProcessingTimeTimers()); // there should be two elements now assertEquals(0, testHarness.extractOutputStreamRecords().size()); }
assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
private void testOnTimePurgeDoesNotCleanupMergingSet(TimeDomainAdaptor timeAdaptor) throws Exception { MergingWindowAssigner<Integer, TimeWindow> mockAssigner = mockMergingAssigner(); timeAdaptor.setIsEventTime(mockAssigner); Trigger<Integer, TimeWindow> mockTrigger = mockTrigger(); InternalWindowFunction<Iterable<Integer>, Void, Integer, TimeWindow> mockWindowFunction = mockWindowFunction(); KeyedOneInputStreamOperatorTestHarness<Integer, Integer, Void> testHarness = createWindowOperator(mockAssigner, mockTrigger, 0L, mockWindowFunction); testHarness.open(); when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext())) .thenReturn(Arrays.asList(new TimeWindow(0, 4))); assertEquals(0, testHarness.getOutput().size()); assertEquals(0, testHarness.numKeyedStateEntries()); timeAdaptor.shouldRegisterTimerOnElement(mockTrigger, 1L); testHarness.processElement(new StreamRecord<>(0, 0L)); timeAdaptor.shouldPurgeOnTime(mockTrigger); assertEquals(2, testHarness.numKeyedStateEntries()); // the merging window set + window contents assertEquals(2, timeAdaptor.numTimers(testHarness)); // one cleanup timer + timer assertEquals(0, testHarness.getOutput().size()); timeAdaptor.advanceTime(testHarness, 1L); assertEquals(1, testHarness.numKeyedStateEntries()); // the merging window set assertEquals(1, timeAdaptor.numTimers(testHarness)); // one cleanup timer assertEquals(0, testHarness.extractOutputStreamRecords().size()); }
assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries());
assertEquals(0, testHarness.extractOutputStreamRecords().size()); assertEquals(0, testHarness.numKeyedStateEntries()); assertEquals(2, timeAdaptor.numTimers(testHarness)); // trigger timer plus GC timer assertEquals(0, testHarness.extractOutputStreamRecords().size());