Search in sources :

Example 1 with MockStreamTask

use of org.apache.flink.streaming.util.MockStreamTask in project flink by apache.

the class InputProcessorUtilTest method testCreateCheckpointedMultipleInputGate.

@Test
public void testCreateCheckpointedMultipleInputGate() throws Exception {
    try (CloseableRegistry registry = new CloseableRegistry()) {
        MockEnvironment environment = new MockEnvironmentBuilder().build();
        MockStreamTask streamTask = new MockStreamTaskBuilder(environment).build();
        StreamConfig streamConfig = new StreamConfig(environment.getJobConfiguration());
        streamConfig.setCheckpointMode(CheckpointingMode.EXACTLY_ONCE);
        streamConfig.setUnalignedCheckpointsEnabled(true);
        // First input gate has index larger than the second
        List<IndexedInputGate>[] inputGates = new List[] { Collections.singletonList(getGate(1, 4)), Collections.singletonList(getGate(0, 2)) };
        CheckpointBarrierHandler barrierHandler = InputProcessorUtil.createCheckpointBarrierHandler(streamTask, streamConfig, new TestSubtaskCheckpointCoordinator(new MockChannelStateWriter()), streamTask.getName(), inputGates, Collections.emptyList(), new SyncMailboxExecutor(), new TestProcessingTimeService());
        CheckpointedInputGate[] checkpointedMultipleInputGate = InputProcessorUtil.createCheckpointedMultipleInputGate(new SyncMailboxExecutor(), inputGates, environment.getMetricGroup().getIOMetricGroup(), barrierHandler, streamConfig);
        for (CheckpointedInputGate checkpointedInputGate : checkpointedMultipleInputGate) {
            registry.registerCloseable(checkpointedInputGate);
        }
        List<IndexedInputGate> allInputGates = Arrays.stream(inputGates).flatMap(gates -> gates.stream()).collect(Collectors.toList());
        for (IndexedInputGate inputGate : allInputGates) {
            for (int channelId = 0; channelId < inputGate.getNumberOfInputChannels(); channelId++) {
                barrierHandler.processBarrier(new CheckpointBarrier(1, 42, CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, CheckpointStorageLocationReference.getDefault())), new InputChannelInfo(inputGate.getGateIndex(), channelId), false);
            }
        }
        assertTrue(barrierHandler.getAllBarriersReceivedFuture(1).isDone());
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) Arrays(java.util.Arrays) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) CheckpointingMode(org.apache.flink.streaming.api.CheckpointingMode) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestSubtaskCheckpointCoordinator(org.apache.flink.streaming.runtime.tasks.TestSubtaskCheckpointCoordinator) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) Collectors(java.util.stream.Collectors) List(java.util.List) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) Collections(java.util.Collections) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestSubtaskCheckpointCoordinator(org.apache.flink.streaming.runtime.tasks.TestSubtaskCheckpointCoordinator) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) List(java.util.List) Test(org.junit.Test)

Example 2 with MockStreamTask

use of org.apache.flink.streaming.util.MockStreamTask in project flink by apache.

the class StreamSourceOperatorWatermarksTest method setupSourceOperator.

// ------------------------------------------------------------------------
@SuppressWarnings("unchecked")
private static <T> MockStreamTask setupSourceOperator(StreamSource<T, ?> operator, TimeCharacteristic timeChar, long watermarkInterval, final TimerService timeProvider) throws Exception {
    ExecutionConfig executionConfig = new ExecutionConfig();
    executionConfig.setAutoWatermarkInterval(watermarkInterval);
    StreamConfig cfg = new StreamConfig(new Configuration());
    cfg.setStateBackend(new MemoryStateBackend());
    cfg.setTimeCharacteristic(timeChar);
    cfg.setOperatorID(new OperatorID());
    Environment env = new DummyEnvironment("MockTwoInputTask", 1, 0);
    MockStreamTask mockTask = new MockStreamTaskBuilder(env).setConfig(cfg).setExecutionConfig(executionConfig).setTimerService(timeProvider).build();
    operator.setup(mockTask, cfg, (Output<StreamRecord<T>>) mock(Output.class));
    return mockTask;
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Configuration(org.apache.flink.configuration.Configuration) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) Environment(org.apache.flink.runtime.execution.Environment) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID)

Example 3 with MockStreamTask

use of org.apache.flink.streaming.util.MockStreamTask in project flink by apache.

the class StreamSourceOperatorLatencyMetricsTest method setupSourceOperator.

// ------------------------------------------------------------------------
@SuppressWarnings("unchecked")
private static <T> void setupSourceOperator(StreamSource<T, ?> operator, ExecutionConfig executionConfig, Environment env, TimerService timerService) {
    StreamConfig cfg = new StreamConfig(new Configuration());
    cfg.setStateBackend(new MemoryStateBackend());
    cfg.setTimeCharacteristic(TimeCharacteristic.EventTime);
    cfg.setOperatorID(new OperatorID());
    try {
        MockStreamTask mockTask = new MockStreamTaskBuilder(env).setConfig(cfg).setExecutionConfig(executionConfig).setTimerService(timerService).build();
        operator.setProcessingTimeService(mockTask.getProcessingTimeServiceFactory().createProcessingTimeService(null));
        operator.setup(mockTask, cfg, (Output<StreamRecord<T>>) mock(Output.class));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Configuration(org.apache.flink.configuration.Configuration) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID)

Aggregations

StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)3 MockStreamTask (org.apache.flink.streaming.util.MockStreamTask)3 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)3 Configuration (org.apache.flink.configuration.Configuration)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)2 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)1 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)1 CheckpointType (org.apache.flink.runtime.checkpoint.CheckpointType)1 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)1 MockChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter)1 Environment (org.apache.flink.runtime.execution.Environment)1 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)1 IndexedInputGate (org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate)1