Skip to content

Commit

Permalink
Use shorter paths for test cluster working directories to avoid issue…
Browse files Browse the repository at this point in the history
…s on Windows (#93570)
  • Loading branch information
mark-vieira committed Feb 8, 2023
1 parent 11d0d7a commit 603bae6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,21 @@ public class LocalClusterFactory implements ClusterFactory<LocalClusterSpec, Loc
private static final String ENABLE_DEBUG_JVM_ARGS = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=";
private static final int DEFAULT_DEBUG_PORT = 5007;

private final Path baseWorkingDir;
private final DistributionResolver distributionResolver;
private Path baseWorkingDir;

public LocalClusterFactory(Path baseWorkingDir, DistributionResolver distributionResolver) {
this.baseWorkingDir = baseWorkingDir;
public LocalClusterFactory(DistributionResolver distributionResolver) {
this.distributionResolver = distributionResolver;
}

@Override
public LocalClusterHandle create(LocalClusterSpec spec) {
try {
this.baseWorkingDir = Files.createTempDirectory(spec.getName());
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return new LocalClusterHandle(spec.getName(), spec.getNodes().stream().map(Node::new).toList());
}

Expand All @@ -95,7 +100,7 @@ public class Node {

public Node(LocalNodeSpec spec) {
this.spec = spec;
this.workingDir = baseWorkingDir.resolve(spec.getCluster().getName()).resolve(spec.getName());
this.workingDir = baseWorkingDir.resolve(spec.getName());
this.repoDir = baseWorkingDir.resolve("repo");
this.dataDir = workingDir.resolve("data");
this.logsDir = workingDir.resolve("logs");
Expand Down Expand Up @@ -127,6 +132,7 @@ public synchronized void start(Version version) {
copyExtraConfigFiles();
}

deleteGcLogs();
writeConfiguration();
createKeystore();
addKeystoreSettings();
Expand Down Expand Up @@ -209,6 +215,20 @@ public void waitUntilReady() {
}
}

private void deleteGcLogs() {
try (Stream<Path> logs = Files.list(logsDir)) {
logs.filter(l -> l.getFileName().toString().startsWith("gc.log")).forEach(path -> {
try {
IOUtils.deleteWithRetry(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void createConfigDirectory() {
try {
IOUtils.deleteWithRetry(configDir);
Expand Down Expand Up @@ -271,7 +291,8 @@ private void initializeWorkingDirectory(boolean preserveWorkingDirectory) {
private boolean canUseSharedDistribution() {
return OS.current() != WINDOWS // Issues with long file paths on Windows in CI
&& System.getProperty(TESTS_CLUSTER_FIPS_JAR_PATH_SYSPROP) == null
&& (distributionDescriptor.getType() == DEFAULT || (getSpec().getPlugins().isEmpty() && getSpec().getModules().isEmpty()));
&& getSpec().getPlugins().isEmpty()
&& (distributionDescriptor.getType() == DEFAULT || getSpec().getModules().isEmpty());
}

private void copyExtraJarFiles() {
Expand Down Expand Up @@ -607,7 +628,7 @@ private Map<String, String> getJvmOptionsReplacements() {

private void runToolScript(String tool, String input, String... args) {
try {
ProcessUtils.exec(
int exit = ProcessUtils.exec(
input,
distributionDir,
distributionDir.resolve("bin")
Expand All @@ -616,13 +637,17 @@ private void runToolScript(String tool, String input, String... args) {
false,
args
).waitFor();

if (exit != 0) {
throw new RuntimeException("Execution of " + tool + " failed with exit code " + exit);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private String getServiceName() {
return baseWorkingDir.getFileName() + "-" + spec.getCluster().getName() + "-" + spec.getName();
return baseWorkingDir.getFileName() + "-" + spec.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.nio.file.Path;

public class LocalElasticsearchCluster implements ElasticsearchCluster {
private final DefaultLocalClusterSpecBuilder builder;
private LocalClusterSpec spec;
Expand All @@ -35,7 +33,6 @@ public void evaluate() throws Throwable {
try {
spec = builder.buildClusterSpec();
handle = new LocalClusterFactory(
Path.of(System.getProperty("java.io.tmpdir")).resolve(description.getDisplayName()).toAbsolutePath(),
new LocalDistributionResolver(new SnapshotDistributionResolver(new ReleasedDistributionResolver()))
).create(spec);
handle.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public static Process exec(
processBuilder.environment().clear();
processBuilder.environment().putAll(environment);

LOGGER.info("Executing '{}' in '{}'", command, workingDir);

try {
process = processBuilder.start();

Expand Down

0 comments on commit 603bae6

Please sign in to comment.