org.apache.flink.streaming.util.KeyedTwoInputStreamOperatorTestHarness Java Examples
The following examples show how to use
org.apache.flink.streaming.util.KeyedTwoInputStreamOperatorTestHarness.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UrlDBFunctionTest.java From flink-crawler with Apache License 2.0 | 6 votes |
private KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl> makeTestHarness( int parallelism, int subTaskIndex, OperatorSubtaskState savedState) throws Exception { BaseUrlStateMerger merger = new DefaultUrlStateMerger(); FetchQueue fetchQueue = new ReFetchingQueue(); KeyedCoProcessOperator<String, CrawlStateUrl, DomainScore, FetchUrl> operator = new KeyedCoProcessOperator<>( new UrlDBFunction(_terminator, merger, fetchQueue)); KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl> result = new KeyedTwoInputStreamOperatorTestHarness<>( operator, _pldKeySelector, _domainScoreKeySelector, BasicTypeInfo.STRING_TYPE_INFO, MAX_PARALLELISM, parallelism, subTaskIndex); result.setStateBackend(new MemoryStateBackend()); result.setup(); if (savedState != null) { result.initializeState(savedState); } result.open(); return result; }
Example #2
Source File: ExpiringStateHarnessTest.java From flink-training-exercises with Apache License 2.0 | 6 votes |
@Test public void testRideThenFare() throws Exception { KeyedTwoInputStreamOperatorTestHarness<Long, TaxiRide, TaxiFare, Tuple2<TaxiRide, TaxiFare>> harness = setupHarness(); final TaxiRide ride1 = testRide(1); final TaxiFare fare1 = testFare(1); final long timeForFare = 1L; harness.processElement1(new StreamRecord<>(ride1, 0)); harness.processElement2(new StreamRecord<>(fare1, timeForFare)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>(new Tuple2<>(ride1, fare1), timeForFare)); // Check that the result is correct ConcurrentLinkedQueue<Object> actualOutput = harness.getOutput(); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, actualOutput); // Check that no state or timers are left behind assert(harness.numKeyedStateEntries() == 0); assert(harness.numEventTimeTimers() == 0); }
Example #3
Source File: ExpiringStateHarnessTest.java From flink-training-exercises with Apache License 2.0 | 6 votes |
private KeyedTwoInputStreamOperatorTestHarness<Long, TaxiRide, TaxiFare, Tuple2<TaxiRide, TaxiFare>> setupHarness() throws Exception { // instantiate operator KeyedCoProcessOperator<Long, TaxiRide, TaxiFare, Tuple2<TaxiRide, TaxiFare>> operator = new KeyedCoProcessOperator<>(new ExpiringStateSolution.EnrichmentFunction()); // setup test harness KeyedTwoInputStreamOperatorTestHarness<Long, TaxiRide, TaxiFare, Tuple2<TaxiRide, TaxiFare>> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, (TaxiRide r) -> r.rideId, (TaxiFare f) -> f.rideId, BasicTypeInfo.LONG_TYPE_INFO); testHarness.setup(); testHarness.open(); return testHarness; }
Example #4
Source File: EventTimeJoinTest.java From flink-training-exercises with Apache License 2.0 | 6 votes |
private TwoInputStreamOperatorTestHarness<Trade, Customer, EnrichedTrade> setupHarness() throws Exception { // instantiate operator KeyedCoProcessOperator<Long, Trade, Customer, EnrichedTrade> operator = new KeyedCoProcessOperator<>(new EventTimeJoinExercise.EventTimeJoinFunction()); // setup test harness TwoInputStreamOperatorTestHarness<Trade, Customer, EnrichedTrade> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, (Trade t) -> t.customerId, (Customer c) -> c.customerId, BasicTypeInfo.LONG_TYPE_INFO); testHarness.setup(); testHarness.open(); return testHarness; }
Example #5
Source File: KeyedCoProcessOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testProcessingTimeTimerWithState() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeTriggeringStatefulProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(1); testHarness.processElement1(new StreamRecord<>(17)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13)); // should set timer for 6 testHarness.setProcessingTime(2); testHarness.processElement1(new StreamRecord<>(13)); // should delete timer again testHarness.processElement2(new StreamRecord<>("42")); // should set timer for 7 testHarness.setProcessingTime(6); testHarness.setProcessingTime(7); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT1:13")); expectedOutput.add(new StreamRecord<>("INPUT2:42")); expectedOutput.add(new StreamRecord<>("STATE:17")); expectedOutput.add(new StreamRecord<>("STATE:42")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #6
Source File: UrlDBFunctionTest.java From flink-crawler with Apache License 2.0 | 5 votes |
private void addProcessingTime(long extraTime) throws Exception { for (int subTaskIndex = 0; subTaskIndex < _testHarnesses.length; subTaskIndex++) { KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl> testHarness = _testHarnesses[subTaskIndex]; long newTime = testHarness.getProcessingTime() + extraTime; LOGGER.debug("Test harness ({}/{}) processing time is now {}", subTaskIndex + 1, _testHarnesses.length, newTime); testHarness.setProcessingTime(newTime); } }
Example #7
Source File: ProcTimeBoundedStreamJoinTest.java From flink with Apache License 2.0 | 5 votes |
private KeyedTwoInputStreamOperatorTestHarness<BaseRow, BaseRow, BaseRow, BaseRow> createTestHarness( ProcTimeBoundedStreamJoin windowJoinFunc) throws Exception { LegacyKeyedCoProcessOperator<BaseRow, BaseRow, BaseRow, BaseRow> operator = new LegacyKeyedCoProcessOperator<>( windowJoinFunc); KeyedTwoInputStreamOperatorTestHarness<BaseRow, BaseRow, BaseRow, BaseRow> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, keySelector, keySelector, keyType); return testHarness; }
Example #8
Source File: RowTimeBoundedStreamJoinTest.java From flink with Apache License 2.0 | 5 votes |
private KeyedTwoInputStreamOperatorTestHarness<BaseRow, BaseRow, BaseRow, BaseRow> createTestHarness( RowTimeBoundedStreamJoin windowJoinFunc) throws Exception { LegacyKeyedCoProcessOperator<BaseRow, BaseRow, BaseRow, BaseRow> operator = new KeyedCoProcessOperatorWithWatermarkDelay<>( windowJoinFunc, windowJoinFunc.getMaxOutputDelay()); KeyedTwoInputStreamOperatorTestHarness<BaseRow, BaseRow, BaseRow, BaseRow> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, keySelector, keySelector, keyType); return testHarness; }
Example #9
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampAndWatermarkQuerying() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new WatermarkQueryingProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processWatermark1(new Watermark(17)); testHarness.processWatermark2(new Watermark(17)); testHarness.processElement1(new StreamRecord<>(5, 12L)); testHarness.processWatermark1(new Watermark(42)); testHarness.processWatermark2(new Watermark(42)); testHarness.processElement2(new StreamRecord<>("6", 13L)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new Watermark(17L)); expectedOutput.add(new StreamRecord<>("5WM:17 TS:12", 12L)); expectedOutput.add(new Watermark(42L)); expectedOutput.add(new StreamRecord<>("6WM:42 TS:13", 13L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #10
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEventTimeTimers() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new EventTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17, 42L)); testHarness.processElement2(new StreamRecord<>("18", 42L)); testHarness.processWatermark1(new Watermark(5)); testHarness.processWatermark2(new Watermark(5)); testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17", 42L)); expectedOutput.add(new StreamRecord<>("INPUT2:18", 42L)); expectedOutput.add(new StreamRecord<>("17:1777", 5L)); expectedOutput.add(new Watermark(5L)); expectedOutput.add(new StreamRecord<>("18:1777", 6L)); expectedOutput.add(new Watermark(6L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #11
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testProcessingTimeTimers() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17)); testHarness.processElement2(new StreamRecord<>("18")); testHarness.setProcessingTime(5); testHarness.setProcessingTime(6); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT2:18")); expectedOutput.add(new StreamRecord<>("1777")); expectedOutput.add(new StreamRecord<>("1777")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #12
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testProcessingTimeTimerWithState() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeTriggeringStatefulProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(1); testHarness.processElement1(new StreamRecord<>(17)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13)); // should set timer for 6 testHarness.setProcessingTime(2); testHarness.processElement1(new StreamRecord<>(13)); // should delete timer again testHarness.processElement2(new StreamRecord<>("42")); // should set timer for 7 testHarness.setProcessingTime(6); testHarness.setProcessingTime(7); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT1:13")); expectedOutput.add(new StreamRecord<>("INPUT2:42")); expectedOutput.add(new StreamRecord<>("STATE:17")); expectedOutput.add(new StreamRecord<>("STATE:42")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #13
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testGetCurrentKeyFromContext() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new AppendCurrentKeyProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(5)); testHarness.processElement1(new StreamRecord<>(6)); testHarness.processElement2(new StreamRecord<>("hello")); testHarness.processElement2(new StreamRecord<>("world")); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("5,5")); expectedOutput.add(new StreamRecord<>("6,6")); expectedOutput.add(new StreamRecord<>("hello,hello")); expectedOutput.add(new StreamRecord<>("world,world")); TestHarnessUtil.assertOutputEquals( "Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #14
Source File: UrlDBFunctionTest.java From flink-crawler with Apache License 2.0 | 5 votes |
private void setProcessingTime(long newTime) throws Exception { for (int subTaskIndex = 0; subTaskIndex < _testHarnesses.length; subTaskIndex++) { KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl> testHarness = _testHarnesses[subTaskIndex]; LOGGER.debug("Test harness ({}/{}) processing time is now {}", subTaskIndex + 1, _testHarnesses.length, newTime); testHarness.setProcessingTime(newTime); } }
Example #15
Source File: CoBroadcastWithKeyedOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static <KEY, IN1, IN2, OUT> TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> getInitializedTestHarness( final TypeInformation<KEY> keyTypeInfo, final KeySelector<IN1, KEY> keyKeySelector, final KeyedBroadcastProcessFunction<KEY, IN1, IN2, OUT> function, final int maxParallelism, final int numTasks, final int taskIdx, final OperatorSubtaskState initState) throws Exception { final TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( new CoBroadcastWithKeyedOperator<>( Preconditions.checkNotNull(function), Collections.singletonList(STATE_DESCRIPTOR)), keyKeySelector, null, keyTypeInfo, maxParallelism, numTasks, taskIdx ); testHarness.setup(); testHarness.initializeState(initState); testHarness.open(); return testHarness; }
Example #16
Source File: UrlDBFunctionTest.java From flink-crawler with Apache License 2.0 | 5 votes |
private KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl>[] makeTestHarnesses( int parallelism, OperatorSubtaskState savedState) throws Exception { @SuppressWarnings("unchecked") KeyedTwoInputStreamOperatorTestHarness<String, CrawlStateUrl, DomainScore, FetchUrl> result[] = new KeyedTwoInputStreamOperatorTestHarness[parallelism]; _terminator = new ManualCrawlTerminator(); for (int i = 0; i < parallelism; i++) { result[i] = makeTestHarness(parallelism, i, savedState); } return result; }
Example #17
Source File: RowTimeIntervalJoinTest.java From flink with Apache License 2.0 | 5 votes |
private KeyedTwoInputStreamOperatorTestHarness<RowData, RowData, RowData, RowData> createTestHarness( RowTimeIntervalJoin intervalJoinFunc) throws Exception { KeyedCoProcessOperator<RowData, RowData, RowData, RowData> operator = new KeyedCoProcessOperatorWithWatermarkDelay<>( intervalJoinFunc, intervalJoinFunc.getMaxOutputDelay()); KeyedTwoInputStreamOperatorTestHarness<RowData, RowData, RowData, RowData> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, keySelector, keySelector, keyType); return testHarness; }
Example #18
Source File: ProcTimeIntervalJoinTest.java From flink with Apache License 2.0 | 5 votes |
private KeyedTwoInputStreamOperatorTestHarness<RowData, RowData, RowData, RowData> createTestHarness( ProcTimeIntervalJoin intervalJoinFunc) throws Exception { KeyedCoProcessOperator<RowData, RowData, RowData, RowData> operator = new KeyedCoProcessOperator<>( intervalJoinFunc); KeyedTwoInputStreamOperatorTestHarness<RowData, RowData, RowData, RowData> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>(operator, keySelector, keySelector, keyType); return testHarness; }
Example #19
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampAndWatermarkQuerying() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new WatermarkQueryingProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processWatermark1(new Watermark(17)); testHarness.processWatermark2(new Watermark(17)); testHarness.processElement1(new StreamRecord<>(5, 12L)); testHarness.processWatermark1(new Watermark(42)); testHarness.processWatermark2(new Watermark(42)); testHarness.processElement2(new StreamRecord<>("6", 13L)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new Watermark(17L)); expectedOutput.add(new StreamRecord<>("5WM:17 TS:12", 12L)); expectedOutput.add(new Watermark(42L)); expectedOutput.add(new StreamRecord<>("6WM:42 TS:13", 13L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #20
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampAndProcessingTimeQuerying() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new ProcessingTimeQueryingProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(17); testHarness.processElement1(new StreamRecord<>(5)); testHarness.setProcessingTime(42); testHarness.processElement2(new StreamRecord<>("6")); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("5PT:17 TS:null")); expectedOutput.add(new StreamRecord<>("6PT:42 TS:null")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #21
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEventTimeTimers() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new EventTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17, 42L)); testHarness.processElement2(new StreamRecord<>("18", 42L)); testHarness.processWatermark1(new Watermark(5)); testHarness.processWatermark2(new Watermark(5)); testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17", 42L)); expectedOutput.add(new StreamRecord<>("INPUT2:18", 42L)); expectedOutput.add(new StreamRecord<>("1777", 5L)); expectedOutput.add(new Watermark(5L)); expectedOutput.add(new StreamRecord<>("1777", 6L)); expectedOutput.add(new Watermark(6L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #22
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testProcessingTimeTimers() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new ProcessingTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17)); testHarness.processElement2(new StreamRecord<>("18")); testHarness.setProcessingTime(5); testHarness.setProcessingTime(6); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT2:18")); expectedOutput.add(new StreamRecord<>("1777")); expectedOutput.add(new StreamRecord<>("1777")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #23
Source File: LegacyKeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testProcessingTimeTimerWithState() throws Exception { LegacyKeyedCoProcessOperator<String, Integer, String, String> operator = new LegacyKeyedCoProcessOperator<>(new ProcessingTimeTriggeringStatefulProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(1); testHarness.processElement1(new StreamRecord<>(17)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13)); // should set timer for 6 testHarness.setProcessingTime(2); testHarness.processElement1(new StreamRecord<>(13)); // should delete timer again testHarness.processElement2(new StreamRecord<>("42")); // should set timer for 7 testHarness.setProcessingTime(6); testHarness.setProcessingTime(7); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT1:13")); expectedOutput.add(new StreamRecord<>("INPUT2:42")); expectedOutput.add(new StreamRecord<>("STATE:17")); expectedOutput.add(new StreamRecord<>("STATE:42")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #24
Source File: CoBroadcastWithKeyedOperatorTest.java From flink with Apache License 2.0 | 5 votes |
private static <KEY, IN1, IN2, OUT> TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> getInitializedTestHarness( final TypeInformation<KEY> keyTypeInfo, final KeySelector<IN1, KEY> keyKeySelector, final KeyedBroadcastProcessFunction<KEY, IN1, IN2, OUT> function, final int maxParallelism, final int numTasks, final int taskIdx, final OperatorSubtaskState initState) throws Exception { final TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( new CoBroadcastWithKeyedOperator<>( Preconditions.checkNotNull(function), Collections.singletonList(STATE_DESCRIPTOR)), keyKeySelector, null, keyTypeInfo, maxParallelism, numTasks, taskIdx ); testHarness.setup(); testHarness.initializeState(initState); testHarness.open(); return testHarness; }
Example #25
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampAndWatermarkQuerying() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new WatermarkQueryingProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processWatermark1(new Watermark(17)); testHarness.processWatermark2(new Watermark(17)); testHarness.processElement1(new StreamRecord<>(5, 12L)); testHarness.processWatermark1(new Watermark(42)); testHarness.processWatermark2(new Watermark(42)); testHarness.processElement2(new StreamRecord<>("6", 13L)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new Watermark(17L)); expectedOutput.add(new StreamRecord<>("5WM:17 TS:12", 12L)); expectedOutput.add(new Watermark(42L)); expectedOutput.add(new StreamRecord<>("6WM:42 TS:13", 13L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #26
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampAndProcessingTimeQuerying() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeQueryingProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(17); testHarness.processElement1(new StreamRecord<>(5)); testHarness.setProcessingTime(42); testHarness.processElement2(new StreamRecord<>("6")); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("5PT:17 TS:null")); expectedOutput.add(new StreamRecord<>("6PT:42 TS:null")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #27
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEventTimeTimers() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new EventTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17, 42L)); testHarness.processElement2(new StreamRecord<>("18", 42L)); testHarness.processWatermark1(new Watermark(5)); testHarness.processWatermark2(new Watermark(5)); testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17", 42L)); expectedOutput.add(new StreamRecord<>("INPUT2:18", 42L)); expectedOutput.add(new StreamRecord<>("17:1777", 5L)); expectedOutput.add(new Watermark(5L)); expectedOutput.add(new StreamRecord<>("18:1777", 6L)); expectedOutput.add(new Watermark(6L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #28
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testProcessingTimeTimers() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeTriggeringProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(17)); testHarness.processElement2(new StreamRecord<>("18")); testHarness.setProcessingTime(5); testHarness.setProcessingTime(6); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT2:18")); expectedOutput.add(new StreamRecord<>("1777")); expectedOutput.add(new StreamRecord<>("1777")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #29
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testProcessingTimeTimerWithState() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new ProcessingTimeTriggeringStatefulProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.setProcessingTime(1); testHarness.processElement1(new StreamRecord<>(17)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13)); // should set timer for 6 testHarness.setProcessingTime(2); testHarness.processElement1(new StreamRecord<>(13)); // should delete timer again testHarness.processElement2(new StreamRecord<>("42")); // should set timer for 7 testHarness.setProcessingTime(6); testHarness.setProcessingTime(7); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("INPUT1:17")); expectedOutput.add(new StreamRecord<>("INPUT1:13")); expectedOutput.add(new StreamRecord<>("INPUT2:42")); expectedOutput.add(new StreamRecord<>("STATE:17")); expectedOutput.add(new StreamRecord<>("STATE:42")); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example #30
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testGetCurrentKeyFromContext() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new AppendCurrentKeyProcessFunction()); TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.open(); testHarness.processElement1(new StreamRecord<>(5)); testHarness.processElement1(new StreamRecord<>(6)); testHarness.processElement2(new StreamRecord<>("hello")); testHarness.processElement2(new StreamRecord<>("world")); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("5,5")); expectedOutput.add(new StreamRecord<>("6,6")); expectedOutput.add(new StreamRecord<>("hello,hello")); expectedOutput.add(new StreamRecord<>("world,world")); TestHarnessUtil.assertOutputEquals( "Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }