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 91d158ffb63..36939b5ac71 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -348,21 +348,14 @@ private ProcessInfo _exec(Class clazz, List extraJvmOpts, String... a String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; var basicArgs = Stream.of(javaBin, "-Dproc=" + clazz.getSimpleName()); - var jvmArgs = extraJvmOpts.stream(); - var propsArgs = config.getSystemProperties().entrySet().stream() + var jvmOptions = Stream.concat(config.getJvmOptions().stream(), extraJvmOpts.stream()); + var systemProps = config.getSystemProperties().entrySet().stream() .map(e -> String.format("-D%s=%s", e.getKey(), e.getValue())); - // @formatter:off - var hardcodedArgs = Stream.of( - "-Dapple.awt.UIElement=true", - "-Djava.net.preferIPv4Stack=true", - "-XX:+PerfDisableSharedMem", - "-XX:+AlwaysPreTouch", - Main.class.getName(), clazz.getName()); - // @formatter:on + var classArgs = Stream.of(Main.class.getName(), clazz.getName()); // concatenate all the args sources into a single list of args - var argList = Stream.of(basicArgs, jvmArgs, propsArgs, hardcodedArgs, Stream.of(args)) + var argList = Stream.of(basicArgs, jvmOptions, systemProps, classArgs, Stream.of(args)) .flatMap(Function.identity()).collect(toList()); ProcessBuilder builder = new ProcessBuilder(argList); diff --git a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java index 363fe204784..dbbbf5aecd5 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java @@ -30,10 +30,12 @@ import java.io.IOException; import java.util.EnumMap; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import java.util.Set; import java.util.function.Consumer; import org.apache.accumulo.compactor.Compactor; @@ -86,7 +88,8 @@ public class MiniAccumuloConfigImpl { MONITOR, Monitor.class, ZOOKEEPER, ZooKeeperServerMain.class, TABLET_SERVER, TabletServer.class, SCAN_SERVER, ScanServer.class, COMPACTOR, Compactor.class)); private boolean jdwpEnabled = false; - private Map systemProperties = new HashMap<>(); + private final Map systemProperties = new HashMap<>(); + private final Set jvmOptions = new HashSet<>(); private String instanceName = "miniInstance"; private String rootUserName = "root"; @@ -131,6 +134,11 @@ public class MiniAccumuloConfigImpl { public MiniAccumuloConfigImpl(File dir, String rootPassword) { this.dir = dir; this.rootPassword = rootPassword; + // Set default options + this.jvmOptions.add("-XX:+PerfDisableSharedMem"); + this.jvmOptions.add("-XX:+AlwaysPreTouch"); + this.systemProperties.put("-Dapple.awt.UIElement", "true"); + this.systemProperties.put("-Djava.net.preferIPv4Stack", "true"); } /** @@ -669,7 +677,7 @@ public File getClientPropsFile() { * @since 1.6.0 */ public void setSystemProperties(Map systemProperties) { - this.systemProperties = new HashMap<>(systemProperties); + this.systemProperties.putAll(systemProperties); } /** @@ -681,6 +689,39 @@ public Map getSystemProperties() { return new HashMap<>(systemProperties); } + /** + * Add a JVM option to the spawned JVM processes. The default set of JVM options contains + * '-XX:+PerfDisableSharedMem' and '-XX:+AlwaysPreTouch' + * + * @param option JVM option + * @since 2.1.5 + */ + public void addJvmOption(String option) { + this.jvmOptions.add(option); + } + + /** + * Remove an option from the set of JVM options. Only options that match the {@code option} + * exactly will be removed. + * + * @param option JVM option + * @return true if removed, false if not removed + * @since 2.1.5 + */ + public boolean removeJvmOption(String option) { + return this.jvmOptions.remove(option); + } + + /** + * Get the set of JVM options + * + * @return set of options + * @since 2.1.5 + */ + public Set getJvmOptions() { + return new HashSet<>(jvmOptions); + } + /** * Gets the classpath elements to use when spawning processes. *