Skip to content

Commit 98bfeab

Browse files
authored
Remove cross project support in TestFixturesPlugin (#109077) (#109081)
- One step closer to configuration cache support - Crossproject support has been replaced by using testcontainer based fixtures
1 parent 978557a commit 98bfeab

File tree

5 files changed

+75
-211
lines changed

5 files changed

+75
-211
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/testfixtures/TestFixtureExtension.java

Lines changed: 0 additions & 112 deletions
This file was deleted.

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/testfixtures/TestFixturesPlugin.java

Lines changed: 75 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public void apply(Project project) {
7070
project.getRootProject().getPluginManager().apply(DockerSupportPlugin.class);
7171

7272
TaskContainer tasks = project.getTasks();
73-
TestFixtureExtension extension = project.getExtensions().create("testFixtures", TestFixtureExtension.class, project);
7473
Provider<DockerComposeThrottle> dockerComposeThrottle = project.getGradle()
7574
.getSharedServices()
7675
.registerIfAbsent(DOCKER_COMPOSE_THROTTLE, DockerComposeThrottle.class, spec -> spec.getMaxParallelUsages().set(1));
@@ -84,73 +83,63 @@ public void apply(Project project) {
8483
File testFixturesDir = project.file("testfixtures_shared");
8584
ext.set("testFixturesDir", testFixturesDir);
8685

87-
if (project.file(DOCKER_COMPOSE_YML).exists()) {
88-
project.getPluginManager().apply(BasePlugin.class);
89-
project.getPluginManager().apply(DockerComposePlugin.class);
90-
TaskProvider<TestFixtureTask> preProcessFixture = project.getTasks().register("preProcessFixture", TestFixtureTask.class, t -> {
91-
t.getFixturesDir().set(testFixturesDir);
92-
t.doFirst(task -> {
93-
try {
94-
Files.createDirectories(testFixturesDir.toPath());
95-
} catch (IOException e) {
96-
throw new UncheckedIOException(e);
97-
}
98-
});
99-
});
100-
TaskProvider<Task> buildFixture = project.getTasks()
101-
.register("buildFixture", t -> t.dependsOn(preProcessFixture, tasks.named("composeUp")));
102-
103-
TaskProvider<TestFixtureTask> postProcessFixture = project.getTasks()
104-
.register("postProcessFixture", TestFixtureTask.class, task -> {
105-
task.getFixturesDir().set(testFixturesDir);
106-
task.dependsOn(buildFixture);
107-
configureServiceInfoForTask(
108-
task,
109-
project,
110-
false,
111-
(name, port) -> task.getExtensions().getByType(ExtraPropertiesExtension.class).set(name, port)
112-
);
113-
});
114-
115-
maybeSkipTask(dockerSupport, preProcessFixture);
116-
maybeSkipTask(dockerSupport, postProcessFixture);
117-
maybeSkipTask(dockerSupport, buildFixture);
118-
119-
ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
120-
composeExtension.setProjectName(project.getName());
121-
composeExtension.getUseComposeFiles().addAll(Collections.singletonList(DOCKER_COMPOSE_YML));
122-
composeExtension.getRemoveContainers().set(true);
123-
composeExtension.getCaptureContainersOutput()
124-
.set(EnumSet.of(LogLevel.INFO, LogLevel.DEBUG).contains(project.getGradle().getStartParameter().getLogLevel()));
125-
composeExtension.getUseDockerComposeV2().set(false);
126-
composeExtension.getExecutable().set(this.providerFactory.provider(() -> {
127-
String composePath = dockerSupport.get().getDockerAvailability().dockerComposePath();
128-
LOGGER.debug("Docker Compose path: {}", composePath);
129-
return composePath != null ? composePath : "/usr/bin/docker-compose";
130-
}));
131-
132-
tasks.named("composeUp").configure(t -> {
133-
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
134-
if (BuildParams.isCi()) {
135-
t.usesService(dockerComposeThrottle);
86+
if (project.file(DOCKER_COMPOSE_YML).exists() == false) {
87+
// if only one fixture is used, that's this one, but without a compose file that's not a valid configuration
88+
throw new IllegalStateException("No " + DOCKER_COMPOSE_YML + " found for " + project.getPath() + ".");
89+
}
90+
project.getPluginManager().apply(BasePlugin.class);
91+
project.getPluginManager().apply(DockerComposePlugin.class);
92+
TaskProvider<TestFixtureTask> preProcessFixture = project.getTasks().register("preProcessFixture", TestFixtureTask.class, t -> {
93+
t.getFixturesDir().set(testFixturesDir);
94+
t.doFirst(task -> {
95+
try {
96+
Files.createDirectories(testFixturesDir.toPath());
97+
} catch (IOException e) {
98+
throw new UncheckedIOException(e);
13699
}
137-
t.mustRunAfter(preProcessFixture);
138100
});
139-
tasks.named("composePull").configure(t -> t.mustRunAfter(preProcessFixture));
140-
tasks.named("composeDown").configure(t -> t.doLast(t2 -> getFileSystemOperations().delete(d -> d.delete(testFixturesDir))));
141-
} else {
142-
project.afterEvaluate(spec -> {
143-
if (extension.fixtures.isEmpty()) {
144-
// if only one fixture is used, that's this one, but without a compose file that's not a valid configuration
145-
throw new IllegalStateException(
146-
"No " + DOCKER_COMPOSE_YML + " found for " + project.getPath() + " nor does it use other fixtures."
147-
);
148-
}
101+
});
102+
TaskProvider<Task> buildFixture = project.getTasks()
103+
.register("buildFixture", t -> t.dependsOn(preProcessFixture, tasks.named("composeUp")));
104+
105+
TaskProvider<TestFixtureTask> postProcessFixture = project.getTasks()
106+
.register("postProcessFixture", TestFixtureTask.class, task -> {
107+
task.getFixturesDir().set(testFixturesDir);
108+
task.dependsOn(buildFixture);
109+
configureServiceInfoForTask(
110+
task,
111+
project,
112+
false,
113+
(name, port) -> task.getExtensions().getByType(ExtraPropertiesExtension.class).set(name, port)
114+
);
149115
});
150-
}
151116

152-
extension.fixtures.matching(fixtureProject -> fixtureProject.equals(project) == false)
153-
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));
117+
maybeSkipTask(dockerSupport, preProcessFixture);
118+
maybeSkipTask(dockerSupport, postProcessFixture);
119+
maybeSkipTask(dockerSupport, buildFixture);
120+
121+
ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
122+
composeExtension.setProjectName(project.getName());
123+
composeExtension.getUseComposeFiles().addAll(Collections.singletonList(DOCKER_COMPOSE_YML));
124+
composeExtension.getRemoveContainers().set(true);
125+
composeExtension.getCaptureContainersOutput()
126+
.set(EnumSet.of(LogLevel.INFO, LogLevel.DEBUG).contains(project.getGradle().getStartParameter().getLogLevel()));
127+
composeExtension.getUseDockerComposeV2().set(false);
128+
composeExtension.getExecutable().set(this.providerFactory.provider(() -> {
129+
String composePath = dockerSupport.get().getDockerAvailability().dockerComposePath();
130+
LOGGER.debug("Docker Compose path: {}", composePath);
131+
return composePath != null ? composePath : "/usr/bin/docker-compose";
132+
}));
133+
134+
tasks.named("composeUp").configure(t -> {
135+
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
136+
if (BuildParams.isCi()) {
137+
t.usesService(dockerComposeThrottle);
138+
}
139+
t.mustRunAfter(preProcessFixture);
140+
});
141+
tasks.named("composePull").configure(t -> t.mustRunAfter(preProcessFixture));
142+
tasks.named("composeDown").configure(t -> t.doLast(t2 -> getFileSystemOperations().delete(d -> d.delete(testFixturesDir))));
154143

155144
// Skip docker compose tasks if it is unavailable
156145
maybeSkipTasks(tasks, dockerSupport, Test.class);
@@ -161,17 +150,18 @@ public void apply(Project project) {
161150
maybeSkipTasks(tasks, dockerSupport, ComposePull.class);
162151
maybeSkipTasks(tasks, dockerSupport, ComposeDown.class);
163152

164-
tasks.withType(Test.class).configureEach(task -> extension.fixtures.all(fixtureProject -> {
165-
task.dependsOn(fixtureProject.getTasks().named("postProcessFixture"));
166-
task.finalizedBy(fixtureProject.getTasks().named("composeDown"));
153+
tasks.withType(Test.class).configureEach(testTask -> {
154+
testTask.dependsOn(postProcessFixture);
155+
testTask.finalizedBy(tasks.named("composeDown"));
167156
configureServiceInfoForTask(
168-
task,
169-
fixtureProject,
157+
testTask,
158+
project,
170159
true,
171-
(name, host) -> task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
160+
(name, host) -> testTask.getExtensions()
161+
.getByType(SystemPropertyCommandLineArgumentProvider.class)
162+
.systemProperty(name, host)
172163
);
173-
}));
174-
164+
});
175165
}
176166

177167
private void maybeSkipTasks(TaskContainer tasks, Provider<DockerSupportService> dockerSupport, Class<? extends DefaultTask> taskClass) {
@@ -203,28 +193,20 @@ private void configureServiceInfoForTask(
203193
task.doFirst(new Action<Task>() {
204194
@Override
205195
public void execute(Task theTask) {
206-
TestFixtureExtension extension = theTask.getProject().getExtensions().getByType(TestFixtureExtension.class);
207-
208-
fixtureProject.getExtensions()
209-
.getByType(ComposeExtension.class)
210-
.getServicesInfos()
211-
.entrySet()
212-
.stream()
213-
.filter(entry -> enableFilter == false || extension.isServiceRequired(entry.getKey(), fixtureProject.getPath()))
214-
.forEach(entry -> {
215-
String service = entry.getKey();
216-
ServiceInfo infos = entry.getValue();
217-
infos.getTcpPorts().forEach((container, host) -> {
218-
String name = "test.fixtures." + service + ".tcp." + container;
219-
theTask.getLogger().info("port mapping property: {}={}", name, host);
220-
consumer.accept(name, host);
221-
});
222-
infos.getUdpPorts().forEach((container, host) -> {
223-
String name = "test.fixtures." + service + ".udp." + container;
224-
theTask.getLogger().info("port mapping property: {}={}", name, host);
225-
consumer.accept(name, host);
226-
});
196+
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos().entrySet().stream().forEach(entry -> {
197+
String service = entry.getKey();
198+
ServiceInfo infos = entry.getValue();
199+
infos.getTcpPorts().forEach((container, host) -> {
200+
String name = "test.fixtures." + service + ".tcp." + container;
201+
theTask.getLogger().info("port mapping property: {}={}", name, host);
202+
consumer.accept(name, host);
227203
});
204+
infos.getUdpPorts().forEach((container, host) -> {
205+
String name = "test.fixtures." + service + ".udp." + container;
206+
theTask.getLogger().info("port mapping property: {}={}", name, host);
207+
consumer.accept(name, host);
208+
});
209+
});
228210
}
229211
});
230212
}

distribution/docker/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ if (useDra == false) {
7272
}
7373
}
7474

75-
testFixtures.useFixture()
76-
7775
configurations {
7876
aarch64DockerSource {
7977
attributes {

qa/apm/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ apply plugin: 'elasticsearch.standalone-rest-test'
1616
apply plugin: 'elasticsearch.test.fixtures'
1717
apply plugin: 'elasticsearch.internal-distribution-download'
1818

19-
testFixtures.useFixture()
20-
2119
dockerCompose {
2220
environment.put 'STACK_VERSION', BuildParams.snapshotBuild ? VersionProperties.elasticsearch : VersionProperties.elasticsearch + "-SNAPSHOT"
2321
}

qa/remote-clusters/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ apply plugin: 'elasticsearch.standalone-rest-test'
1515
apply plugin: 'elasticsearch.test.fixtures'
1616
apply plugin: 'elasticsearch.internal-distribution-download'
1717

18-
testFixtures.useFixture()
19-
2018
tasks.register("copyNodeKeyMaterial", Sync) {
2119
from project(':x-pack:plugin:core')
2220
.files(

0 commit comments

Comments
 (0)