Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast error message on docker creation error #32333

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.4.6
version=0.4.7
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static private class ContainerFactory {
final private String imageName;
final private List<Method> methods;
private PostgreSQLContainer<?> sharedContainer;
private RuntimeException containerCreationError;

private ContainerFactory(String imageNamePlusMethods) {
final String[] parts = imageNamePlusMethods.split("\\+");
Expand All @@ -183,18 +184,27 @@ private ContainerFactory(String imageNamePlusMethods) {

private synchronized PostgreSQLContainer<?> getOrCreateSharedContainer() {
if (sharedContainer == null) {
if (containerCreationError != null) {
throw new RuntimeException("Error during container creation for imageName=" + imageName + ", methods=" + methods, containerCreationError);
}
LOGGER.info("Creating new shared container based on {} with {}.", imageName, methods.stream().map(Method::getName).toList());
final var parsed = DockerImageName.parse(imageName).asCompatibleSubstituteFor("postgres");
sharedContainer = new PostgreSQLContainer<>(parsed);
for (Method method : methods) {
LOGGER.info("Calling {} on new shared container based on {}.", method.getName(), imageName);
try {
try {
final var parsed = DockerImageName.parse(imageName).asCompatibleSubstituteFor("postgres");
PostgreSQLContainer<?> sharedContainer = new PostgreSQLContainer<>(parsed);
for (Method method : methods) {
LOGGER.info("Calling {} on new shared container based on {}.", method.getName(),
imageName);
method.invoke(this);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
sharedContainer.start();
} catch (IllegalAccessException | InvocationTargetException e) {
containerCreationError = new RuntimeException(e);
throw containerCreationError;
} catch (RuntimeException e) {
containerCreationError = e;
throw e;
}
sharedContainer.start();
this.sharedContainer = sharedContainer;
}
return sharedContainer;
}
Expand Down
Loading