Java Code Examples for org.apache.flink.streaming.util.TwoInputStreamOperatorTestHarness#setup()
The following examples show how to use
org.apache.flink.streaming.util.TwoInputStreamOperatorTestHarness#setup() .
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: CoBroadcastWithNonKeyedOperatorTest.java From flink with Apache License 2.0 | 6 votes |
private static <IN1, IN2, OUT> TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> getInitializedTestHarness( final BroadcastProcessFunction<IN1, IN2, OUT> function, final int maxParallelism, final int numTasks, final int taskIdx, final OperatorSubtaskState initState, final MapStateDescriptor<?, ?>... descriptors) throws Exception { TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness = new TwoInputStreamOperatorTestHarness<>( new CoBroadcastWithNonKeyedOperator<>( Preconditions.checkNotNull(function), Arrays.asList(descriptors)), maxParallelism, numTasks, taskIdx ); testHarness.setup(); testHarness.initializeState(initState); testHarness.open(); return testHarness; }
Example 2
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 3
Source File: CoBroadcastWithNonKeyedOperatorTest.java From flink with Apache License 2.0 | 6 votes |
private static <IN1, IN2, OUT> TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> getInitializedTestHarness( final BroadcastProcessFunction<IN1, IN2, OUT> function, final int maxParallelism, final int numTasks, final int taskIdx, final OperatorSubtaskState initState, final MapStateDescriptor<?, ?>... descriptors) throws Exception { TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness = new TwoInputStreamOperatorTestHarness<>( new CoBroadcastWithNonKeyedOperator<>( Preconditions.checkNotNull(function), Arrays.asList(descriptors)), maxParallelism, numTasks, taskIdx ); testHarness.setup(); testHarness.initializeState(initState); testHarness.open(); return testHarness; }
Example 4
Source File: CoBroadcastWithNonKeyedOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static <IN1, IN2, OUT> TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> getInitializedTestHarness( final BroadcastProcessFunction<IN1, IN2, OUT> function, final int maxParallelism, final int numTasks, final int taskIdx, final OperatorSubtaskState initState, final MapStateDescriptor<?, ?>... descriptors) throws Exception { TwoInputStreamOperatorTestHarness<IN1, IN2, OUT> testHarness = new TwoInputStreamOperatorTestHarness<>( new CoBroadcastWithNonKeyedOperator<>( Preconditions.checkNotNull(function), Arrays.asList(descriptors)), maxParallelism, numTasks, taskIdx ); testHarness.setup(); testHarness.initializeState(initState); testHarness.open(); return testHarness; }
Example 5
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 6
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 7
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 8
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 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: 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 11
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 12
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 13
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 14
Source File: KeyedCoProcessOperatorTest.java From Flink-CEPplus 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<>("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 15
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 16
Source File: KeyedCoProcessOperatorTest.java From Flink-CEPplus 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 17
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 18
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 4 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testEventTimeTimerWithState() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new EventTimeTriggeringStatefulProcessFunction()); 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(1)); testHarness.processWatermark2(new Watermark(1)); testHarness.processElement1(new StreamRecord<>(17, 0L)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13, 0L)); // should set timer for 6 testHarness.processWatermark1(new Watermark(2)); testHarness.processWatermark2(new Watermark(2)); testHarness.processElement1(new StreamRecord<>(13, 1L)); // should delete timer testHarness.processElement2(new StreamRecord<>("42", 1L)); // should set timer for 7 testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); testHarness.processWatermark1(new Watermark(7)); testHarness.processWatermark2(new Watermark(7)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new Watermark(1L)); expectedOutput.add(new StreamRecord<>("INPUT1:17", 0L)); expectedOutput.add(new StreamRecord<>("INPUT1:13", 0L)); expectedOutput.add(new Watermark(2L)); expectedOutput.add(new StreamRecord<>("INPUT2:42", 1L)); expectedOutput.add(new StreamRecord<>("STATE:17", 6L)); expectedOutput.add(new Watermark(6L)); expectedOutput.add(new StreamRecord<>("STATE:42", 7L)); expectedOutput.add(new Watermark(7L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example 19
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 4 votes |
/** * Verifies that we don't have leakage between different keys. */ @Test public void testEventTimeTimerWithState() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new EventTimeTriggeringStatefulProcessFunction()); 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(1)); testHarness.processWatermark2(new Watermark(1)); testHarness.processElement1(new StreamRecord<>(17, 0L)); // should set timer for 6 testHarness.processElement1(new StreamRecord<>(13, 0L)); // should set timer for 6 testHarness.processWatermark1(new Watermark(2)); testHarness.processWatermark2(new Watermark(2)); testHarness.processElement1(new StreamRecord<>(13, 1L)); // should delete timer testHarness.processElement2(new StreamRecord<>("42", 1L)); // should set timer for 7 testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); testHarness.processWatermark1(new Watermark(7)); testHarness.processWatermark2(new Watermark(7)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new Watermark(1L)); expectedOutput.add(new StreamRecord<>("INPUT1:17", 0L)); expectedOutput.add(new StreamRecord<>("INPUT1:13", 0L)); expectedOutput.add(new Watermark(2L)); expectedOutput.add(new StreamRecord<>("INPUT2:42", 1L)); expectedOutput.add(new StreamRecord<>("STATE:17", 6L)); expectedOutput.add(new Watermark(6L)); expectedOutput.add(new StreamRecord<>("STATE:42", 7L)); expectedOutput.add(new Watermark(7L)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }
Example 20
Source File: KeyedCoProcessOperatorTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testSnapshotAndRestore() throws Exception { KeyedCoProcessOperator<String, Integer, String, String> operator = new KeyedCoProcessOperator<>(new BothTriggeringProcessFunction()); 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, 12L)); testHarness.processElement2(new StreamRecord<>("5", 12L)); // snapshot and restore from scratch OperatorSubtaskState snapshot = testHarness.snapshot(0, 0); testHarness.close(); operator = new KeyedCoProcessOperator<>(new BothTriggeringProcessFunction()); testHarness = new KeyedTwoInputStreamOperatorTestHarness<>( operator, new IntToStringKeySelector<>(), new IdentityKeySelector<String>(), BasicTypeInfo.STRING_TYPE_INFO); testHarness.setup(); testHarness.initializeState(snapshot); testHarness.open(); testHarness.setProcessingTime(5); testHarness.processWatermark1(new Watermark(6)); testHarness.processWatermark2(new Watermark(6)); ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>(); expectedOutput.add(new StreamRecord<>("PROC:1777")); expectedOutput.add(new StreamRecord<>("EVENT:1777", 6L)); expectedOutput.add(new Watermark(6)); TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput()); testHarness.close(); }