DefaultDockerComposeIntegrationTests Class — spring-boot Architecture
Architecture documentation for the DefaultDockerComposeIntegrationTests class in DefaultDockerComposeIntegrationTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java lines 48–122
@DisabledIfDockerUnavailable
@DisabledIfProcessUnavailable({ "docker", "compose" })
class DefaultDockerComposeIntegrationTests {
@Test
void shouldWorkWithProfiles(@TempDir Path tempDir) throws IOException {
// Profile 1 contains redis1 and redis3
// Profile 2 contains redis2 and redis3
File composeFile = createComposeFile(tempDir, "profiles.yaml").toFile();
DefaultDockerCompose dockerComposeWithProfile1 = new DefaultDockerCompose(new DockerCli(tempDir.toFile(),
new DockerComposeOptions(DockerComposeFile.of(composeFile), Set.of("1"), Collections.emptyList())),
null);
DefaultDockerCompose dockerComposeWithProfile2 = new DefaultDockerCompose(new DockerCli(tempDir.toFile(),
new DockerComposeOptions(DockerComposeFile.of(composeFile), Set.of("2"), Collections.emptyList())),
null);
DefaultDockerCompose dockerComposeWithAllProfiles = new DefaultDockerCompose(new DockerCli(tempDir.toFile(),
new DockerComposeOptions(DockerComposeFile.of(composeFile), Set.of("1", "2"), Collections.emptyList())),
null);
dockerComposeWithAllProfiles.up(LogLevel.DEBUG);
try {
List<RunningService> runningServicesProfile1 = dockerComposeWithProfile1.getRunningServices();
assertThatContainsService(runningServicesProfile1, "redis1");
assertThatDoesNotContainService(runningServicesProfile1, "redis2");
assertThatContainsService(runningServicesProfile1, "redis3");
List<RunningService> runningServicesProfile2 = dockerComposeWithProfile2.getRunningServices();
assertThatDoesNotContainService(runningServicesProfile2, "redis1");
assertThatContainsService(runningServicesProfile2, "redis2");
assertThatContainsService(runningServicesProfile2, "redis3");
// Assert that redis3 is started only once and is shared between profile 1 and
// profile 2
assertThat(dockerComposeWithAllProfiles.getRunningServices()).hasSize(3);
RunningService redis3Profile1 = findService(runningServicesProfile1, "redis3");
RunningService redis3Profile2 = findService(runningServicesProfile2, "redis3");
assertThat(redis3Profile1).isNotNull();
assertThat(redis3Profile2).isNotNull();
assertThat(redis3Profile1.name()).isEqualTo(redis3Profile2.name());
}
finally {
dockerComposeWithAllProfiles.down(Duration.ofSeconds(10));
}
}
private @Nullable RunningService findService(List<RunningService> runningServices, String serviceName) {
for (RunningService runningService : runningServices) {
if (runningService.name().contains(serviceName)) {
return runningService;
}
}
return null;
}
private void assertThatDoesNotContainService(List<RunningService> runningServices, String service) {
if (findService(runningServices, service) != null) {
fail("Did not expect service '%s', but found it in [%s]", service, runningServices);
}
}
private void assertThatContainsService(List<RunningService> runningServices, String service) {
if (findService(runningServices, service) == null) {
fail("Expected service '%s', but hasn't been found in [%s]", service, runningServices);
}
}
private static Path createComposeFile(Path tempDir, String resource) throws IOException {
String composeFileTemplate = new ClassPathResource(resource, DockerCliIntegrationTests.class)
.getContentAsString(StandardCharsets.UTF_8);
String content = composeFileTemplate.replace("{imageName}", TestImage.REDIS.toString());
Path composeFile = tempDir.resolve(resource);
Files.writeString(composeFile, content);
return composeFile;
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free