[NO ISSUE] Fix duplicate -Xmx args being passed

The -Xmx override was looking for " -Xmx" instead of "-Xmx".
Added a test to stop regression.

Change-Id: I7e59be72fcc9aea3c315c2cee5339c1c7573ef51
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2206
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Tested-by: Michael Blow <mblow@apache.org>
diff --git a/asterixdb/asterix-server/src/test/resources/NCServiceExecutionIT/cc.conf b/asterixdb/asterix-server/src/test/resources/NCServiceExecutionIT/cc.conf
index a6cb064..fd7e268 100644
--- a/asterixdb/asterix-server/src/test/resources/NCServiceExecutionIT/cc.conf
+++ b/asterixdb/asterix-server/src/test/resources/NCServiceExecutionIT/cc.conf
@@ -34,7 +34,7 @@
 address=127.0.0.1
 command=asterixnc
 app.class=org.apache.asterix.hyracks.bootstrap.NCApplication
-jvm.args=-Xmx4096m -Dnode.Resolver="org.apache.asterix.external.util.IdentitiyResolverFactory"
+jvm.args=-Xmx4g -Dnode.Resolver="org.apache.asterix.external.util.IdentitiyResolverFactory"
 storage.subdir=test_storage
 storage.memorycomponent.globalbudget = 1073741824
 
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-nc-service/src/main/java/org/apache/hyracks/control/nc/service/NCService.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-nc-service/src/main/java/org/apache/hyracks/control/nc/service/NCService.java
index 9da3502..c0e5678 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-nc-service/src/main/java/org/apache/hyracks/control/nc/service/NCService.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-nc-service/src/main/java/org/apache/hyracks/control/nc/service/NCService.java
@@ -131,15 +131,15 @@
         }
 
         // Sets up memory parameter if it is not specified.
-        if (!jvmargs.contains(" -Xmx")) {
+        if (!jvmargs.contains("-Xmx")) {
             long ramSize = ((com.sun.management.OperatingSystemMXBean) osMXBean).getTotalPhysicalMemorySize();
             int proportionalRamSize = (int) Math.ceil(0.6 * ramSize / (1024 * 1024));
             //if under 32bit JVM, use less than 1GB heap by default. otherwise use proportional ramsize.
             int heapSize = "32".equals(System.getProperty("sun.arch.data.model"))
                     ? (proportionalRamSize <= 1024 ? proportionalRamSize : 1024) : proportionalRamSize;
             jvmargs = jvmargs + " -Xmx" + heapSize + "m";
-            env.put("JAVA_OPTS", jvmargs.trim());
         }
+        env.put("JAVA_OPTS", jvmargs.trim());
         LOGGER.info("Setting JAVA_OPTS to " + jvmargs);
     }
 
diff --git a/hyracks-fullstack/hyracks/hyracks-server/pom.xml b/hyracks-fullstack/hyracks/hyracks-server/pom.xml
index 68639ae..8ad94e3 100644
--- a/hyracks-fullstack/hyracks/hyracks-server/pom.xml
+++ b/hyracks-fullstack/hyracks/hyracks-server/pom.xml
@@ -150,6 +150,11 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.hyracks</groupId>
+      <artifactId>hyracks-util</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
     </dependency>
@@ -163,10 +168,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-control-nc</artifactId>
       <version>${project.version}</version>
diff --git a/hyracks-fullstack/hyracks/hyracks-server/src/test/java/org/apache/hyracks/server/test/NCServiceIT.java b/hyracks-fullstack/hyracks/hyracks-server/src/test/java/org/apache/hyracks/server/test/NCServiceIT.java
index fda099e..c3bdb2a 100644
--- a/hyracks-fullstack/hyracks/hyracks-server/src/test/java/org/apache/hyracks/server/test/NCServiceIT.java
+++ b/hyracks-fullstack/hyracks/hyracks-server/src/test/java/org/apache/hyracks/server/test/NCServiceIT.java
@@ -21,10 +21,12 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
+import java.util.Iterator;
 import java.util.logging.Logger;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import junit.framework.Assert;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpResponse;
@@ -34,20 +36,17 @@
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
 import org.apache.hyracks.server.process.HyracksVirtualCluster;
+import org.apache.hyracks.util.file.FileUtil;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class NCServiceIT {
 
-    private static final String TARGET_DIR = StringUtils
-            .join(new String[] { ".", "target" }, File.separator);
-    private static final String LOG_DIR = StringUtils
-            .join(new String[] { TARGET_DIR, "failsafe-reports" }, File.separator);
-    private static final String RESOURCE_DIR = StringUtils
-            .join(new String[] { TARGET_DIR, "test-classes", "NCServiceIT" }, File.separator);
-    private static final String APP_HOME = StringUtils
-            .join(new String[] { TARGET_DIR, "appassembler" }, File.separator);
+    private static final String TARGET_DIR = FileUtil.joinPath(".", "target");
+    private static final String LOG_DIR = FileUtil.joinPath(TARGET_DIR, "failsafe-reports");
+    private static final String RESOURCE_DIR = FileUtil.joinPath(TARGET_DIR, "test-classes", "NCServiceIT");
+    private static final String APP_HOME = FileUtil.joinPath(TARGET_DIR, "appassembler");
     private static final Logger LOGGER = Logger.getLogger(NCServiceIT.class.getName());
 
     private static HyracksVirtualCluster cluster = null;
@@ -55,31 +54,20 @@
     @BeforeClass
     public static void setUp() throws Exception {
         cluster = new HyracksVirtualCluster(new File(APP_HOME), null);
-        cluster.addNCService(
-                new File(RESOURCE_DIR, "nc-red.conf"),
-                new File(LOG_DIR, "nc-red.log")
-        );
-        cluster.addNCService(
-                new File(RESOURCE_DIR, "nc-blue.conf"),
-                new File(LOG_DIR, "nc-blue.log")
-        );
+        cluster.addNCService(new File(RESOURCE_DIR, "nc-red.conf"), new File(LOG_DIR, "nc-red.log"));
+        cluster.addNCService(new File(RESOURCE_DIR, "nc-blue.conf"), new File(LOG_DIR, "nc-blue.log"));
 
         try {
             Thread.sleep(2000);
-        }
-        catch (InterruptedException ignored) {
+        } catch (InterruptedException ignored) {
         }
 
         // Start CC
-        cluster.start(
-                new File(RESOURCE_DIR, "cc.conf"),
-                new File(LOG_DIR, "cc.log")
-        );
+        cluster.start(new File(RESOURCE_DIR, "cc.conf"), new File(LOG_DIR, "cc.log"));
 
         try {
             Thread.sleep(10000);
-        }
-        catch (InterruptedException ignored) {
+        } catch (InterruptedException ignored) {
         }
     }
 
@@ -108,15 +96,20 @@
         }
     }
 
+    private JsonNode getEndpoint(String endpoint) throws Exception {
+        ObjectMapper om = new ObjectMapper();
+        String localhost = InetAddress.getLoopbackAddress().getHostAddress();
+        String response = getHttp("http://" + localhost + ":12345" + endpoint);
+        JsonNode result = om.readTree(response);
+        JsonNode nodes = result.get("result");
+        return nodes;
+    }
+
     @Test
     public void IsNodelistCorrect() throws Exception {
         // Ping the nodelist HTTP API
 
-        ObjectMapper om = new ObjectMapper();
-        String localhost = InetAddress.getLoopbackAddress().getHostAddress();
-        String response = getHttp("http://" + localhost + ":12345/rest/nodes");
-        JsonNode result = om.readTree(response);
-        JsonNode nodes = result.get("result");
+        JsonNode nodes = getEndpoint("/rest/nodes");
         int numNodes = nodes.size();
         Assert.assertEquals("Wrong number of nodes!", 2, numNodes);
         for (int i = 0; i < nodes.size(); i++) {
@@ -129,6 +122,18 @@
         }
     }
 
+    @Test
+    public void isXmxOverrideCorrect() throws Exception {
+        ArrayNode inputArgs = (ArrayNode) getEndpoint("/rest/nodes/red").get("input-arguments");
+        for (Iterator<JsonNode> it = inputArgs.elements(); it.hasNext();) {
+            String s = it.next().asText();
+            if (s.startsWith("-Xmx") && s.endsWith("m")) {
+                String digits = s.substring(4, 8);
+                Assert.assertEquals("1234", digits);
+            }
+        }
+    }
+
     public static void main(String[] args) throws Exception {
         try {
             setUp();
diff --git a/hyracks-fullstack/hyracks/hyracks-server/src/test/resources/NCServiceIT/cc.conf b/hyracks-fullstack/hyracks/hyracks-server/src/test/resources/NCServiceIT/cc.conf
index 69676f7..419b8ca 100644
--- a/hyracks-fullstack/hyracks/hyracks-server/src/test/resources/NCServiceIT/cc.conf
+++ b/hyracks-fullstack/hyracks/hyracks-server/src/test/resources/NCServiceIT/cc.conf
@@ -18,6 +18,7 @@
 [nc/red]
 address = 127.0.0.1
 #jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006
+jvm.args= -Xmx1234m
 
 [nc/blue]
 address = 127.0.0.1