Limit memory usage in tests

Tests can have lots of processes running at once,
if they all default to 75% of physical memory
we can run out, as processes can continue to allocate
instead of running GC
This commit is contained in:
Stuart Douglas
2020-01-29 13:52:13 +11:00
parent 4c5d8fc33a
commit 41a238ba12
3 changed files with 12 additions and 18 deletions

View File

@@ -18,7 +18,6 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.ToolchainManager;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
@@ -49,29 +48,12 @@ public class RemoteDevMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.sourceDirectory}")
private File sourceDir;
@Parameter(defaultValue = "${jvm.args}")
private String jvmArgs;
@Parameter(defaultValue = "${session}")
private MavenSession session;
@Parameter(defaultValue = "TRUE")
private boolean deleteDevJar;
@Component
private MavenVersionEnforcer mavenVersionEnforcer;
@Component
private ToolchainManager toolchainManager;
public ToolchainManager getToolchainManager() {
return toolchainManager;
}
public MavenSession getSession() {
return session;
}
@Override
public void execute() throws MojoFailureException, MojoExecutionException {
mavenVersionEnforcer.ensureMavenVersion(getLog(), session);

View File

@@ -46,6 +46,12 @@ public class RunAndCheckMojoTestBase extends MojoTestBase {
// if no explicit debug options have been specified, let's just disable debugging
args.add("-Ddebug=false");
}
//we need to limit the memory consumption, as we can have a lot of these processes
//running at once, if they add default to 75% of total mem we can easily run out
//of physical memory as they will consume way more than what they need instead of
//just running GC
args.add("-Djvm.args=-Xmx128m");
running.execute(args, Collections.emptyMap());
}

View File

@@ -118,6 +118,12 @@ public class RunningInvoker extends MavenProcessInvoker {
if (System.getProperty("mavenOpts") != null) {
request.setMavenOpts(System.getProperty("mavenOpts"));
} else {
//we need to limit the memory consumption, as we can have a lot of these processes
//running at once, if they add default to 75% of total mem we can easily run out
//of physical memory as they will consume way more than what they need instead of
//just running GC
request.setMavenOpts("-Xmx128m");
}
request.setShellEnvironmentInherited(true);