@gatling.io/cli
Version:
Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).
64 lines (63 loc) • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runJavaProcess = void 0;
const child_process_1 = require("child_process");
const os_1 = require("./dependencies/os");
const log_1 = require("./log");
const runJavaProcess = (options, mainClass, additionalClasspathElements, javaArgs, mainClassArgs, proxyConf) => {
const command = `${options.graalvmHome}/bin/java`;
const classpathSeparator = os_1.osType === "Windows_NT" ? ";" : ":";
const classpath = [...additionalClasspathElements, options.jvmClasspath].join(classpathSeparator);
const proxyArgs = generateProxyArgs(proxyConf);
const allArgs = [
"-server",
"-XX:+HeapDumpOnOutOfMemoryError",
"-XX:MaxInlineLevel=20",
"-XX:MaxTrivialSize=12",
"-classpath",
classpath,
...javaArgs,
...proxyArgs,
mainClass,
...mainClassArgs
];
const spawned = (0, child_process_1.spawn)(command, allArgs, {
env: process.env,
stdio: [process.stdin, process.stdout, process.stderr]
});
return new Promise((resolve, reject) => {
spawned.on("error", (error) => log_1.logger.error("Failed to run Gatling process: " + error.toString()));
spawned.on("close", (code) => {
if (code === 0) {
resolve();
}
else {
reject(Error("Gatling process finished with code " + code));
}
});
});
};
exports.runJavaProcess = runJavaProcess;
const generateProxyArgs = (proxyConf) => {
const proxyProps = (protocol, url) => {
const props = [];
if (url !== undefined) {
props.push(`-D${protocol}.proxyHost=${url.hostname}`);
props.push(`-D${protocol}.proxyPort=${url.port || "80"}`);
if (url.username) {
props.push(`-D${protocol}.proxyUser=${url.username}`);
}
if (url.password) {
props.push(`-D${protocol}.proxyPassword=${url.password}`);
}
}
return props;
};
const httpProps = proxyProps("http", proxyConf?.proxyUrl);
// For HTTPS, fallback on proxyUrl if httpsProxyUrl isn't set, following npm's own behavior
const httpsProps = proxyProps("https", proxyConf?.httpsProxyUrl || proxyConf?.proxyUrl);
const noProxyProps = proxyConf !== undefined && proxyConf.noProxyHosts.length > 0
? [`-Dhttp.nonProxyHosts=${proxyConf.noProxyHosts.join("|")}`]
: [];
return [...httpProps, ...httpsProps, ...noProxyProps];
};