zentol 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_r269524405
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestTaskManagerActions.java
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.taskexecutor;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.jobmaster.JobMasterGateway;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable;
+import org.apache.flink.runtime.taskmanager.TaskExecutionState;
+import org.apache.flink.runtime.taskmanager.TaskManagerActions;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Customized {@link TaskManagerActions} that wait for ExecutionState changes.
+ */
+public class TestTaskManagerActions implements TaskManagerActions {
+
+       public static CompletableFuture<Throwable> fatalErrorFuture = new 
CompletableFuture<>();
+       private JobMasterGateway jobMasterGateway;
+       private TaskSlotTable taskSlotTable;
+       private TaskManagerActionListeners taskManagerActionListeners = new 
TaskManagerActionListeners();
+
+       public TestTaskManagerActions() {
+       }
+
+       public void addListener(ExecutionAttemptID eid, ExecutionState 
executionState, CompletableFuture<Void> future) {
+               taskManagerActionListeners.addListener(eid, executionState, 
future);
+       }
+
+
+       public void setTaskSlotTable(TaskSlotTable taskSlotTable) {
+               this.taskSlotTable = taskSlotTable;
+       }
+
+       public void setJobMasterGateway(JobMasterGateway jobMasterGateway) {
+               this.jobMasterGateway = jobMasterGateway;
+       }
+
+       @Override public void notifyFatalError(String message, Throwable cause) 
{
+               fatalErrorFuture.complete(cause);
+       }
+
+       @Override public void failTask(ExecutionAttemptID executionAttemptID, 
Throwable cause) {
+               if (taskSlotTable != null) {
+                       
taskSlotTable.getTask(executionAttemptID).failExternally(cause);
+               }
+       }
+
+       @Override public void updateTaskExecutionState(TaskExecutionState 
taskExecutionState) {
+               CompletableFuture<Void> listenerFuture =
+                       
taskManagerActionListeners.getListenerFuture(taskExecutionState.getID(), 
taskExecutionState.getExecutionState());
+               if (listenerFuture != null) {
+                       listenerFuture.complete(null);
+               }
+               if (jobMasterGateway != null) {
+                       CompletableFuture<Acknowledge> futureAcknowledge = 
jobMasterGateway.updateTaskExecutionState(taskExecutionState);
+
+                       futureAcknowledge.whenComplete(
+                               (ack, throwable) -> {
+                                       if (throwable != null) {
+                                               
failTask(taskExecutionState.getID(), throwable);
+                                       }
+                               }
+                       );
+               }
+       }
+
+       public static class TaskManagerActionListeners {
 
 Review comment:
   can be private

----------------------------------------------------------------
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