Search in sources :

Example 1 with TestTaskBuilder

use of org.apache.flink.runtime.taskmanager.TestTaskBuilder in project flink by apache.

the class StreamTaskTest method taskBuilderWithConfiguredRecordWriter.

private TestTaskBuilder taskBuilderWithConfiguredRecordWriter(NettyShuffleEnvironment shuffleEnvironment) {
    Configuration taskConfiguration = new Configuration();
    outputEdgeConfiguration(taskConfiguration);
    ResultPartitionDeploymentDescriptor descriptor = new ResultPartitionDeploymentDescriptor(PartitionDescriptorBuilder.newBuilder().build(), NettyShuffleDescriptorBuilder.newBuilder().buildLocal(), 1, false);
    return new TestTaskBuilder(shuffleEnvironment).setInvokable(NoOpStreamTask.class).setTaskConfig(taskConfiguration).setResultPartitions(singletonList(descriptor));
}
Also used : ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) Configuration(org.apache.flink.configuration.Configuration) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder)

Example 2 with TestTaskBuilder

use of org.apache.flink.runtime.taskmanager.TestTaskBuilder in project flink by apache.

the class StreamTaskTest method testEarlyCanceling.

/**
 * This test checks that cancel calls that are issued before the operator is instantiated still
 * lead to proper canceling.
 */
@Test
public void testEarlyCanceling() throws Exception {
    final StreamConfig cfg = new StreamConfig(new Configuration());
    cfg.setOperatorID(new OperatorID(4711L, 42L));
    cfg.setStreamOperator(new SlowlyDeserializingOperator());
    cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);
    final TaskManagerActions taskManagerActions = spy(new NoOpTaskManagerActions());
    try (NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build()) {
        final Task task = new TestTaskBuilder(shuffleEnvironment).setInvokable(SourceStreamTask.class).setTaskConfig(cfg.getConfiguration()).setTaskManagerActions(taskManagerActions).build();
        final TaskExecutionState state = new TaskExecutionState(task.getExecutionId(), ExecutionState.RUNNING);
        task.startTaskThread();
        verify(taskManagerActions, timeout(2000L)).updateTaskExecutionState(eq(state));
        // send a cancel. because the operator takes a long time to deserialize, this should
        // hit the task before the operator is deserialized
        task.cancelExecution();
        task.getExecutingThread().join();
        assertFalse("Task did not cancel", task.getExecutingThread().isAlive());
        assertEquals(ExecutionState.CANCELED, task.getExecutionState());
    }
}
Also used : NoOpTaskManagerActions(org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions) Task(org.apache.flink.runtime.taskmanager.Task) Configuration(org.apache.flink.configuration.Configuration) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) 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) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) NoOpTaskManagerActions(org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions) Test(org.junit.Test)

Example 3 with TestTaskBuilder

use of org.apache.flink.runtime.taskmanager.TestTaskBuilder in project flink by apache.

the class RemoteInputChannelTest method testOnFailedPartitionRequestDoesNotBlockNetworkThreads.

/**
 * Test to guard against FLINK-13249.
 */
@Test
public void testOnFailedPartitionRequestDoesNotBlockNetworkThreads() throws Exception {
    final long testBlockedWaitTimeoutMillis = 30_000L;
    final PartitionProducerStateChecker partitionProducerStateChecker = (jobId, intermediateDataSetId, resultPartitionId) -> CompletableFuture.completedFuture(ExecutionState.RUNNING);
    final NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build();
    final Task task = new TestTaskBuilder(shuffleEnvironment).setPartitionProducerStateChecker(partitionProducerStateChecker).build();
    final SingleInputGate inputGate = new SingleInputGateBuilder().setPartitionProducerStateProvider(task).build();
    TestTaskBuilder.setTaskState(task, ExecutionState.RUNNING);
    final OneShotLatch ready = new OneShotLatch();
    final OneShotLatch blocker = new OneShotLatch();
    final AtomicBoolean timedOutOrInterrupted = new AtomicBoolean(false);
    final ConnectionManager blockingConnectionManager = new TestingConnectionManager() {

        @Override
        public PartitionRequestClient createPartitionRequestClient(ConnectionID connectionId) {
            ready.trigger();
            try {
                // We block here, in a section that holds the
                // SingleInputGate#requestLock
                blocker.await(testBlockedWaitTimeoutMillis, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | TimeoutException e) {
                timedOutOrInterrupted.set(true);
            }
            return new TestingPartitionRequestClient();
        }
    };
    final RemoteInputChannel remoteInputChannel = InputChannelBuilder.newBuilder().setConnectionManager(blockingConnectionManager).buildRemoteChannel(inputGate);
    inputGate.setInputChannels(remoteInputChannel);
    final Thread simulatedNetworkThread = new Thread(() -> {
        try {
            ready.await();
            // We want to make sure that our simulated network thread does not
            // block on
            // SingleInputGate#requestLock as well through this call.
            remoteInputChannel.onFailedPartitionRequest();
            // Will only give free the blocker if we did not block ourselves.
            blocker.trigger();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    });
    simulatedNetworkThread.start();
    // The entry point to that will lead us into
    // blockingConnectionManager#createPartitionRequestClient(...).
    inputGate.requestPartitions();
    simulatedNetworkThread.join();
    Assert.assertFalse("Test ended by timeout or interruption - this indicates that the network thread was blocked.", timedOutOrInterrupted.get());
}
Also used : TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) Arrays(java.util.Arrays) Matchers.isA(org.hamcrest.Matchers.isA) AvailabilityUtil.assertAvailability(org.apache.flink.runtime.io.network.partition.AvailabilityUtil.assertAvailability) ProducerFailedException(org.apache.flink.runtime.io.network.partition.ProducerFailedException) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Random(java.util.Random) PartitionRequestClient(org.apache.flink.runtime.io.network.PartitionRequestClient) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) AvailabilityUtil.assertPriorityAvailability(org.apache.flink.runtime.io.network.partition.AvailabilityUtil.assertPriorityAvailability) Lists(org.apache.flink.shaded.guava30.com.google.common.collect.Lists) Future(java.util.concurrent.Future) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) CheckpointStorageLocationReference.getDefault(org.apache.flink.runtime.state.CheckpointStorageLocationReference.getDefault) Assert.fail(org.junit.Assert.fail) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) EventSerializer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer) TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) InputChannelTestUtils(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils) DataType(org.apache.flink.runtime.io.network.buffer.Buffer.DataType) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) FreeingBufferRecycler(org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) Collectors(java.util.stream.Collectors) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) Executors(java.util.concurrent.Executors) Matchers.any(org.mockito.Matchers.any) CloseableIterator(org.apache.flink.util.CloseableIterator) List(java.util.List) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) TestingPartitionRequestClient(org.apache.flink.runtime.io.network.TestingPartitionRequestClient) Matchers.is(org.hamcrest.Matchers.is) Queue(java.util.Queue) Mockito.mock(org.mockito.Mockito.mock) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) TestBufferFactory(org.apache.flink.runtime.io.network.util.TestBufferFactory) CHECKPOINT(org.apache.flink.runtime.checkpoint.CheckpointType.CHECKPOINT) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) ChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckpointOptions.alignedWithTimeout(org.apache.flink.runtime.checkpoint.CheckpointOptions.alignedWithTimeout) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) Nullable(javax.annotation.Nullable) ExecutorService(java.util.concurrent.ExecutorService) MemorySegment(org.apache.flink.core.memory.MemorySegment) MemorySegmentFactory(org.apache.flink.core.memory.MemorySegmentFactory) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) PartitionProducerStateChecker(org.apache.flink.runtime.taskexecutor.PartitionProducerStateChecker) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) BufferBuilderTestUtils.buildSingleBuffer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer) BufferAndAvailability(org.apache.flink.runtime.io.network.partition.consumer.InputChannel.BufferAndAvailability) Task(org.apache.flink.runtime.taskmanager.Task) Assert.assertNull(org.junit.Assert.assertNull) NoOpBufferPool(org.apache.flink.runtime.io.network.buffer.NoOpBufferPool) Assert(org.junit.Assert) ArrayDeque(java.util.ArrayDeque) PartitionProducerStateProvider(org.apache.flink.runtime.io.network.partition.PartitionProducerStateProvider) Assert.assertEquals(org.junit.Assert.assertEquals) Task(org.apache.flink.runtime.taskmanager.Task) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) PartitionProducerStateChecker(org.apache.flink.runtime.taskexecutor.PartitionProducerStateChecker) TestingPartitionRequestClient(org.apache.flink.runtime.io.network.TestingPartitionRequestClient) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

TestTaskBuilder (org.apache.flink.runtime.taskmanager.TestTaskBuilder)3 Configuration (org.apache.flink.configuration.Configuration)2 NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)2 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)2 Task (org.apache.flink.runtime.taskmanager.Task)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 Random (java.util.Random)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1