Skip to content

Commit e01136f

Browse files
committed
fix tests
1 parent 1136cad commit e01136f

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/JvmOptionsParserTests.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@
4545
@WithoutSecurityManager
4646
public class JvmOptionsParserTests extends ESTestCase {
4747

48-
private static final Map<String, String> TEST_SYSPROPS = Map.of("os.name", "Linux", "os.arch", "aarch64");
49-
50-
private static final Path ENTITLEMENTS_LIB_DIR = Path.of("lib", "entitlement-bridge");
48+
private static Map<String, String> testSysprops;
5149

5250
@BeforeClass
5351
public static void beforeClass() throws IOException {
54-
Files.createDirectories(ENTITLEMENTS_LIB_DIR);
55-
Files.createTempFile(ENTITLEMENTS_LIB_DIR, "mock-entitlements-bridge", ".jar");
52+
Path homeDir = createTempDir();
53+
Path entitlementLibDir = homeDir.resolve("lib/entitlement-bridge");
54+
Files.createDirectories(entitlementLibDir);
55+
Files.createTempFile(entitlementLibDir, "mock-entitlements-bridge", ".jar");
56+
testSysprops = Map.of("os.name", "Linux", "os.arch", "aarch64", "es.path.home", homeDir.toString());
5657
}
5758

5859
@AfterClass
@@ -369,30 +370,30 @@ public void accept(final int lineNumber, final String line) {
369370

370371
public void testNodeProcessorsActiveCount() {
371372
{
372-
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(Settings.EMPTY, TEST_SYSPROPS);
373+
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(Settings.EMPTY, testSysprops);
373374
assertThat(jvmOptions, not(hasItem(containsString("-XX:ActiveProcessorCount="))));
374375
}
375376
{
376377
Settings nodeSettings = Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 1).build();
377-
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(nodeSettings, TEST_SYSPROPS);
378+
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(nodeSettings, testSysprops);
378379
assertThat(jvmOptions, hasItem("-XX:ActiveProcessorCount=1"));
379380
}
380381
{
381382
// check rounding
382383
Settings nodeSettings = Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 0.2).build();
383-
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(nodeSettings, TEST_SYSPROPS);
384+
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(nodeSettings, testSysprops);
384385
assertThat(jvmOptions, hasItem("-XX:ActiveProcessorCount=1"));
385386
}
386387
{
387388
// check validation
388389
Settings nodeSettings = Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 10000).build();
389-
var e = expectThrows(IllegalArgumentException.class, () -> SystemJvmOptions.systemJvmOptions(nodeSettings, TEST_SYSPROPS));
390+
var e = expectThrows(IllegalArgumentException.class, () -> SystemJvmOptions.systemJvmOptions(nodeSettings, testSysprops));
390391
assertThat(e.getMessage(), containsString("setting [node.processors] must be <="));
391392
}
392393
}
393394

394395
public void testCommandLineDistributionType() {
395-
var sysprops = new HashMap<>(TEST_SYSPROPS);
396+
var sysprops = new HashMap<>(testSysprops);
396397
sysprops.put("es.distribution.type", "testdistro");
397398
final List<String> jvmOptions = SystemJvmOptions.systemJvmOptions(Settings.EMPTY, sysprops);
398399
assertThat(jvmOptions, hasItem("-Des.distribution.type=testdistro"));

distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/ServerProcessTests.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class ServerProcessTests extends ESTestCase {
6666
protected final Map<String, String> sysprops = new HashMap<>();
6767
protected final Map<String, String> envVars = new HashMap<>();
6868
Path esHomeDir;
69+
Path workingDir;
6970
Settings.Builder nodeSettings;
7071
ProcessValidator processValidator;
7172
MainMethod mainCallback;
@@ -88,12 +89,14 @@ int runForeground() throws Exception {
8889

8990
@Before
9091
public void resetEnv() {
92+
esHomeDir = createTempDir();
9193
terminal.reset();
9294
sysprops.clear();
9395
sysprops.put("os.name", "Linux");
9496
sysprops.put("java.home", "javahome");
97+
sysprops.put("es.path.home", esHomeDir.toString());
9598
envVars.clear();
96-
esHomeDir = createTempDir();
99+
workingDir = createTempDir();
97100
nodeSettings = Settings.builder();
98101
processValidator = null;
99102
mainCallback = null;
@@ -229,7 +232,8 @@ ServerProcess startProcess(boolean daemonize, boolean quiet) throws Exception {
229232
.withProcessInfo(pinfo)
230233
.withServerArgs(createServerArgs(daemonize, quiet))
231234
.withJvmOptions(List.of())
232-
.withTempDir(ServerProcessUtils.setupTempDir(pinfo));
235+
.withTempDir(ServerProcessUtils.setupTempDir(pinfo))
236+
.withWorkingDir(workingDir);
233237
return serverProcessBuilder.start(starter);
234238
}
235239

@@ -238,7 +242,7 @@ public void testProcessBuilder() throws Exception {
238242
assertThat(pb.redirectInput(), equalTo(ProcessBuilder.Redirect.PIPE));
239243
assertThat(pb.redirectOutput(), equalTo(ProcessBuilder.Redirect.INHERIT));
240244
assertThat(pb.redirectError(), equalTo(ProcessBuilder.Redirect.PIPE));
241-
assertThat(pb.directory(), nullValue()); // leave default, which is working directory
245+
assertThat(pb.directory().toString(), equalTo(workingDir.toString())); // leave default, which is working directory
242246
};
243247
mainCallback = (args, stdin, stderr, exitCode) -> {
244248
try (PrintStream err = new PrintStream(stderr, true, StandardCharsets.UTF_8)) {
@@ -312,7 +316,8 @@ public void testCommandLineSysprops() throws Exception {
312316
.withProcessInfo(createProcessInfo())
313317
.withServerArgs(createServerArgs(false, false))
314318
.withJvmOptions(List.of("-Dfoo1=bar", "-Dfoo2=baz"))
315-
.withTempDir(Path.of("."));
319+
.withTempDir(Path.of("."))
320+
.withWorkingDir(workingDir);
316321
serverProcessBuilder.start(starter).waitFor();
317322
}
318323

0 commit comments

Comments
 (0)