This is an automated email from the ASF dual-hosted git repository.

snemeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new 510bfef  SUBMARINE-60. Remove stubServiceClient from YarnServiceUtils
510bfef is described below

commit 510bfefe2e841117c52376e450cfcf3774b9c9b6
Author: Adam Antal <[email protected]>
AuthorDate: Wed Nov 20 15:22:26 2019 +0100

    SUBMARINE-60. Remove stubServiceClient from YarnServiceUtils
    
    ### What is this PR for?
    Remove stubServiceClient from YarnServiceUtils and introduce a Factory 
based injecting solution. (See jira for further details)
    
    ### What type of PR is it?
    Refactoring
    
    ### Todos
    * [ ] - Check whether the refactored test passes.
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/SUBMARINE-60
    
    ### How should this be tested?
    * No need for integration testing, just the UTs.
    
    ### Screenshots (if appropriate)
    -
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Adam Antal <[email protected]>
    
    Closes #96 from adamantal/SUBMARINE-60 and squashes the following commits:
    
    adb6e62 [Adam Antal] SUBMARINE-60. Remove stubServiceClient from 
YarnServiceUtils
---
 .../submitter/yarnservice/YarnServiceUtils.java    | 26 ++++++++++++----------
 .../TestYarnServiceRunJobCliCommons.java           | 19 +++++++++++++---
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git 
a/submarine-server/server-submitter/submitter-yarnservice/src/main/java/org/apache/submarine/server/submitter/yarnservice/YarnServiceUtils.java
 
b/submarine-server/server-submitter/submitter-yarnservice/src/main/java/org/apache/submarine/server/submitter/yarnservice/YarnServiceUtils.java
index 018cbcf..18343fd 100644
--- 
a/submarine-server/server-submitter/submitter-yarnservice/src/main/java/org/apache/submarine/server/submitter/yarnservice/YarnServiceUtils.java
+++ 
b/submarine-server/server-submitter/submitter-yarnservice/src/main/java/org/apache/submarine/server/submitter/yarnservice/YarnServiceUtils.java
@@ -30,24 +30,21 @@ import static 
org.apache.hadoop.yarn.client.api.AppAdminClient.DEFAULT_TYPE;
  * based on the provided parameters.
  */
 public final class YarnServiceUtils {
+  private static AppAdminClientFactory appAdminClientFactory =
+      new AppAdminClientFactory();
+
   private YarnServiceUtils() {
   }
 
-  // This will be true only in UT.
-  private static AppAdminClient stubServiceClient = null;
+  @VisibleForTesting
+  public static void setAppAdminClientFactory(
+      AppAdminClientFactory appAdminClientFactory) {
+    YarnServiceUtils.appAdminClientFactory = appAdminClientFactory;
+  }
 
   static AppAdminClient createServiceClient(
       Configuration yarnConfiguration) {
-    if (stubServiceClient != null) {
-      return stubServiceClient;
-    }
-
-    return AppAdminClient.createAppAdminClient(DEFAULT_TYPE, 
yarnConfiguration);
-  }
-
-  @VisibleForTesting
-  public static void setStubServiceClient(AppAdminClient stubServiceClient) {
-    YarnServiceUtils.stubServiceClient = stubServiceClient;
+    return appAdminClientFactory.createDefault(yarnConfiguration);
   }
 
   public static String getDNSName(String serviceName,
@@ -61,4 +58,9 @@ public final class YarnServiceUtils {
     return "." + serviceName + "." + userName + "." + domain + ":" + port;
   }
 
+  public static class AppAdminClientFactory {
+    public AppAdminClient createDefault(Configuration configuration) {
+      return AppAdminClient.createAppAdminClient(DEFAULT_TYPE, configuration);
+    }
+  }
 }
diff --git 
a/submarine-server/server-submitter/submitter-yarnservice/src/test/java/org/apache/submarine/client/cli/yarnservice/TestYarnServiceRunJobCliCommons.java
 
b/submarine-server/server-submitter/submitter-yarnservice/src/test/java/org/apache/submarine/client/cli/yarnservice/TestYarnServiceRunJobCliCommons.java
index eff2ad6..1317219 100644
--- 
a/submarine-server/server-submitter/submitter-yarnservice/src/test/java/org/apache/submarine/client/cli/yarnservice/TestYarnServiceRunJobCliCommons.java
+++ 
b/submarine-server/server-submitter/submitter-yarnservice/src/test/java/org/apache/submarine/client/cli/yarnservice/TestYarnServiceRunJobCliCommons.java
@@ -19,6 +19,7 @@
 
 package org.apache.submarine.client.cli.yarnservice;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.yarn.client.api.AppAdminClient;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.service.api.records.Service;
@@ -56,14 +57,27 @@ public class TestYarnServiceRunJobCliCommons {
 
   void setup() throws IOException, YarnException {
     SubmarineLogs.verboseOff();
+    AppAdminClient serviceClient = createMockAppAdminClient();
+    createAndSetAppAdminClientFactory(serviceClient);
+    fileUtils.setup();
+  }
+
+  private AppAdminClient createMockAppAdminClient()
+      throws IOException, YarnException {
     AppAdminClient serviceClient = mock(AppAdminClient.class);
     when(serviceClient.actionLaunch(any(String.class), any(String.class),
         any(Long.class), any(String.class))).thenReturn(EXIT_SUCCESS);
     when(serviceClient.getStatusString(any(String.class))).thenReturn(
         "{\"id\": \"application_1234_1\"}");
-    YarnServiceUtils.setStubServiceClient(serviceClient);
+    return serviceClient;
+  }
 
-    fileUtils.setup();
+  private void createAndSetAppAdminClientFactory(AppAdminClient serviceClient) 
{
+    YarnServiceUtils.AppAdminClientFactory appAdminClientFactory =
+        mock(YarnServiceUtils.AppAdminClientFactory.class);
+    when(appAdminClientFactory.createDefault(any(Configuration.class)))
+        .thenReturn(serviceClient);
+    YarnServiceUtils.setAppAdminClientFactory(appAdminClientFactory);
   }
 
   void teardown() throws IOException {
@@ -78,5 +92,4 @@ public class TestYarnServiceRunJobCliCommons {
     return ((YarnServiceJobSubmitter) jobSubmitter).getServiceWrapper()
         .getService();
   }
-
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to