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

ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new f0ce689fb8 Use CLASSPATH env instead of `-cp` (#2617)
f0ce689fb8 is described below

commit f0ce689fb8f038adddda9373cd1d6486e1930212
Author: Christopher Tubbs <ctubb...@apache.org>
AuthorDate: Tue Apr 12 00:23:03 2022 -0400

    Use CLASSPATH env instead of `-cp` (#2617)
    
    * Replace use of `-cp` for specifying the class path with use of the
      CLASSPATH environment variable
    * Removing redundant display of extraJvmOpts and classpath from the
      debug log message when MiniAccumuloCluster starts (they're already
      available in the args and the environment)
    * Use Streams to avoid intermediate list objects and to make the
      process' argList construction more intuitive
---
 .../miniclusterImpl/MiniAccumuloClusterImpl.java   | 37 ++++++++++------------
 start/src/test/shell/makeTestJars.sh               |  3 +-
 .../test/functional/HalfDeadTServerIT.java         |  8 ++---
 3 files changed, 20 insertions(+), 28 deletions(-)

diff --git 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
index b6e6b1f644..82df42a47a 100644
--- 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
+++ 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
@@ -21,6 +21,7 @@ package org.apache.accumulo.miniclusterImpl;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Objects.requireNonNull;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static java.util.stream.Collectors.toList;
 import static 
org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
 
 import java.io.File;
@@ -34,7 +35,6 @@ import java.net.Socket;
 import java.net.URI;
 import java.nio.file.Files;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -51,6 +51,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.function.Function;
 import java.util.stream.Stream;
 
 import org.apache.accumulo.cluster.AccumuloCluster;
@@ -210,28 +211,28 @@ public class MiniAccumuloClusterImpl implements 
AccumuloCluster {
       throws IOException {
     String javaHome = System.getProperty("java.home");
     String javaBin = javaHome + File.separator + "bin" + File.separator + 
"java";
-    String classpath = getClasspath();
 
-    String className = clazz.getName();
+    var basicArgs = Stream.of(javaBin, "-Dproc=" + clazz.getSimpleName());
+    var jvmArgs = extraJvmOpts.stream();
+    var propsArgs = config.getSystemProperties().entrySet().stream()
+        .map(e -> String.format("-D%s=%s", e.getKey(), e.getValue()));
 
-    ArrayList<String> argList = new ArrayList<>();
-    argList.addAll(Arrays.asList(javaBin, "-Dproc=" + clazz.getSimpleName(), 
"-cp", classpath));
-    argList.addAll(extraJvmOpts);
-    for (Entry<String,String> sysProp : 
config.getSystemProperties().entrySet()) {
-      argList.add(String.format("-D%s=%s", sysProp.getKey(), 
sysProp.getValue()));
-    }
     // @formatter:off
-    argList.addAll(Arrays.asList(
+    var hardcodedArgs = Stream.of(
         "-Dapple.awt.UIElement=true",
         "-Djava.net.preferIPv4Stack=true",
         "-XX:+PerfDisableSharedMem",
         "-XX:+AlwaysPreTouch",
-        Main.class.getName(), className));
+        Main.class.getName(), clazz.getName());
     // @formatter:on
-    argList.addAll(Arrays.asList(args));
 
+    // concatenate all the args sources into a single list of args
+    var argList = Stream.of(basicArgs, jvmArgs, propsArgs, hardcodedArgs, 
Stream.of(args))
+        .flatMap(Function.identity()).collect(toList());
     ProcessBuilder builder = new ProcessBuilder(argList);
 
+    final String classpath = getClasspath();
+    builder.environment().put("CLASSPATH", classpath);
     builder.environment().put("ACCUMULO_HOME", 
config.getDir().getAbsolutePath());
     builder.environment().put("ACCUMULO_LOG_DIR", 
config.getLogDir().getAbsolutePath());
     builder.environment().put("ACCUMULO_CLIENT_CONF_PATH",
@@ -255,8 +256,7 @@ public class MiniAccumuloClusterImpl implements 
AccumuloCluster {
     }
 
     log.debug("Starting MiniAccumuloCluster process with class: " + 
clazz.getSimpleName()
-        + "\n, jvmOpts: " + extraJvmOpts + "\n, classpath: " + classpath + 
"\n, args: " + argList
-        + "\n, environment: " + builder.environment());
+        + "\n, args: " + argList + "\n, environment: " + 
builder.environment());
 
     int hashcode = builder.hashCode();
 
@@ -294,8 +294,7 @@ public class MiniAccumuloClusterImpl implements 
AccumuloCluster {
     if (configOverrides != null && !configOverrides.isEmpty()) {
       File siteFile =
           Files.createTempFile(config.getConfDir().toPath(), "accumulo", 
".properties").toFile();
-      Map<String,String> confMap = new HashMap<>();
-      confMap.putAll(config.getSiteConfig());
+      Map<String,String> confMap = new HashMap<>(config.getSiteConfig());
       confMap.putAll(configOverrides);
       writeConfigProperties(siteFile, confMap);
       jvmOpts.add("-Daccumulo.properties=" + siteFile.getName());
@@ -730,11 +729,7 @@ public class MiniAccumuloClusterImpl implements 
AccumuloCluster {
   }
 
   List<ProcessReference> references(Process... procs) {
-    List<ProcessReference> result = new ArrayList<>();
-    for (Process proc : procs) {
-      result.add(new ProcessReference(proc));
-    }
-    return result;
+    return Stream.of(procs).map(ProcessReference::new).collect(toList());
   }
 
   public Map<ServerType,Collection<ProcessReference>> getProcesses() {
diff --git a/start/src/test/shell/makeTestJars.sh 
b/start/src/test/shell/makeTestJars.sh
index 5d26bb1b68..f6781e3b96 100755
--- a/start/src/test/shell/makeTestJars.sh
+++ b/start/src/test/shell/makeTestJars.sh
@@ -27,7 +27,8 @@ for x in A B C
 do
     mkdir -p target/generated-sources/$x/test 
target/test-classes/ClassLoaderTest$x
     sed "s/testX/test$x/" < src/test/java/test/TestTemplate > 
target/generated-sources/$x/test/TestObject.java
-    $JAVA_HOME/bin/javac -cp target/test-classes 
target/generated-sources/$x/test/TestObject.java -d target/generated-sources/$x
+    export CLASSPATH=target/test-classes
+    $JAVA_HOME/bin/javac target/generated-sources/$x/test/TestObject.java -d 
target/generated-sources/$x
     $JAVA_HOME/bin/jar -cf target/test-classes/ClassLoaderTest$x/Test.jar -C 
target/generated-sources/$x test/TestObject.class
     rm -r target/generated-sources/$x
 done
diff --git 
a/test/src/main/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java 
b/test/src/main/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java
index 74f59c9f8d..43a8f3532a 100644
--- 
a/test/src/main/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java
+++ 
b/test/src/main/java/org/apache/accumulo/test/functional/HalfDeadTServerIT.java
@@ -29,8 +29,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.time.Duration;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Map;
 import java.util.Scanner;
 import java.util.concurrent.TimeUnit;
@@ -170,11 +168,9 @@ public class HalfDeadTServerIT extends ConfigurableMacBase 
{
       String classpath = System.getProperty("java.class.path");
       classpath = new File(cluster.getConfig().getDir(), "conf") + 
File.pathSeparator + classpath;
       String className = TabletServer.class.getName();
-      ArrayList<String> argList = new ArrayList<>();
-      argList.addAll(Arrays.asList(javaBin, "-cp", classpath));
-      argList.addAll(Arrays.asList(Main.class.getName(), className));
-      ProcessBuilder builder = new ProcessBuilder(argList);
+      ProcessBuilder builder = new ProcessBuilder(javaBin, 
Main.class.getName(), className);
       Map<String,String> env = builder.environment();
+      env.put("CLASSPATH", classpath);
       env.put("ACCUMULO_HOME", cluster.getConfig().getDir().getAbsolutePath());
       env.put("ACCUMULO_LOG_DIR", 
cluster.getConfig().getLogDir().getAbsolutePath());
       String trickFilename = cluster.getConfig().getLogDir().getAbsolutePath() 
+ "/TRICK_FILE";

Reply via email to