use of org.apache.flink.table.runtime.operators.multipleinput.input.OneInput in project flink by apache.
the class BatchMultipleInputStreamOperatorTest method testProcess.
@Test
public void testProcess() throws Exception {
TestingBatchMultipleInputStreamOperator op = createMultipleInputStreamOperator();
List<StreamElement> outputData = op.getOutputData();
TestingTwoInputStreamOperator joinOp2 = (TestingTwoInputStreamOperator) op.getTailWrapper().getStreamOperator();
TableOperatorWrapper<?> joinWrapper1 = op.getTailWrapper().getInputWrappers().get(0);
TestingTwoInputStreamOperator joinOp1 = (TestingTwoInputStreamOperator) joinWrapper1.getStreamOperator();
TableOperatorWrapper<?> aggWrapper1 = joinWrapper1.getInputWrappers().get(0);
TestingOneInputStreamOperator aggOp1 = (TestingOneInputStreamOperator) aggWrapper1.getStreamOperator();
TableOperatorWrapper<?> aggWrapper2 = joinWrapper1.getInputWrappers().get(1);
TestingOneInputStreamOperator aggOp2 = (TestingOneInputStreamOperator) aggWrapper2.getStreamOperator();
List<Input> inputs = op.getInputs();
assertEquals(3, inputs.size());
Input input1 = inputs.get(0);
Input input2 = inputs.get(1);
Input input3 = inputs.get(2);
assertTrue(input1 instanceof OneInput);
assertTrue(input2 instanceof OneInput);
assertTrue(input3 instanceof SecondInputOfTwoInput);
assertNull(joinOp2.getCurrentElement1());
assertNull(joinOp2.getCurrentElement2());
assertNull(joinOp1.getCurrentElement1());
assertNull(joinOp1.getCurrentElement2());
assertNull(aggOp1.getCurrentElement());
assertNull(aggOp2.getCurrentElement());
assertTrue(outputData.isEmpty());
// process first input (input id is 3)
StreamRecord<RowData> element1 = new StreamRecord<>(GenericRowData.of(StringData.fromString("123")), 456);
input3.processElement(element1);
assertEquals(element1, joinOp2.getCurrentElement2());
assertNull(joinOp2.getCurrentElement1());
assertTrue(outputData.isEmpty());
// finish first input
assertTrue(joinOp2.getEndInputs().isEmpty());
op.endInput(3);
assertTrue(outputData.isEmpty());
assertEquals(Collections.singletonList(2), joinOp2.getEndInputs());
// process second input (input id is 1)
StreamRecord<RowData> element2 = new StreamRecord<>(GenericRowData.of(StringData.fromString("124")), 457);
input1.processElement(element2);
assertEquals(element2, aggOp1.getCurrentElement());
assertNull(joinOp1.getCurrentElement1());
assertNull(joinOp2.getCurrentElement1());
assertTrue(outputData.isEmpty());
// finish second input
assertTrue(joinOp1.getEndInputs().isEmpty());
op.endInput(1);
assertEquals(Collections.singletonList(1), joinOp1.getEndInputs());
assertEquals(Collections.singletonList(2), joinOp2.getEndInputs());
assertEquals(element2, joinOp1.getCurrentElement1());
assertTrue(outputData.isEmpty());
// process third input (input id is 2)
StreamRecord<RowData> element3 = new StreamRecord<>(GenericRowData.of(StringData.fromString("125")), 458);
input2.processElement(element3);
assertEquals(element3, aggOp2.getCurrentElement());
assertNull(joinOp1.getCurrentElement2());
assertNull(joinOp2.getCurrentElement1());
assertTrue(outputData.isEmpty());
// finish third input
assertEquals(Collections.singletonList(1), joinOp1.getEndInputs());
op.endInput(2);
assertEquals(Arrays.asList(1, 2), joinOp1.getEndInputs());
assertEquals(Arrays.asList(2, 1), joinOp2.getEndInputs());
assertEquals(element3, joinOp1.getCurrentElement2());
assertEquals(3, outputData.size());
}
Aggregations