xintongsong commented on a change in pull request #13311: URL: https://github.com/apache/flink/pull/13311#discussion_r485430987
########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/TestingYarnNodeManagerClientFactory.java ########## @@ -0,0 +1,50 @@ +/* + * 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.client.api.async.NMClientAsync; + +/** + * A {@link YarnNodeManagerClientFactory} implementation for testing. + */ +public class TestingYarnNodeManagerClientFactory implements YarnNodeManagerClientFactory { + + private NMClientAsync.CallbackHandler callbackHandler; + private TestingYarnNMClientAsync testingYarnNMClientAsync; + private TestingYarnNMClientAsync.Builder testingYarnNMClientAsyncBuilder = TestingYarnNMClientAsync.builder(); + + TestingYarnNMClientAsync.Builder getTestingYarnNMClientAsyncBuilder() { + return testingYarnNMClientAsyncBuilder; + } Review comment: This ties `TestingYarnNodeManagerClientFactory` with `TestingYarnNMClientAsync`. I think a more flexible approach is to pass in a `Function<NMClientAsync.CallbackHandler, NMClientAsync>`. In that way, we also don't need to provide `getCallbackHandler()` and `getTestingYarnNMClientAsync()`. Same for `TestingYarnResourceManagerClientFactory`. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/TestingRegisterApplicationMasterResponse.java ########## @@ -0,0 +1,48 @@ +/* + * 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.protocolrecords.RegisterApplicationMasterResponse; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; +import org.apache.hadoop.yarn.api.records.Container; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.function.Supplier; + +/** + * A Yarn {@link RegisterApplicationMasterResponse} implementation for testing. + */ +public class TestingRegisterApplicationMasterResponse extends RegisterApplicationMasterResponsePBImpl { + private final Supplier<List<Container>> getContainersFromPreviousAttemptsSupplier; + + TestingRegisterApplicationMasterResponse(Supplier<List<Container>> getContainersFromPreviousAttemptsSupplier) { + this.getContainersFromPreviousAttemptsSupplier = getContainersFromPreviousAttemptsSupplier; + } + + public List<Container> getContainersFromPreviousAttempts() { + return getContainersFromPreviousAttemptsSupplier.get(); + } + + @SuppressWarnings("unchecked") + public EnumSet getSchedulerResourceTypes() { + return EnumSet.copyOf(Collections.<Enum>emptySet()); + } Review comment: nit: Let's comment that `@Override` is intentionally removed for these two methods and explain the reason. Just in case somebody try to "fix" it in future. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/TestingYarnAMRMClientAsync.java ########## @@ -111,23 +115,35 @@ static Builder builder() { return new Builder(); } + CompletableFuture<Void> getClientInitFuture() { + return clientInitFuture; + } + + CompletableFuture<Void> getClientStartFuture() { + return clientStartFuture; + } + + CompletableFuture<Void> getClientStopFuture() { + return clientStopFuture; + } + // ------------------------------------------------------------------------ // Override lifecycle methods to avoid actually starting the service // ------------------------------------------------------------------------ @Override protected void serviceInit(Configuration conf) throws Exception { - // noop + clientInitFuture.complete(null); } @Override protected void serviceStart() throws Exception { - // noop + clientStartFuture.complete(null); } @Override protected void serviceStop() throws Exception { - // noop + clientStopFuture.complete(null); } Review comment: I think we'd better override `init`, `start` and `stop`, rather than the current `serviceInit`, `serviceStart` and `serviceStop`, to completely prevent behaviors of `AMRMClientAsyncImpl`. The problem is not introduce by this PR though. Same for `TestingYarnNMClientAsync`. ########## File path: flink-yarn/src/test/java/org/apache/flink/yarn/TestingYarnAMRMClientAsync.java ########## @@ -52,6 +53,9 @@ private volatile Consumer<Integer> setHeartbeatIntervalConsumer; private volatile TriFunction<String, Integer, String, RegisterApplicationMasterResponse> registerApplicationMasterFunction; private volatile TriConsumer<FinalApplicationStatus, String, String> unregisterApplicationMasterConsumer; + private final CompletableFuture<Void> clientInitFuture = new CompletableFuture<>(); + private final CompletableFuture<Void> clientStartFuture = new CompletableFuture<>(); + private final CompletableFuture<Void> clientStopFuture = new CompletableFuture<>(); Review comment: Let's replace the futures with consumers and runnables, leaving defining the behaviors to the callers. Same for `TestingYarnNMClientAsync`. ---------------------------------------------------------------- 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: us...@infra.apache.org