Search in sources :

Example 11 with MockSource

use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.

the class SourceOperatorStreamTaskTest method testTriggeringStopWithSavepointWithDrain.

@Test
public void testTriggeringStopWithSavepointWithDrain() throws Exception {
    SourceOperatorFactory<Integer> sourceOperatorFactory = new SourceOperatorFactory<>(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 2), WatermarkStrategy.noWatermarks());
    CompletableFuture<Boolean> checkpointCompleted = new CompletableFuture<>();
    CheckpointResponder checkpointResponder = new TestCheckpointResponder() {

        @Override
        public void acknowledgeCheckpoint(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointMetrics checkpointMetrics, TaskStateSnapshot subtaskState) {
            super.acknowledgeCheckpoint(jobID, executionAttemptID, checkpointId, checkpointMetrics, subtaskState);
            checkpointCompleted.complete(null);
        }
    };
    try (StreamTaskMailboxTestHarness<Integer> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(SourceOperatorStreamTask::new, BasicTypeInfo.INT_TYPE_INFO).setupOutputForSingletonOperatorChain(sourceOperatorFactory).setCheckpointResponder(checkpointResponder).build()) {
        CompletableFuture<Boolean> triggerResult = testHarness.streamTask.triggerCheckpointAsync(new CheckpointMetaData(2, 2), CheckpointOptions.alignedNoTimeout(SavepointType.terminate(SavepointFormatType.CANONICAL), CheckpointStorageLocationReference.getDefault()));
        checkpointCompleted.whenComplete((ignored, exception) -> testHarness.streamTask.notifyCheckpointCompleteAsync(2));
        testHarness.waitForTaskCompletion();
        testHarness.finishProcessing();
        assertTrue(triggerResult.isDone());
        assertTrue(triggerResult.get());
        assertTrue(checkpointCompleted.isDone());
    }
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TestCheckpointResponder(org.apache.flink.runtime.taskmanager.TestCheckpointResponder) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory) CompletableFuture(java.util.concurrent.CompletableFuture) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) TestCheckpointResponder(org.apache.flink.runtime.taskmanager.TestCheckpointResponder) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 12 with MockSource

use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.

the class StreamingJobGraphGeneratorTest method testCoordinatedOperator.

@Test
public void testCoordinatedOperator() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Integer> source = env.fromSource(new MockSource(Boundedness.BOUNDED, 1), WatermarkStrategy.noWatermarks(), "TestSource");
    source.addSink(new DiscardingSink<>());
    StreamGraph streamGraph = env.getStreamGraph();
    JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(streamGraph);
    // There should be only one job vertex.
    assertEquals(1, jobGraph.getNumberOfVertices());
    JobVertex jobVertex = jobGraph.getVerticesAsArray()[0];
    List<SerializedValue<OperatorCoordinator.Provider>> coordinatorProviders = jobVertex.getOperatorCoordinators();
    // There should be only one coordinator provider.
    assertEquals(1, coordinatorProviders.size());
    // The invokable class should be SourceOperatorStreamTask.
    final ClassLoader classLoader = getClass().getClassLoader();
    assertEquals(SourceOperatorStreamTask.class, jobVertex.getInvokableClass(classLoader));
    StreamOperatorFactory operatorFactory = new StreamConfig(jobVertex.getConfiguration()).getStreamOperatorFactory(classLoader);
    assertTrue(operatorFactory instanceof SourceOperatorFactory);
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) OneInputStreamOperatorFactory(org.apache.flink.streaming.api.operators.OneInputStreamOperatorFactory) StreamOperatorFactory(org.apache.flink.streaming.api.operators.StreamOperatorFactory) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) SerializedValue(org.apache.flink.util.SerializedValue) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 13 with MockSource

use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.

the class StreamGraphGeneratorExecutionModeDetectionTest method testExecutionModePropagationFromEnvWithAutomaticAndBoundedSource.

@Test
public void testExecutionModePropagationFromEnvWithAutomaticAndBoundedSource() {
    final Configuration config = new Configuration();
    config.set(ExecutionOptions.RUNTIME_MODE, RuntimeExecutionMode.AUTOMATIC);
    final StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
    environment.enableCheckpointing(100L);
    environment.configure(config, getClass().getClassLoader());
    environment.fromSource(new MockSource(Boundedness.BOUNDED, 100), WatermarkStrategy.noWatermarks(), "bounded-source").print();
    assertTrue(environment.isChainingEnabled());
    assertThat(environment.getCheckpointInterval(), is(equalTo(100L)));
    final StreamGraph streamGraph = environment.getStreamGraph();
    assertThat(streamGraph, hasProperties(GlobalStreamExchangeMode.ALL_EDGES_BLOCKING, JobType.BATCH, false, false));
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) Configuration(org.apache.flink.configuration.Configuration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 14 with MockSource

use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.

the class StreamingJobGraphGeneratorTest method testOperatorCoordinatorAddedToJobVertex.

@Test
public void testOperatorCoordinatorAddedToJobVertex() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Integer> stream = env.fromSource(new MockSource(Boundedness.BOUNDED, 1), WatermarkStrategy.noWatermarks(), "TestingSource");
    OneInputTransformation<Integer, Integer> resultTransform = new OneInputTransformation<Integer, Integer>(stream.getTransformation(), "AnyName", new CoordinatedTransformOperatorFactory(), BasicTypeInfo.INT_TYPE_INFO, env.getParallelism());
    new TestingSingleOutputStreamOperator<>(env, resultTransform).print();
    JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph());
    assertEquals(2, jobGraph.getVerticesAsArray()[0].getOperatorCoordinators().size());
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Test(org.junit.Test)

Example 15 with MockSource

use of org.apache.flink.api.connector.source.mocks.MockSource in project flink by apache.

the class DataStreamSourceTest method testConstructor.

/**
 * Test constructor for new Sources (FLIP-27).
 */
@Test
public void testConstructor() {
    int expectParallelism = 100;
    boolean expectIsParallel = true;
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    MockSource mockSource = new MockSource(Boundedness.BOUNDED, 10);
    DataStreamSource<Integer> stream = env.fromSource(mockSource, WatermarkStrategy.noWatermarks(), "TestingSource");
    stream.setParallelism(expectParallelism);
    assertEquals(expectIsParallel, stream.isParallel());
    assertEquals(expectParallelism, stream.getParallelism());
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

MockSource (org.apache.flink.api.connector.source.mocks.MockSource)18 Test (org.junit.Test)16 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)7 SourceOperatorFactory (org.apache.flink.streaming.api.operators.SourceOperatorFactory)6 ArrayList (java.util.ArrayList)5 ArrayDeque (java.util.ArrayDeque)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 JobID (org.apache.flink.api.common.JobID)2 SourceReaderContext (org.apache.flink.api.connector.source.SourceReaderContext)2 MockSourceSplit (org.apache.flink.api.connector.source.mocks.MockSourceSplit)2 Gauge (org.apache.flink.metrics.Gauge)2 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)2 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)2 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)2 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)2 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)2