xintongsong commented on a change in pull request #11248: [FLINK-16299] Release 
containers recovered from previous attempt in w…
URL: https://github.com/apache/flink/pull/11248#discussion_r385994939
 
 

 ##########
 File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/TestingNMClientAsync.java
 ##########
 @@ -0,0 +1,107 @@
+/*
+ * 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.yarn;
+
+import org.apache.hadoop.yarn.api.records.Container;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.ContainerStatus;
+import org.apache.hadoop.yarn.api.records.NodeId;
+import org.apache.hadoop.yarn.client.api.async.NMClientAsync;
+
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+
+/**
+ * Testing implementation of {@link NMClientAsync} for tests.
+ */
+public class TestingNMClientAsync extends NMClientAsync {
+       private final BiFunction<ContainerId, NodeId, ContainerStatus> 
getContainerStatusAsyncBiFunction;
+       private final BiConsumer<Container, ContainerLaunchContext> 
startContainerAsyncBiConsumer;
+       private final BiConsumer<ContainerId, NodeId> 
stopContainerAsyncBiConsumer;
+
+       private TestingNMClientAsync(
+                       CallbackHandler callbackHandler,
+                       BiFunction<ContainerId, NodeId, ContainerStatus> 
getContainerStatusAsyncBiFunction,
+                       BiConsumer<Container, ContainerLaunchContext> 
startContainerAsyncBiConsumer,
+                       BiConsumer<ContainerId, NodeId> 
stopContainerAsyncBiConsumer) {
+               super(callbackHandler);
+               this.getContainerStatusAsyncBiFunction = 
getContainerStatusAsyncBiFunction;
+               this.startContainerAsyncBiConsumer = 
startContainerAsyncBiConsumer;
+               this.stopContainerAsyncBiConsumer = 
stopContainerAsyncBiConsumer;
+       }
+
+       @Override
+       public void startContainerAsync(Container container, 
ContainerLaunchContext containerLaunchContext) {
+               startContainerAsyncBiConsumer.accept(container, 
containerLaunchContext);
+       }
+
+       @Override
+       public void stopContainerAsync(ContainerId containerId, NodeId nodeId) {
+               stopContainerAsyncBiConsumer.accept(containerId, nodeId);
+       }
+
+       @Override
+       public void getContainerStatusAsync(ContainerId containerId, NodeId 
nodeId) {
+               callbackHandler.onContainerStatusReceived(containerId, 
getContainerStatusAsyncBiFunction.apply(containerId, nodeId));
+       }
+
+       public static Builder newBuilder(NMClientAsync.CallbackHandler 
callbackHandler) {
+               return new Builder(callbackHandler);
+       }
+
+       /**
+        * Builder for {@link TestingNMClientAsync}.
+        */
+       public static class Builder {
+               private BiFunction<ContainerId, NodeId, ContainerStatus> 
getContainerStatusAsyncBiFunction = (containerId, nodeId) -> {
+                       throw new UnsupportedOperationException("No 
getContainerStatusAsync function has been set.");
+               };
+               private BiConsumer<Container, ContainerLaunchContext> 
startContainerAsyncBiConsumer = (container, containerLaunchContext) -> {};
+               private BiConsumer<ContainerId, NodeId> 
stopContainerAsyncBiConsumer = (containerId, nodeId) -> {};
+               private NMClientAsync.CallbackHandler callbackHandler;
 
 Review comment:
   nit: this could be `final`.

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