use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.
the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testOnlyOneSource.
@Test
public void testOnlyOneSource() throws Exception {
try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).modifyExecutionConfig(applyObjectReuse(objectReuse)).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.BOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(1)).build()) {
testHarness.setAutoProcess(false);
ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
addSourceRecords(testHarness, 0, 42, 43, 44);
processSingleStepUntil(testHarness, () -> !testHarness.getOutput().isEmpty());
expectedOutput.add(new StreamRecord<>("42", TimestampAssigner.NO_TIMESTAMP));
CheckpointBarrier barrier = createBarrier(testHarness);
Future<Boolean> checkpointFuture = testHarness.getStreamTask().triggerCheckpointAsync(metaData, barrier.getCheckpointOptions());
processSingleStepUntil(testHarness, checkpointFuture::isDone);
ArrayList<Object> actualOutput = new ArrayList<>(testHarness.getOutput());
assertThat(actualOutput.subList(0, expectedOutput.size()), containsInAnyOrder(expectedOutput.toArray()));
assertThat(actualOutput.get(expectedOutput.size()), equalTo(barrier));
}
}
use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.
the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testStopWithSavepointDrainWaitsForSourcesFinish.
/**
* In this scenario:
*
* <ul>
* <li>Network inputs are processed until CheckpointBarriers for synchronous savepoint are
* processed.
* <li>RPC for stop-with-savepoint comes for sources
* <li>Sources keep being invoked until they return END_OF_DATA
* <li>Synchronous savepoint is triggered
* </ul>
*/
@Test
public void testStopWithSavepointDrainWaitsForSourcesFinish() throws Exception {
try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).setCollectNetworkEvents().modifyExecutionConfig(applyObjectReuse(objectReuse)).modifyStreamConfig(config -> config.setCheckpointingEnabled(true)).addInput(BasicTypeInfo.STRING_TYPE_INFO).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).addInput(BasicTypeInfo.DOUBLE_TYPE_INFO).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(4, true)).build()) {
testHarness.setAutoProcess(false);
ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
CheckpointBarrier barrier = createStopWithSavepointDrainBarrier();
testHarness.processElement(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP), 0);
testHarness.processEvent(new EndOfData(StopMode.DRAIN), 0);
testHarness.processEvent(barrier, 0);
testHarness.processElement(new StreamRecord<>(47d, TimestampAssigner.NO_TIMESTAMP), 1);
testHarness.processEvent(new EndOfData(StopMode.DRAIN), 1);
testHarness.processEvent(barrier, 1);
addSourceRecords(testHarness, 1, Boundedness.CONTINUOUS_UNBOUNDED, 1, 2);
addSourceRecords(testHarness, 2, Boundedness.CONTINUOUS_UNBOUNDED, 3, 4);
testHarness.processAll();
Future<Boolean> checkpointFuture = testHarness.getStreamTask().triggerCheckpointAsync(metaData, barrier.getCheckpointOptions());
processSingleStepUntil(testHarness, checkpointFuture::isDone);
expectedOutput.add(new StreamRecord<>("3", TimestampAssigner.NO_TIMESTAMP));
expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
expectedOutput.add(new StreamRecord<>("1", TimestampAssigner.NO_TIMESTAMP));
expectedOutput.add(new StreamRecord<>("4", TimestampAssigner.NO_TIMESTAMP));
expectedOutput.add(new StreamRecord<>("2", TimestampAssigner.NO_TIMESTAMP));
ArrayList<Object> actualOutput = new ArrayList<>(testHarness.getOutput());
assertThat(actualOutput.subList(0, expectedOutput.size()), containsInAnyOrder(expectedOutput.toArray()));
assertThat(actualOutput.subList(actualOutput.size() - 3, actualOutput.size()), contains(new StreamRecord<>("FINISH"), new EndOfData(StopMode.DRAIN), barrier));
}
}
use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.
the class HybridSourceSplitSerializerTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Map<Integer, Source> switchedSources = new HashMap<>();
switchedSources.put(0, new MockSource(null, 0));
byte[] splitBytes = { 1, 2, 3 };
HybridSourceSplitSerializer serializer = new HybridSourceSplitSerializer();
HybridSourceSplit split = new HybridSourceSplit(0, splitBytes, 0, "splitId");
byte[] serialized = serializer.serialize(split);
HybridSourceSplit clonedSplit = serializer.deserialize(0, serialized);
Assert.assertEquals(split, clonedSplit);
try {
serializer.deserialize(1, serialized);
Assert.fail();
} catch (IOException e) {
// expected invalid version
}
}
Aggregations