Clarkkkkk commented on a change in pull request #7780: [FLINK-11593][tests] 
Check & port TaskManagerTest to new code base
URL: https://github.com/apache/flink/pull/7780#discussion_r268093968
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
 ##########
 @@ -1760,9 +1797,616 @@ private TaskExecutorLocalStateStoresManager 
createTaskExecutorLocalStateStoresMa
                        Executors.directExecutor());
        }
 
+       /**
+        * Tests that we can cancel the task of the TaskManager given that 
we've submitted it.
+        */
+       @Test(timeout = 10000L)
+       public void testTaskSubmissionAndCancelling() throws Throwable {
+               final JobVertexID vid1 = new JobVertexID();
+               final JobVertexID vid2 = new JobVertexID();
+               final ExecutionAttemptID eid1 = new ExecutionAttemptID();
+               final ExecutionAttemptID eid2 = new ExecutionAttemptID();
+
+               final TaskDeploymentDescriptor tdd1 = 
createTestTaskDeploymentDescriptor("test task", vid1, eid1, 
BlockingNoOpInvokable.class);
+               final TaskDeploymentDescriptor tdd2 = 
createTestTaskDeploymentDescriptor("test task", vid2, eid2, 
BlockingNoOpInvokable.class);
+
+               runTestAfterTaskSubmission(
+                       Arrays.asList(tdd1, tdd2),
+                       null,
+                       (taskManager, taskManagerServices) -> {
+                               TaskSlotTable taskSlotTable = 
taskManagerServices.getTaskSlotTable();
+                               TestTaskManagerActions taskManagerActions =
+                                       (TestTaskManagerActions) 
taskManagerServices.getJobManagerTable().get(jobId).getTaskManagerActions();
+                               
assertTrue(taskSlotTable.getTask(eid1).getExecutionState() == 
ExecutionState.RUNNING);
+                               
assertTrue(taskSlotTable.getTask(eid2).getExecutionState() == 
ExecutionState.RUNNING);
+                               CompletableFuture<Void> canceledFuture = new 
CompletableFuture<>();
+                               taskManagerActions.putCanceledStateFuture(eid1, 
canceledFuture);
+                               CompletableFuture<Acknowledge> 
acknowledgeCompletableFuture = taskManager.cancelTask(eid1, timeout);
+                               acknowledgeCompletableFuture.get();
+                               canceledFuture.get(timeout.toMilliseconds(), 
TimeUnit.MILLISECONDS);
+                               
assertTrue(taskSlotTable.getTask(eid1).getExecutionState() == 
ExecutionState.CANCELED);
+                               
assertTrue(taskSlotTable.getTask(eid2).getExecutionState() == 
ExecutionState.RUNNING);
+                       });
+       }
+
+       /**
+        * Tests that we can stop the task of the TaskManager given that we've 
submitted it.
+        */
+       @Test(timeout = 10000L)
+       public void testTaskSubmissionAndStop() throws Throwable {
+               final JobVertexID vid1 = new JobVertexID();
+               final JobVertexID vid2 = new JobVertexID();
+               final ExecutionAttemptID eid1 = new ExecutionAttemptID();
+               final ExecutionAttemptID eid2 = new ExecutionAttemptID();
+
+               final TaskDeploymentDescriptor tdd1 = 
createTestTaskDeploymentDescriptor("test task", vid1, eid1, 
StoppableInvokable.class);
+               final TaskDeploymentDescriptor tdd2 = 
createTestTaskDeploymentDescriptor("test task", vid2, eid2, 
BlockingNoOpInvokable.class);
+
+               runTestAfterTaskSubmission(
+                       Arrays.asList(tdd1, tdd2),
+                       null,
+                       (taskManager, taskManagerServices) -> {
+                               TaskSlotTable taskSlotTable = 
taskManagerServices.getTaskSlotTable();
+                               
assertTrue(taskSlotTable.getTask(eid1).getExecutionState() == 
ExecutionState.RUNNING);
+                               
assertTrue(taskSlotTable.getTask(eid2).getExecutionState() == 
ExecutionState.RUNNING);
+                               TestTaskManagerActions taskManagerActions =
+                                       (TestTaskManagerActions) 
taskManagerServices.getJobManagerTable().get(jobId).getTaskManagerActions();
+                               CompletableFuture<Void> finishedFuture = new 
CompletableFuture<>();
+                               taskManagerActions.putFinishedStateFuture(eid1, 
finishedFuture);
+                               CompletableFuture<Acknowledge> 
acknowledgeOfTask1 = taskManager.stopTask(eid1, timeout);
+                               acknowledgeOfTask1.get();
+                               finishedFuture.get(timeout.toMilliseconds(), 
TimeUnit.MILLISECONDS);
+                               CompletableFuture<Acknowledge> 
acknowledgeOfTask2 =     taskManager.stopTask(eid2, timeout);
+                               boolean hasTaskException = false;
+                               try {
+                                       acknowledgeOfTask2.get();
+                               } catch (Throwable e) {
+                                       while (e.getCause() != null && 
!(e.getCause() instanceof TaskException)) {
 
 Review comment:
   Thanks for the remind.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to