Search in sources :

Example 36 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamTaskTest method testTaskAvoidHangingAfterSnapshotStateThrownException.

@Test
public void testTaskAvoidHangingAfterSnapshotStateThrownException() throws Exception {
    // given: Configured SourceStreamTask with source which fails on checkpoint.
    Configuration taskManagerConfig = new Configuration();
    taskManagerConfig.setString(STATE_BACKEND, TestMemoryStateBackendFactory.class.getName());
    StreamConfig cfg = new StreamConfig(new Configuration());
    cfg.setStateKeySerializer(mock(TypeSerializer.class));
    cfg.setOperatorID(new OperatorID(4712L, 43L));
    FailedSource failedSource = new FailedSource();
    cfg.setStreamOperator(new TestStreamSource<String, FailedSource>(failedSource));
    cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);
    try (NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build()) {
        Task task = createTask(SourceStreamTask.class, shuffleEnvironment, cfg, taskManagerConfig);
        // when: Task starts
        task.startTaskThread();
        // wait for the task starts doing the work.
        failedSource.awaitRunning();
        // and: Checkpoint is triggered which should lead to exception in Source.
        task.triggerCheckpointBarrier(42L, 1L, CheckpointOptions.forCheckpointWithDefaultLocation());
        // wait for clean termination.
        task.getExecutingThread().join();
        // then: The task doesn't hang but finished with FAILED state.
        assertEquals(ExecutionState.FAILED, task.getExecutionState());
    }
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) Configuration(org.apache.flink.configuration.Configuration) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) MockStreamConfig(org.apache.flink.streaming.util.MockStreamConfig) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) Test(org.junit.Test)

Example 37 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamTaskTest method testThreadInvariants.

/**
 * Tests that some StreamTask methods are called only in the main task's thread. Currently, the
 * main task's thread is the thread that creates the task.
 */
@Test
public void testThreadInvariants() throws Throwable {
    Configuration taskConfiguration = new Configuration();
    StreamConfig streamConfig = new StreamConfig(taskConfiguration);
    streamConfig.setStreamOperator(new StreamMap<>(value -> value));
    streamConfig.setOperatorID(new OperatorID());
    try (MockEnvironment mockEnvironment = new MockEnvironmentBuilder().setTaskConfiguration(taskConfiguration).build()) {
        ClassLoader taskClassLoader = new TestUserCodeClassLoader();
        RunningTask<ThreadInspectingTask> runningTask = runTask(() -> {
            Thread.currentThread().setContextClassLoader(taskClassLoader);
            return new ThreadInspectingTask(mockEnvironment);
        });
        runningTask.invocationFuture.get();
        assertThat(runningTask.streamTask.getTaskClassLoader(), is(sameInstance(taskClassLoader)));
    }
}
Also used : InternalTimeServiceManager(org.apache.flink.streaming.api.operators.InternalTimeServiceManager) NettyShuffleDescriptorBuilder(org.apache.flink.runtime.util.NettyShuffleDescriptorBuilder) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) TaskLocalStateStoreImpl(org.apache.flink.runtime.state.TaskLocalStateStoreImpl) Collections.singletonList(java.util.Collections.singletonList) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AvailabilityTestResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.AvailabilityTestResultPartitionWriter) FunctionWithException(org.apache.flink.util.function.FunctionWithException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FatalExitExceptionHandler(org.apache.flink.util.FatalExitExceptionHandler) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException) Assert.assertFalse(org.junit.Assert.assertFalse) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) OptionalLong(java.util.OptionalLong) MAX_PRIORITY(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailbox.MAX_PRIORITY) Output(org.apache.flink.streaming.api.operators.Output) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MockStreamConfig(org.apache.flink.streaming.util.MockStreamConfig) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) JobID(org.apache.flink.api.common.JobID) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) Assert.assertEquals(org.junit.Assert.assertEquals) TaskStateManagerImpl(org.apache.flink.runtime.state.TaskStateManagerImpl) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) SystemClock(org.apache.flink.util.clock.SystemClock) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) ShuffleEnvironment(org.apache.flink.runtime.shuffle.ShuffleEnvironment) ObjectInputStream(java.io.ObjectInputStream) ExceptionUtils(org.apache.flink.util.ExceptionUtils) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) TimerGauge(org.apache.flink.runtime.metrics.TimerGauge) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckpointStorageLocationReference.getDefault(org.apache.flink.runtime.state.CheckpointStorageLocationReference.getDefault) Matchers.eq(org.mockito.Matchers.eq) BUFFER_DEBLOAT_ENABLED(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_ENABLED) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES) MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Preconditions(org.apache.flink.util.Preconditions) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) CloseableIterable(org.apache.flink.util.CloseableIterable) DEFAULT_OUTPUT_FLUSH_THREAD_NAME(org.apache.flink.runtime.io.network.api.writer.RecordWriter.DEFAULT_OUTPUT_FLUSH_THREAD_NAME) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) Assert.assertThrows(org.junit.Assert.assertThrows) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) ArgumentCaptor(org.mockito.ArgumentCaptor) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamTaskStateInitializer(org.apache.flink.streaming.api.operators.StreamTaskStateInitializer) RichParallelSourceFunction(org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StreamInputProcessor(org.apache.flink.streaming.runtime.io.StreamInputProcessor) ExecutorService(java.util.concurrent.ExecutorService) RunnableFuture(java.util.concurrent.RunnableFuture) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Configuration(org.apache.flink.configuration.Configuration) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) Mockito.when(org.mockito.Mockito.when) Consumer(java.util.function.Consumer) STATE_BACKEND(org.apache.flink.configuration.StateBackendOptions.STATE_BACKEND) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) ProcessingTimeCallback(org.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) TaskIOMetricGroup(org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup) Arrays(java.util.Arrays) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) Executors(java.util.concurrent.Executors) StopMode(org.apache.flink.runtime.io.network.api.StopMode) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SnapshotType(org.apache.flink.runtime.checkpoint.SnapshotType) TaskStateManager(org.apache.flink.runtime.state.TaskStateManager) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) StateHandleID(org.apache.flink.runtime.state.StateHandleID) RunnableWithException(org.apache.flink.util.function.RunnableWithException) STRING_TYPE_INFO(org.apache.flink.api.common.typeinfo.BasicTypeInfo.STRING_TYPE_INFO) ArrayList(java.util.ArrayList) MEMORY_SEGMENT_SIZE(org.apache.flink.configuration.TaskManagerOptions.MEMORY_SEGMENT_SIZE) Mockito.timeout(org.mockito.Mockito.timeout) OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ReadableConfig(org.apache.flink.configuration.ReadableConfig) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter) Nullable(javax.annotation.Nullable) SnapshotResult(org.apache.flink.runtime.state.SnapshotResult) TimeCharacteristic(org.apache.flink.streaming.api.TimeCharacteristic) MailboxDefaultAction(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxDefaultAction) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) InMemoryStateChangelogStorage(org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) Task(org.apache.flink.runtime.taskmanager.Task) SubtaskState(org.apache.flink.runtime.checkpoint.SubtaskState) TestingUncaughtExceptionHandler(org.apache.flink.util.concurrent.TestingUncaughtExceptionHandler) Assert(org.junit.Assert) CoreMatchers(org.hamcrest.CoreMatchers) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) SavepointType(org.apache.flink.runtime.checkpoint.SavepointType) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) StreamTaskUtil.waitTaskIsRunning(org.apache.flink.streaming.util.StreamTaskUtil.waitTaskIsRunning) PartitionDescriptorBuilder(org.apache.flink.runtime.shuffle.PartitionDescriptorBuilder) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) MapFunction(org.apache.flink.api.common.functions.MapFunction) BUFFER_DEBLOAT_PERIOD(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_PERIOD) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) MockStateBackend(org.apache.flink.runtime.state.ttl.mock.MockStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) BUFFER_DEBLOAT_TARGET(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_TARGET) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) AbstractStateBackend(org.apache.flink.runtime.state.AbstractStateBackend) StateObjectCollection.singleton(org.apache.flink.runtime.checkpoint.StateObjectCollection.singleton) List(java.util.List) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) Optional(java.util.Optional) StateBackendFactory(org.apache.flink.runtime.state.StateBackendFactory) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) Environment(org.apache.flink.runtime.execution.Environment) SupplierWithException(org.apache.flink.util.function.SupplierWithException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) NoOpTaskManagerActions(org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE(org.apache.flink.runtime.checkpoint.CheckpointFailureReason.UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) Matchers.anyLong(org.mockito.Matchers.anyLong) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) ExpectedException(org.junit.rules.ExpectedException) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) StreamOperatorStateContext(org.apache.flink.streaming.api.operators.StreamOperatorStateContext) Matchers(org.hamcrest.Matchers) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) DoneFuture(org.apache.flink.runtime.state.DoneFuture) Rule(org.junit.Rule) Closeable(java.io.Closeable) Collections(java.util.Collections) StateInitializationContext(org.apache.flink.runtime.state.StateInitializationContext) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) Configuration(org.apache.flink.configuration.Configuration) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) MockStreamConfig(org.apache.flink.streaming.util.MockStreamConfig) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Example 38 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamTaskMailboxTestHarnessBuilder method initializeSourceInput.

private SourceInputConfig initializeSourceInput(int inputId, SourceInputConfigPlaceHolder sourceInput, StreamNode mainNode) {
    Map<Integer, StreamConfig> transitiveChainedTaskConfigs = streamConfig.getTransitiveChainedTaskConfigs(getClass().getClassLoader());
    Integer maxNodeId = transitiveChainedTaskConfigs.isEmpty() ? StreamConfigChainer.MAIN_NODE_ID : Collections.max(transitiveChainedTaskConfigs.keySet());
    List<StreamEdge> outEdgesInOrder = new LinkedList<>();
    StreamEdge sourceToMainEdge = new StreamEdge(new StreamNode(maxNodeId + inputId + 1337, null, null, (StreamOperator<?>) null, null, null), mainNode, 0, new ForwardPartitioner<>(), null);
    outEdgesInOrder.add(sourceToMainEdge);
    StreamConfig sourceConfig = new StreamConfig(new Configuration());
    sourceConfig.setTimeCharacteristic(streamConfig.getTimeCharacteristic());
    sourceConfig.setOutEdgesInOrder(outEdgesInOrder);
    sourceConfig.setChainedOutputs(outEdgesInOrder);
    sourceConfig.setTypeSerializerOut(sourceInput.getSourceSerializer());
    sourceConfig.setOperatorID(sourceInput.getOperatorId());
    sourceConfig.setStreamOperatorFactory(sourceInput.getSourceOperatorFactory());
    transitiveChainedTaskConfigs.put(sourceToMainEdge.getSourceId(), sourceConfig);
    streamConfig.setTransitiveChainedTaskConfigs(transitiveChainedTaskConfigs);
    return new SourceInputConfig(sourceToMainEdge);
}
Also used : BufferDebloatConfiguration(org.apache.flink.runtime.throughput.BufferDebloatConfiguration) Configuration(org.apache.flink.configuration.Configuration) SourceInputConfig(org.apache.flink.streaming.api.graph.StreamConfig.SourceInputConfig) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) StreamEdge(org.apache.flink.streaming.api.graph.StreamEdge) StreamNode(org.apache.flink.streaming.api.graph.StreamNode) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) LinkedList(java.util.LinkedList)

Example 39 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamTaskTerminationTest method testConcurrentAsyncCheckpointCannotFailFinishedStreamTask.

/**
 * FLINK-6833
 *
 * <p>Tests that a finished stream task cannot be failed by an asynchronous checkpointing
 * operation after the stream task has stopped running.
 */
@Test
public void testConcurrentAsyncCheckpointCannotFailFinishedStreamTask() throws Exception {
    final Configuration taskConfiguration = new Configuration();
    final StreamConfig streamConfig = new StreamConfig(taskConfiguration);
    final NoOpStreamOperator<Long> noOpStreamOperator = new NoOpStreamOperator<>();
    final StateBackend blockingStateBackend = new BlockingStateBackend();
    streamConfig.setStreamOperator(noOpStreamOperator);
    streamConfig.setOperatorID(new OperatorID());
    streamConfig.setStateBackend(blockingStateBackend);
    final long checkpointId = 0L;
    final long checkpointTimestamp = 0L;
    final JobInformation jobInformation = new JobInformation(new JobID(), "Test Job", new SerializedValue<>(new ExecutionConfig()), new Configuration(), Collections.emptyList(), Collections.emptyList());
    final TaskInformation taskInformation = new TaskInformation(new JobVertexID(), "Test Task", 1, 1, BlockingStreamTask.class.getName(), taskConfiguration);
    final TaskManagerRuntimeInfo taskManagerRuntimeInfo = new TestingTaskManagerRuntimeInfo();
    final ShuffleEnvironment<?, ?> shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build();
    final Task task = new Task(jobInformation, taskInformation, new ExecutionAttemptID(), new AllocationID(), 0, 0, Collections.<ResultPartitionDeploymentDescriptor>emptyList(), Collections.<InputGateDeploymentDescriptor>emptyList(), MemoryManagerBuilder.newBuilder().setMemorySize(32L * 1024L).build(), new IOManagerAsync(), shuffleEnvironment, new KvStateService(new KvStateRegistry(), null, null), mock(BroadcastVariableManager.class), new TaskEventDispatcher(), ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES, new TestTaskStateManager(), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), new NoOpTaskOperatorEventGateway(), new TestGlobalAggregateManager(), TestingClassLoaderLease.newBuilder().build(), mock(FileCache.class), taskManagerRuntimeInfo, UnregisteredMetricGroups.createUnregisteredTaskMetricGroup(), new NoOpResultPartitionConsumableNotifier(), mock(PartitionProducerStateChecker.class), Executors.directExecutor());
    CompletableFuture<Void> taskRun = CompletableFuture.runAsync(() -> task.run(), TestingUtils.defaultExecutor());
    // wait until the stream task started running
    RUN_LATCH.await();
    // trigger a checkpoint
    task.triggerCheckpointBarrier(checkpointId, checkpointTimestamp, CheckpointOptions.forCheckpointWithDefaultLocation());
    // wait until the task has completed execution
    taskRun.get();
    // check that no failure occurred
    if (task.getFailureCause() != null) {
        throw new Exception("Task failed", task.getFailureCause());
    }
    // check that we have entered the finished state
    assertEquals(ExecutionState.FINISHED, task.getExecutionState());
}
Also used : KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) FutureTask(java.util.concurrent.FutureTask) Task(org.apache.flink.runtime.taskmanager.Task) Configuration(org.apache.flink.configuration.Configuration) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) TaskManagerRuntimeInfo(org.apache.flink.runtime.taskmanager.TaskManagerRuntimeInfo) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) StateBackend(org.apache.flink.runtime.state.StateBackend) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) KvStateService(org.apache.flink.runtime.taskexecutor.KvStateService) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) NoOpTaskOperatorEventGateway(org.apache.flink.runtime.taskmanager.NoOpTaskOperatorEventGateway) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) PartitionProducerStateChecker(org.apache.flink.runtime.taskexecutor.PartitionProducerStateChecker) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) JobInformation(org.apache.flink.runtime.executiongraph.JobInformation) TaskInformation(org.apache.flink.runtime.executiongraph.TaskInformation) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) NoOpResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.NoOpResultPartitionConsumableNotifier) TestGlobalAggregateManager(org.apache.flink.runtime.taskexecutor.TestGlobalAggregateManager) FlinkException(org.apache.flink.util.FlinkException) IOException(java.io.IOException) FileCache(org.apache.flink.runtime.filecache.FileCache) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) Matchers.anyLong(org.mockito.Matchers.anyLong) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 40 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamTaskCancellationTest method testCancelTaskExceptionHandling.

/**
 * CancelTaskException can be thrown in a down stream task, for example if an upstream task was
 * cancelled first and those two tasks were connected via {@link
 * org.apache.flink.runtime.io.network.partition.consumer.LocalInputChannel}. {@link StreamTask}
 * should be able to correctly handle such situation.
 */
@Test
public void testCancelTaskExceptionHandling() throws Exception {
    StreamConfig cfg = new StreamConfig(new Configuration());
    try (NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build()) {
        Task task = createTask(CancelThrowingTask.class, shuffleEnvironment, cfg, new Configuration());
        task.startTaskThread();
        task.getExecutingThread().join();
        assertEquals(ExecutionState.CANCELED, task.getExecutionState());
    }
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) StreamTaskTest.createTask(org.apache.flink.streaming.runtime.tasks.StreamTaskTest.createTask) Configuration(org.apache.flink.configuration.Configuration) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) Test(org.junit.Test)

Aggregations

StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)98 Test (org.junit.Test)57 Configuration (org.apache.flink.configuration.Configuration)41 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)40 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)16 Task (org.apache.flink.runtime.taskmanager.Task)16 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)14 ArrayList (java.util.ArrayList)13 StreamEdge (org.apache.flink.streaming.api.graph.StreamEdge)13 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)12 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)12 StreamMap (org.apache.flink.streaming.api.operators.StreamMap)12 Environment (org.apache.flink.runtime.execution.Environment)9 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)8 CoStreamMap (org.apache.flink.streaming.api.operators.co.CoStreamMap)8 OneInputStreamTaskTestHarness (org.apache.flink.streaming.runtime.tasks.OneInputStreamTaskTestHarness)8 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)8 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)7