Java Code Examples for org.apache.flink.streaming.util.TwoInputStreamOperatorTestHarness#processWatermark1()

The following examples show how to use org.apache.flink.streaming.util.TwoInputStreamOperatorTestHarness#processWatermark1() . 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: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: CoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimestampAndWatermarkQuerying() throws Exception {

	CoProcessOperator<Integer, String, String> operator =
			new CoProcessOperator<>(new WatermarkQueryingProcessFunction());

	TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness =
			new TwoInputStreamOperatorTestHarness<>(operator);

	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 3
Source File: CoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimestampAndWatermarkQuerying() throws Exception {

	CoProcessOperator<Integer, String, String> operator =
			new CoProcessOperator<>(new WatermarkQueryingProcessFunction());

	TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness =
			new TwoInputStreamOperatorTestHarness<>(operator);

	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 4
Source File: CoStreamMapTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCoMap() throws Exception {
	CoStreamMap<Double, Integer, String> operator = new CoStreamMap<Double, Integer, String>(new MyCoMap());

	TwoInputStreamOperatorTestHarness<Double, Integer, String> testHarness = new TwoInputStreamOperatorTestHarness<Double, Integer, String>(operator);

	long initialTime = 0L;
	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<Object>();

	testHarness.open();

	testHarness.processElement1(new StreamRecord<Double>(1.1d, initialTime + 1));
	testHarness.processElement1(new StreamRecord<Double>(1.2d, initialTime + 2));
	testHarness.processElement1(new StreamRecord<Double>(1.3d, initialTime + 3));
	testHarness.processWatermark1(new Watermark(initialTime + 3));
	testHarness.processElement1(new StreamRecord<Double>(1.4d, initialTime + 4));
	testHarness.processElement1(new StreamRecord<Double>(1.5d, initialTime + 5));

	testHarness.processElement2(new StreamRecord<Integer>(1, initialTime + 1));
	testHarness.processElement2(new StreamRecord<Integer>(2, initialTime + 2));
	testHarness.processWatermark2(new Watermark(initialTime + 2));
	testHarness.processElement2(new StreamRecord<Integer>(3, initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(4, initialTime + 4));
	testHarness.processElement2(new StreamRecord<Integer>(5, initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("1.1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("1.2", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("1.3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("1.4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("1.5", initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("2", initialTime + 2));
	expectedOutput.add(new Watermark(initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("5", initialTime + 5));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
 
Example 5
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: CoStreamMapTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCoMap() throws Exception {
	CoStreamMap<Double, Integer, String> operator = new CoStreamMap<Double, Integer, String>(new MyCoMap());

	TwoInputStreamOperatorTestHarness<Double, Integer, String> testHarness = new TwoInputStreamOperatorTestHarness<Double, Integer, String>(operator);

	long initialTime = 0L;
	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<Object>();

	testHarness.open();

	testHarness.processElement1(new StreamRecord<Double>(1.1d, initialTime + 1));
	testHarness.processElement1(new StreamRecord<Double>(1.2d, initialTime + 2));
	testHarness.processElement1(new StreamRecord<Double>(1.3d, initialTime + 3));
	testHarness.processWatermark1(new Watermark(initialTime + 3));
	testHarness.processElement1(new StreamRecord<Double>(1.4d, initialTime + 4));
	testHarness.processElement1(new StreamRecord<Double>(1.5d, initialTime + 5));

	testHarness.processElement2(new StreamRecord<Integer>(1, initialTime + 1));
	testHarness.processElement2(new StreamRecord<Integer>(2, initialTime + 2));
	testHarness.processWatermark2(new Watermark(initialTime + 2));
	testHarness.processElement2(new StreamRecord<Integer>(3, initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(4, initialTime + 4));
	testHarness.processElement2(new StreamRecord<Integer>(5, initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("1.1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("1.2", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("1.3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("1.4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("1.5", initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("2", initialTime + 2));
	expectedOutput.add(new Watermark(initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("5", initialTime + 5));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
 
Example 7
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: KeyedCoProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we don't have leakage between different keys.
 */
@Test
public void testEventTimeTimerWithState() throws Exception {

	LegacyKeyedCoProcessOperator<String, Integer, String, String> operator =
			new LegacyKeyedCoProcessOperator<>(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 13
Source File: EventTimeJoinTest.java    From flink-training-exercises with Apache License 2.0 4 votes vote down vote up
@Test
public void testManyPendingTrades() throws Exception {
	TwoInputStreamOperatorTestHarness<Trade, Customer, EnrichedTrade> testHarness = setupHarness();

	// push in data
	Trade t1700 = new Trade(1700L, 0L, "trade-1700");
	Trade t1800 = new Trade(1800L, 0L, "trade-1800");
	Trade t2000 = new Trade(2000L, 0L, "trade-2000");

	Customer c1600 = new Customer(1600L, 0L, "customer-1600");
	Customer c2100 = new Customer(2100L, 0L, "customer-2100");

	testHarness.processElement1(new StreamRecord<>(t1700, 1700));
	testHarness.processWatermark1(new Watermark(1700));

	testHarness.processElement1(new StreamRecord<>(t1800, 1800));
	testHarness.processWatermark1(new Watermark(1800));

	testHarness.processElement1(new StreamRecord<>(t2000, 2000));
	testHarness.processWatermark1(new Watermark(2000));

	testHarness.processElement2(new StreamRecord<>(c1600, 1600));
	testHarness.processWatermark2(new Watermark(1600));

	testHarness.processElement2(new StreamRecord<>(c2100, 2100));
	testHarness.processWatermark2(new Watermark(2100));

	// verify operator state
	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();

	EnrichedTrade et1700 = new EnrichedTrade(t1700, c1600);
	EnrichedTrade et1800 = new EnrichedTrade(t1800, c1600);
	EnrichedTrade et2000 = new EnrichedTrade(t2000, c1600);

	expectedOutput.add(new Watermark(1600L));
	expectedOutput.add(new StreamRecord<>(et1700, 1700L));
	expectedOutput.add(new StreamRecord<>(et1800, 1800L));
	expectedOutput.add(new StreamRecord<>(et2000, 2000L));
	expectedOutput.add(new Watermark(2000L));

	ConcurrentLinkedQueue<Object> actualOutput = testHarness.getOutput();

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, actualOutput);

	testHarness.close();
}
 
Example 14
Source File: CoStreamFlatMapTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCoFlatMap() throws Exception {
	CoStreamFlatMap<String, Integer, String> operator = new CoStreamFlatMap<String, Integer, String>(new MyCoFlatMap());

	TwoInputStreamOperatorTestHarness<String, Integer, String> testHarness = new TwoInputStreamOperatorTestHarness<String, Integer, String>(operator);

	long initialTime = 0L;
	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<Object>();

	testHarness.open();

	testHarness.processElement1(new StreamRecord<String>("abc", initialTime + 1));
	testHarness.processElement1(new StreamRecord<String>("def", initialTime + 2));
	testHarness.processWatermark1(new Watermark(initialTime + 2));
	testHarness.processElement1(new StreamRecord<String>("ghi", initialTime + 3));

	testHarness.processElement2(new StreamRecord<Integer>(1, initialTime + 1));
	testHarness.processElement2(new StreamRecord<Integer>(2, initialTime + 2));
	testHarness.processWatermark2(new Watermark(initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(3, initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(4, initialTime + 4));
	testHarness.processElement2(new StreamRecord<Integer>(5, initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("a", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("b", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("c", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("d", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("e", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("f", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("g", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("h", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("i", initialTime + 3));

	expectedOutput.add(new StreamRecord<String>("1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("2", initialTime + 2));
	expectedOutput.add(new Watermark(initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("5", initialTime + 5));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
 
Example 15
Source File: CoStreamFlatMapTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCoFlatMap() throws Exception {
	CoStreamFlatMap<String, Integer, String> operator = new CoStreamFlatMap<String, Integer, String>(new MyCoFlatMap());

	TwoInputStreamOperatorTestHarness<String, Integer, String> testHarness = new TwoInputStreamOperatorTestHarness<String, Integer, String>(operator);

	long initialTime = 0L;
	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<Object>();

	testHarness.open();

	testHarness.processElement1(new StreamRecord<String>("abc", initialTime + 1));
	testHarness.processElement1(new StreamRecord<String>("def", initialTime + 2));
	testHarness.processWatermark1(new Watermark(initialTime + 2));
	testHarness.processElement1(new StreamRecord<String>("ghi", initialTime + 3));

	testHarness.processElement2(new StreamRecord<Integer>(1, initialTime + 1));
	testHarness.processElement2(new StreamRecord<Integer>(2, initialTime + 2));
	testHarness.processWatermark2(new Watermark(initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(3, initialTime + 3));
	testHarness.processElement2(new StreamRecord<Integer>(4, initialTime + 4));
	testHarness.processElement2(new StreamRecord<Integer>(5, initialTime + 5));

	expectedOutput.add(new StreamRecord<String>("a", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("b", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("c", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("d", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("e", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("f", initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("g", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("h", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("i", initialTime + 3));

	expectedOutput.add(new StreamRecord<String>("1", initialTime + 1));
	expectedOutput.add(new StreamRecord<String>("2", initialTime + 2));
	expectedOutput.add(new Watermark(initialTime + 2));
	expectedOutput.add(new StreamRecord<String>("3", initialTime + 3));
	expectedOutput.add(new StreamRecord<String>("4", initialTime + 4));
	expectedOutput.add(new StreamRecord<String>("5", initialTime + 5));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
 
Example 16
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * 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 17
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * 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 18
Source File: KeyedCoProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 19
Source File: KeyedCoProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * 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: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we don't have leakage between different keys.
 */
@Test
public void testEventTimeTimerWithState() throws Exception {

	LegacyKeyedCoProcessOperator<String, Integer, String, String> operator =
			new LegacyKeyedCoProcessOperator<>(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();
}