Skip to content

Commit dd5cbb9

Browse files
authored
Use shorter paths for test cluster working directories to avoid issues on Windows (#93570) (#93603)
1 parent 0d3bc04 commit dd5cbb9

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalClusterFactory.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,21 @@ public class LocalClusterFactory implements ClusterFactory<LocalClusterSpec, Loc
6666
private static final String ENABLE_DEBUG_JVM_ARGS = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=";
6767
private static final int DEFAULT_DEBUG_PORT = 5007;
6868

69-
private final Path baseWorkingDir;
7069
private final DistributionResolver distributionResolver;
70+
private Path baseWorkingDir;
7171

72-
public LocalClusterFactory(Path baseWorkingDir, DistributionResolver distributionResolver) {
73-
this.baseWorkingDir = baseWorkingDir;
72+
public LocalClusterFactory(DistributionResolver distributionResolver) {
7473
this.distributionResolver = distributionResolver;
7574
}
7675

7776
@Override
7877
public LocalClusterHandle create(LocalClusterSpec spec) {
78+
try {
79+
this.baseWorkingDir = Files.createTempDirectory(spec.getName());
80+
} catch (IOException e) {
81+
throw new UncheckedIOException(e);
82+
}
83+
7984
return new LocalClusterHandle(spec.getName(), spec.getNodes().stream().map(Node::new).toList());
8085
}
8186

@@ -95,7 +100,7 @@ public class Node {
95100

96101
public Node(LocalNodeSpec spec) {
97102
this.spec = spec;
98-
this.workingDir = baseWorkingDir.resolve(spec.getCluster().getName()).resolve(spec.getName());
103+
this.workingDir = baseWorkingDir.resolve(spec.getName());
99104
this.repoDir = baseWorkingDir.resolve("repo");
100105
this.dataDir = workingDir.resolve("data");
101106
this.logsDir = workingDir.resolve("logs");
@@ -127,6 +132,7 @@ public synchronized void start(Version version) {
127132
copyExtraConfigFiles();
128133
}
129134

135+
deleteGcLogs();
130136
writeConfiguration();
131137
createKeystore();
132138
addKeystoreSettings();
@@ -209,6 +215,20 @@ public void waitUntilReady() {
209215
}
210216
}
211217

218+
private void deleteGcLogs() {
219+
try (Stream<Path> logs = Files.list(logsDir)) {
220+
logs.filter(l -> l.getFileName().toString().startsWith("gc.log")).forEach(path -> {
221+
try {
222+
IOUtils.deleteWithRetry(path);
223+
} catch (IOException e) {
224+
throw new UncheckedIOException(e);
225+
}
226+
});
227+
} catch (IOException e) {
228+
throw new UncheckedIOException(e);
229+
}
230+
}
231+
212232
private void createConfigDirectory() {
213233
try {
214234
IOUtils.deleteWithRetry(configDir);
@@ -271,7 +291,8 @@ private void initializeWorkingDirectory(boolean preserveWorkingDirectory) {
271291
private boolean canUseSharedDistribution() {
272292
return OS.current() != WINDOWS // Issues with long file paths on Windows in CI
273293
&& System.getProperty(TESTS_CLUSTER_FIPS_JAR_PATH_SYSPROP) == null
274-
&& (distributionDescriptor.getType() == DEFAULT || (getSpec().getPlugins().isEmpty() && getSpec().getModules().isEmpty()));
294+
&& getSpec().getPlugins().isEmpty()
295+
&& (distributionDescriptor.getType() == DEFAULT || getSpec().getModules().isEmpty());
275296
}
276297

277298
private void copyExtraJarFiles() {
@@ -607,7 +628,7 @@ private Map<String, String> getJvmOptionsReplacements() {
607628

608629
private void runToolScript(String tool, String input, String... args) {
609630
try {
610-
ProcessUtils.exec(
631+
int exit = ProcessUtils.exec(
611632
input,
612633
distributionDir,
613634
distributionDir.resolve("bin")
@@ -616,13 +637,17 @@ private void runToolScript(String tool, String input, String... args) {
616637
false,
617638
args
618639
).waitFor();
640+
641+
if (exit != 0) {
642+
throw new RuntimeException("Execution of " + tool + " failed with exit code " + exit);
643+
}
619644
} catch (InterruptedException e) {
620645
throw new RuntimeException(e);
621646
}
622647
}
623648

624649
private String getServiceName() {
625-
return baseWorkingDir.getFileName() + "-" + spec.getCluster().getName() + "-" + spec.getName();
650+
return baseWorkingDir.getFileName() + "-" + spec.getName();
626651
}
627652

628653
@Override

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalElasticsearchCluster.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import org.junit.runner.Description;
1717
import org.junit.runners.model.Statement;
1818

19-
import java.nio.file.Path;
20-
2119
public class LocalElasticsearchCluster implements ElasticsearchCluster {
2220
private final DefaultLocalClusterSpecBuilder builder;
2321
private LocalClusterSpec spec;
@@ -35,7 +33,6 @@ public void evaluate() throws Throwable {
3533
try {
3634
spec = builder.buildClusterSpec();
3735
handle = new LocalClusterFactory(
38-
Path.of(System.getProperty("java.io.tmpdir")).resolve(description.getDisplayName()).toAbsolutePath(),
3936
new LocalDistributionResolver(new SnapshotDistributionResolver(new ReleasedDistributionResolver()))
4037
).create(spec);
4138
handle.start();

0 commit comments

Comments
 (0)