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

The following examples show how to use org.apache.flink.streaming.util.TwoInputStreamOperatorTestHarness#close() . 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-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 2
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 3
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 4
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 5
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 6
Source File: CoProcessOperatorTest.java    From Flink-CEPplus 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 7
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 8
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 11
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 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: CoStreamFlatMapTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testOpenClose() throws Exception {
	CoStreamFlatMap<String, Integer, String> operator = new CoStreamFlatMap<String, Integer, String>(new TestOpenCloseCoFlatMapFunction());

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

	long initialTime = 0L;

	testHarness.open();

	testHarness.processElement1(new StreamRecord<String>("Hello", initialTime));
	testHarness.processElement2(new StreamRecord<Integer>(42, initialTime));

	testHarness.close();

	Assert.assertTrue("RichFunction methods where not called.", TestOpenCloseCoFlatMapFunction.closeCalled);
	Assert.assertTrue("Output contains no elements.", testHarness.getOutput().size() > 0);
}
 
Example 14
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 15
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 16
Source File: DoFnOperatorTest.java    From beam with Apache License 2.0 4 votes vote down vote up
void sideInputCheckpointing(
    TestHarnessFactory<
            TwoInputStreamOperatorTestHarness<
                WindowedValue<String>, RawUnionValue, WindowedValue<String>>>
        harnessFactory)
    throws Exception {

  TwoInputStreamOperatorTestHarness<WindowedValue<String>, RawUnionValue, WindowedValue<String>>
      testHarness = harnessFactory.create();

  testHarness.open();

  IntervalWindow firstWindow = new IntervalWindow(new Instant(0), new Instant(100));
  IntervalWindow secondWindow = new IntervalWindow(new Instant(0), new Instant(500));

  // push in some side inputs for both windows
  testHarness.processElement2(
      new StreamRecord<>(
          new RawUnionValue(
              1,
              valuesInWindow(
                  PCollectionViewTesting.materializeValuesFor(
                      view1.getPipeline().getOptions(), View.asIterable(), "hello", "ciao"),
                  new Instant(0),
                  firstWindow))));
  testHarness.processElement2(
      new StreamRecord<>(
          new RawUnionValue(
              2,
              valuesInWindow(
                  PCollectionViewTesting.materializeValuesFor(
                      view2.getPipeline().getOptions(), View.asIterable(), "foo", "bar"),
                  new Instant(0),
                  secondWindow))));

  // snapshot state, throw away the operator, then restore and verify that we still match
  // main-input elements to the side-inputs that we sent earlier
  OperatorSubtaskState snapshot = testHarness.snapshot(0, 0);

  testHarness = harnessFactory.create();

  testHarness.initializeState(snapshot);
  testHarness.open();

  // push in main-input elements
  WindowedValue<String> helloElement = valueInWindow("Hello", new Instant(0), firstWindow);
  WindowedValue<String> worldElement = valueInWindow("World", new Instant(1000), firstWindow);
  testHarness.processElement1(new StreamRecord<>(helloElement));
  testHarness.processElement1(new StreamRecord<>(worldElement));

  assertThat(
      stripStreamRecordFromWindowedValue(testHarness.getOutput()),
      contains(helloElement, worldElement));

  testHarness.close();
}
 
Example 17
Source File: KeyedCoProcessOperatorTest.java    From flink 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 18
Source File: EventTimeJoinTest.java    From flink-training-exercises with Apache License 2.0 4 votes vote down vote up
@Test
public void testTradeBeforeCustomer() throws Exception {
	TwoInputStreamOperatorTestHarness<Trade, Customer, EnrichedTrade> testHarness = setupHarness();
	int timerCountBefore;

	// push in data
	Customer c0 = new Customer(0L, 0L, "customer-0");

	Trade t1000 = new Trade(1000L, 0L, "trade-1000");

	Customer c0500 = new Customer(500L, 0L, "customer-500");
	Customer c1500 = new Customer(1500L, 0L, "customer-1500");

	testHarness.processElement2(new StreamRecord<>(c0, 0));
	testHarness.processWatermark2(new Watermark(0));

	// processing a Trade should create an event-time timer
	timerCountBefore = testHarness.numEventTimeTimers();
	testHarness.processElement1(new StreamRecord<>(t1000, 1000));
	assert(testHarness.numEventTimeTimers() == timerCountBefore + 1);

	testHarness.processWatermark1(new Watermark(1000));

	testHarness.processElement2(new StreamRecord<>(c0500, 500));
	testHarness.processWatermark2(new Watermark(500));

	testHarness.processElement2(new StreamRecord<>(c1500, 1500));

	// now the timer should fire
	timerCountBefore = testHarness.numEventTimeTimers();
	testHarness.processWatermark2(new Watermark(1500));
	assert(testHarness.numEventTimeTimers() == timerCountBefore - 1);

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

	EnrichedTrade et1000 = new EnrichedTrade(t1000, c0500);

	expectedOutput.add(new Watermark(0L));
	expectedOutput.add(new Watermark(500L));
	expectedOutput.add(new StreamRecord<>(et1000, 1000L));
	expectedOutput.add(new Watermark(1000L));

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

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

	testHarness.close();
}
 
Example 19
Source File: CoProcessOperatorTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test
public void testTimestampAndProcessingTimeQuerying() throws Exception {

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

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

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

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

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

	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();
}