Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit e65f579

Browse files
GEODE-8637: Give each test worker a unique working dir (apache#5649)
* Give each test worker a unique working dir Before running a test task, wrap its TestFramework in a wrapper that creates a unique working dir for each new test worker.
1 parent 5312335 commit e65f579

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for additional information regarding
4+
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
16+
package org.apache.geode.gradle;
17+
18+
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
19+
20+
import java.io.IOException;
21+
import java.io.UncheckedIOException;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.util.concurrent.atomic.AtomicLong;
25+
26+
import org.gradle.api.Action;
27+
import org.gradle.api.internal.tasks.testing.TestFramework;
28+
import org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory;
29+
import org.gradle.api.internal.tasks.testing.detection.TestFrameworkDetector;
30+
import org.gradle.api.tasks.testing.TestFrameworkOptions;
31+
import org.gradle.process.internal.JavaExecHandleBuilder;
32+
import org.gradle.process.internal.worker.WorkerProcessBuilder;
33+
34+
/**
35+
* Wraps a test framework to run each test worker in a separate working directory.
36+
*/
37+
public class RunInSubdirectoryTestFramework implements TestFramework {
38+
private static final String GEMFIRE_PROPERTIES = "gemfire.properties";
39+
private final AtomicLong workerId = new AtomicLong();
40+
private final TestFramework delegate;
41+
42+
public RunInSubdirectoryTestFramework(TestFramework delegate) {
43+
this.delegate = delegate;
44+
}
45+
46+
@Override
47+
public TestFrameworkDetector getDetector() {
48+
return delegate.getDetector();
49+
}
50+
51+
@Override
52+
public TestFrameworkOptions getOptions() {
53+
return delegate.getOptions();
54+
}
55+
56+
@Override
57+
public WorkerTestClassProcessorFactory getProcessorFactory() {
58+
return delegate.getProcessorFactory();
59+
}
60+
61+
/**
62+
* Return an action that configures the test worker builder to run the test worker in a unique
63+
* subdirectory of the task's working directory.
64+
*/
65+
@Override
66+
public Action<WorkerProcessBuilder> getWorkerConfigurationAction() {
67+
return workerProcessBuilder -> {
68+
delegate.getWorkerConfigurationAction().execute(workerProcessBuilder);
69+
JavaExecHandleBuilder javaCommand = workerProcessBuilder.getJavaCommand();
70+
71+
Path taskWorkingDir = javaCommand.getWorkingDir().toPath();
72+
String workerWorkingDirName = String.format("test-worker-%06d", workerId.incrementAndGet());
73+
Path workerWorkingDir = taskWorkingDir.resolve(workerWorkingDirName);
74+
75+
createWorkingDir(workerWorkingDir);
76+
copyGemFirePropertiesFile(taskWorkingDir, workerWorkingDir);
77+
78+
javaCommand.setWorkingDir(workerWorkingDir);
79+
};
80+
}
81+
82+
private void copyGemFirePropertiesFile(Path taskWorkingDir, Path workerWorkingDir) {
83+
Path taskPropertiesFile = taskWorkingDir.resolve(GEMFIRE_PROPERTIES);
84+
if (!Files.exists(taskPropertiesFile)) {
85+
return;
86+
}
87+
Path workerPropertiesFile = workerWorkingDir.resolve(taskPropertiesFile.getFileName());
88+
try {
89+
Files.copy(taskPropertiesFile, workerPropertiesFile, COPY_ATTRIBUTES);
90+
} catch (IOException e) {
91+
throw new UncheckedIOException(e);
92+
}
93+
}
94+
95+
private void createWorkingDir(Path workerWorkingDir) {
96+
try {
97+
Files.createDirectories(workerWorkingDir);
98+
} catch (IOException e) {
99+
throw new UncheckedIOException(e);
100+
}
101+
}
102+
}

extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/AbstractSessionsTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public abstract class AbstractSessionsTest {
5454

5555
// Set up the servers we need
5656
protected static void setupServer(final DeltaSessionManager manager) throws Exception {
57-
FileUtils.copyDirectory(Paths.get("..", "resources", "integrationTest", "tomcat").toFile(),
57+
FileUtils.copyDirectory(
58+
Paths.get("..", "..", "resources", "integrationTest", "tomcat").toFile(),
5859
new File("./tomcat"));
5960
port = SocketUtils.findAvailableTcpPort();
6061
server = new EmbeddedTomcat(port, "JVM-1");

gradle/test.gradle

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.apache.geode.gradle.TestPropertiesWriter
22
import org.apache.geode.gradle.RepeatTest
33
import org.apache.geode.gradle.plugins.DependencyConstraints
4+
import org.apache.geode.gradle.RunInSubdirectoryTestFramework
45

56
/*
67
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -161,6 +162,17 @@ configure([integrationTest, distributedTest, performanceTest, acceptanceTest, ui
161162
}
162163
}
163164

165+
configure([acceptanceTest, distributedTest, integrationTest, uiTest, upgradeTest, repeatAcceptanceTest, repeatDistributedTest, repeatIntegrationTest, repeatUnitTest, repeatUpgradeTest]) {
166+
doFirst {
167+
// Wrap the task's test framework in a wrapper that runs each test worker JVM in a unique
168+
// subdirectory.
169+
def subdirFramework = new RunInSubdirectoryTestFramework(testFramework)
170+
// This call works for now, but the Test class declares useTestFramework() as protected, so
171+
// this could become troublesome in a future version of Gradle/Groovy.
172+
useTestFramework subdirFramework
173+
}
174+
}
175+
164176
configure([repeatDistributedTest, repeatIntegrationTest, repeatUpgradeTest, repeatUnitTest, repeatAcceptanceTest]) {
165177
times = Integer.parseInt(repeat)
166178
useJUnit {}

0 commit comments

Comments
 (0)