コード例 #1
0
  @Test
  public void testOpenClose() throws Exception {
    KeySelector<Integer, Integer> keySelector =
        new KeySelector<Integer, Integer>() {
          @Override
          public Integer getKey(Integer value) {
            return value;
          }
        };

    StreamGroupedFold<Integer, String, Integer> operator =
        new StreamGroupedFold<>(new TestOpenCloseFoldFunction(), "init");
    operator.setOutputType(BasicTypeInfo.STRING_TYPE_INFO, new ExecutionConfig());

    OneInputStreamOperatorTestHarness<Integer, String> testHarness =
        new OneInputStreamOperatorTestHarness<>(operator);
    testHarness.configureForKeyedStream(keySelector, BasicTypeInfo.INT_TYPE_INFO);

    long initialTime = 0L;

    testHarness.open();

    testHarness.processElement(new StreamRecord<>(1, initialTime));
    testHarness.processElement(new StreamRecord<>(2, initialTime));

    testHarness.close();

    assertTrue("RichFunction methods where not called.", TestOpenCloseFoldFunction.closeCalled);
    assertTrue("Output contains no elements.", testHarness.getOutput().size() > 0);
  }
コード例 #2
0
  @Test
  public void testGroupedFold() throws Exception {

    KeySelector<Integer, String> keySelector =
        new KeySelector<Integer, String>() {

          @Override
          public String getKey(Integer value) {
            return value.toString();
          }
        };

    StreamGroupedFold<Integer, String, String> operator =
        new StreamGroupedFold<>(new MyFolder(), "100");
    operator.setOutputType(BasicTypeInfo.STRING_TYPE_INFO, new ExecutionConfig());

    OneInputStreamOperatorTestHarness<Integer, String> testHarness =
        new OneInputStreamOperatorTestHarness<>(operator);
    testHarness.configureForKeyedStream(keySelector, BasicTypeInfo.STRING_TYPE_INFO);

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

    testHarness.open();

    testHarness.processElement(new StreamRecord<>(1, initialTime + 1));
    testHarness.processElement(new StreamRecord<>(1, initialTime + 2));
    testHarness.processWatermark(new Watermark(initialTime + 2));
    testHarness.processElement(new StreamRecord<>(2, initialTime + 3));
    testHarness.processElement(new StreamRecord<>(2, initialTime + 4));
    testHarness.processElement(new StreamRecord<>(3, initialTime + 5));

    expectedOutput.add(new StreamRecord<>("1001", initialTime + 1));
    expectedOutput.add(new StreamRecord<>("10011", initialTime + 2));
    expectedOutput.add(new Watermark(initialTime + 2));
    expectedOutput.add(new StreamRecord<>("1002", initialTime + 3));
    expectedOutput.add(new StreamRecord<>("10022", initialTime + 4));
    expectedOutput.add(new StreamRecord<>("1003", initialTime + 5));

    TestHarnessUtil.assertOutputEquals(
        "Output was not correct.", expectedOutput, testHarness.getOutput());
  }