use of org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions 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());
}
}
use of org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions in project flink by apache.
the class StreamTaskTest method testRecordWriterClosedOnTransitStateError.
private void testRecordWriterClosedOnTransitStateError(ExecutionState executionState) throws Exception {
// Throw the exception when the state updating to the expected one.
NoOpTaskManagerActions taskManagerActions = new NoOpTaskManagerActions() {
@Override
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
if (taskExecutionState.getExecutionState() == executionState) {
throw new ExpectedTestException();
}
}
};
testRecordWriterClosedOnError(env -> taskBuilderWithConfiguredRecordWriter(env).setTaskManagerActions(taskManagerActions).build());
}
use of org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions in project flink by apache.
the class TaskExecutorPartitionLifecycleTest method testJobMasterConnectionTerminationAfterExternalReleaseOrPromotion.
private void testJobMasterConnectionTerminationAfterExternalReleaseOrPromotion(TriConsumer<TaskExecutorGateway, JobID, ResultPartitionID> releaseOrPromoteCall) throws Exception {
final CompletableFuture<Void> disconnectFuture = new CompletableFuture<>();
final JobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder().setDisconnectTaskManagerFunction(resourceID -> {
disconnectFuture.complete(null);
return CompletableFuture.completedFuture(Acknowledge.get());
}).build();
final DefaultJobTable jobTable = DefaultJobTable.create();
final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setJobTable(jobTable).setShuffleEnvironment(new NettyShuffleEnvironmentBuilder().build()).setTaskSlotTable(createTaskSlotTable()).build();
final TestingTaskExecutorPartitionTracker partitionTracker = new TestingTaskExecutorPartitionTracker();
final AtomicBoolean trackerIsTrackingPartitions = new AtomicBoolean(false);
partitionTracker.setIsTrackingPartitionsForFunction(jobId -> trackerIsTrackingPartitions.get());
final CompletableFuture<Collection<ResultPartitionID>> firstReleasePartitionsCallFuture = new CompletableFuture<>();
partitionTracker.setStopTrackingAndReleasePartitionsConsumer(firstReleasePartitionsCallFuture::complete);
final ResultPartitionDeploymentDescriptor resultPartitionDeploymentDescriptor = PartitionTestUtils.createPartitionDeploymentDescriptor(ResultPartitionType.BLOCKING);
final ResultPartitionID resultPartitionId = resultPartitionDeploymentDescriptor.getShuffleDescriptor().getResultPartitionID();
final TestingTaskExecutor taskExecutor = createTestingTaskExecutor(taskManagerServices, partitionTracker);
try {
taskExecutor.start();
taskExecutor.waitUntilStarted();
TaskSubmissionTestEnvironment.registerJobMasterConnection(jobTable, jobId, rpc, jobMasterGateway, new NoOpTaskManagerActions(), timeout, taskExecutor.getMainThreadExecutableForTesting());
final TaskExecutorGateway taskExecutorGateway = taskExecutor.getSelfGateway(TaskExecutorGateway.class);
trackerIsTrackingPartitions.set(true);
assertThat(firstReleasePartitionsCallFuture.isDone(), is(false));
taskExecutorGateway.releaseOrPromotePartitions(jobId, Collections.singleton(new ResultPartitionID()), Collections.emptySet());
// at this point we only know that the TE has entered releasePartitions; we cannot be
// certain whether it
// has already checked whether it should disconnect or not
firstReleasePartitionsCallFuture.get();
// connection should be kept alive since the table still contains partitions
assertThat(disconnectFuture.isDone(), is(false));
trackerIsTrackingPartitions.set(false);
// the TM should check whether partitions are still stored, and afterwards terminate the
// connection
releaseOrPromoteCall.accept(taskExecutorGateway, jobId, resultPartitionId);
disconnectFuture.get();
} finally {
RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
}
}
Aggregations