Skip to content

Commit

Permalink
include image name in RemoteDockerImage.toString() to fix #2443
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron David committed Mar 17, 2020
1 parent 410e96e commit dc4a5c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Expand Up @@ -28,6 +28,7 @@ public class RemoteDockerImage extends LazyFuture<String> {

private static final Duration PULL_RETRY_TIME_LIMIT = Duration.ofMinutes(2);

@ToString.Exclude
private Future<DockerImageName> imageNameFuture;

@Wither
Expand All @@ -54,9 +55,8 @@ protected DockerImageName resolve() {
}

@Override
@SneakyThrows({InterruptedException.class, ExecutionException.class})
protected final String resolve() {
final DockerImageName imageName = imageNameFuture.get();
final DockerImageName imageName = getImageName();
Logger logger = DockerLoggerFactory.getLogger(imageName.toString());
try {
if (!imagePullPolicy.shouldPull(imageName)) {
Expand Down Expand Up @@ -95,4 +95,10 @@ protected final String resolve() {
throw new ContainerFetchException("Failed to get Docker client for " + imageName, e);
}
}

@ToString.Include(name = "imageName", rank = 1)
@SneakyThrows({InterruptedException.class, ExecutionException.class})
DockerImageName getImageName() {
return imageNameFuture.get();
}
}
Expand Up @@ -2,7 +2,6 @@

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.InspectContainerResponse.ContainerState;
import com.github.dockerjava.api.model.HostConfig;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
Expand Down Expand Up @@ -54,6 +53,19 @@ public void shouldReportErrorAfterWait() {
}
}

@Test
public void shouldLogImageNameWhenGetDockerImageNameFails() {
// A docker image that doesn't exist is enough. The NotFoundException
// that the ContainerFetchException wraps may contain the image name.
// This test verifies that the ContainerFetchException itself does.
String imageName = "doesNotExist";
try(GenericContainer container = new GenericContainer<>(imageName)) {
assertThatThrownBy(container::getDockerImageName)
.isInstanceOf(ContainerFetchException.class)
.hasMessageContaining(imageName);
}
}

static class NoopStartupCheckStrategy extends StartupCheckStrategy {

@Override
Expand Down

0 comments on commit dc4a5c8

Please sign in to comment.