Skip to content

Commit

Permalink
Test with two threads at least #128
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 23, 2020
1 parent a11b4c4 commit 9c4bab0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
22 changes: 19 additions & 3 deletions client/src/main/java/org/jboss/fuse/mvnd/client/ClientLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ClientLayout extends Layout {
private final int idleTimeoutMs;
private final int keepAliveMs;
private final int maxLostKeepAlive;
private final int minThreads;

public static ClientLayout getEnvInstance() {
if (ENV_INSTANCE == null) {
Expand Down Expand Up @@ -86,6 +87,11 @@ public static ClientLayout getEnvInstance() {
.orLocalProperty(mvndProperties, mvndPropertiesPath)
.orDefault(() -> Integer.toString(Environment.DEFAULT_MAX_LOST_KEEP_ALIVE))
.asInt();
final int minThreads = Environment.MVND_MIN_THREADS
.systemProperty()
.orLocalProperty(mvndProperties, mvndPropertiesPath)
.orDefault(() -> Integer.toString(Environment.DEFAULT_MIN_THREADS))
.asInt();
ENV_INSTANCE = new ClientLayout(
mvndPropertiesPath,
mvndHome,
Expand All @@ -95,14 +101,14 @@ public static ClientLayout getEnvInstance() {
findLocalRepo(),
null,
Environment.findLogbackConfigurationPath(mvndProperties, mvndPropertiesPath, mvndHome),
idleTimeoutMs, keepAliveMs, maxLostKeepAlive);
idleTimeoutMs, keepAliveMs, maxLostKeepAlive, minThreads);
}
return ENV_INSTANCE;
}

public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path multiModuleProjectDirectory, Path javaHome,
Path localMavenRepository, Path settings, Path logbackConfigurationPath, int idleTimeoutMs, int keepAliveMs,
int maxLostKeepAlive) {
int maxLostKeepAlive, int minThreads) {
super(mvndPropertiesPath, mavenHome, userDir, multiModuleProjectDirectory);
this.localMavenRepository = localMavenRepository;
this.settings = settings;
Expand All @@ -111,6 +117,7 @@ public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path
this.idleTimeoutMs = idleTimeoutMs;
this.keepAliveMs = keepAliveMs;
this.maxLostKeepAlive = maxLostKeepAlive;
this.minThreads = minThreads;
}

/**
Expand All @@ -119,7 +126,8 @@ public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path
*/
public ClientLayout cd(Path newUserDir) {
return new ClientLayout(mvndPropertiesPath, mavenHome, newUserDir, multiModuleProjectDirectory, javaHome,
localMavenRepository, settings, logbackConfigurationPath, idleTimeoutMs, keepAliveMs, maxLostKeepAlive);
localMavenRepository, settings, logbackConfigurationPath, idleTimeoutMs, keepAliveMs, maxLostKeepAlive,
minThreads);
}

/**
Expand Down Expand Up @@ -157,6 +165,14 @@ public int getMaxLostKeepAlive() {
return maxLostKeepAlive;
}

/**
* @return the minimum number of threads to use when constructing the default {@code -T} parameter for the daemon.
* This value is ignored if the user passes his own `-T` or `--threads`.
*/
public int getMinThreads() {
return minThreads;
}

static Path findLocalRepo() {
return Environment.MAVEN_REPO_LOCAL.systemProperty().asPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
return new DefaultResult(argv, null);
}

setDefaultArgs(args);
setDefaultArgs(args, layout);
final Path settings = layout.getSettings();
if (settings != null && args.stream().noneMatch(arg -> arg.equals("-s") || arg.equals("--settings"))) {
args.add("-s");
Expand Down Expand Up @@ -237,10 +237,10 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {

}

static void setDefaultArgs(List<String> args) {
static void setDefaultArgs(List<String> args, ClientLayout layout) {
if (args.stream().noneMatch(arg -> arg.startsWith("-T") || arg.equals("--threads"))) {
final int procs = Math.max(Runtime.getRuntime().availableProcessors() - 1, 1);
args.add("-T" + procs);
final int threads = Math.max(Runtime.getRuntime().availableProcessors() - 1, layout.getMinThreads());
args.add("-T" + threads);
}
if (args.stream().noneMatch(arg -> arg.startsWith("-b") || arg.equals("--builder"))) {
args.add("-bsmart");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum Environment {
DAEMON_IDLE_TIMEOUT_MS("daemon.idleTimeoutMs", null),
DAEMON_KEEP_ALIVE_MS("daemon.keepAliveMs", null),
DAEMON_MAX_LOST_KEEP_ALIVE("daemon.maxLostKeepAlive", null),
MVND_MIN_THREADS("mvnd.minThreads", null),
DAEMON_UID("daemon.uid", null);

public static final int DEFAULT_IDLE_TIMEOUT = (int) TimeUnit.HOURS.toMillis(3);
Expand All @@ -51,6 +52,8 @@ public enum Environment {

public static final int DEFAULT_MAX_LOST_KEEP_ALIVE = 3;

public static final int DEFAULT_MIN_THREADS = 1;

private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
static Properties properties = System.getProperties();
static Map<String, String> env = System.getenv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public ExecutionResult execute(ClientOutput output, List<String> args) throws In
cmd.add("-s");
cmd.add(settings.toString());
}
if (args.stream().noneMatch(arg -> arg.startsWith("-T") || arg.equals("--threads"))) {
final int threads = Math.max(Runtime.getRuntime().availableProcessors() - 1, TestLayout.TEST_MIN_THREADS);
cmd.add("-T" + threads);
}

final ProcessBuilder builder = new ProcessBuilder(cmd.toArray(new String[0]))
.directory(layout.userDir().toFile()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import org.jboss.fuse.mvnd.client.ClientLayout;

public class TestLayout extends ClientLayout {
static final int TEST_MIN_THREADS = 2;
private final Path testDir;

public TestLayout(Path testDir, Path mvndPropertiesPath, Path mavenHome, Path userDir, Path multiModuleProjectDirectory,
Path javaHome, Path localMavenRepository, Path settings, Path logbackConfigurationPath,
int idleTimeout, int keepAlive, int maxLostKeepAlive) {
super(mvndPropertiesPath, mavenHome, userDir, multiModuleProjectDirectory, javaHome, localMavenRepository,
settings, logbackConfigurationPath, idleTimeout, keepAlive, maxLostKeepAlive);
settings, logbackConfigurationPath, idleTimeout, keepAlive, maxLostKeepAlive, TEST_MIN_THREADS);
this.testDir = testDir;
}

Expand Down

0 comments on commit 9c4bab0

Please sign in to comment.