aboutsummaryrefslogtreecommitdiffstats
path: root/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java')
-rw-r--r--docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java24
1 files changed, 20 insertions, 4 deletions
diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java
index 69055e6402c..b6e9c4976bf 100644
--- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java
+++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerEngineTest.java
@@ -14,15 +14,20 @@ import com.github.dockerjava.api.command.PullImageCmd;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.core.command.ExecStartResultCallback;
import com.yahoo.config.provision.DockerImage;
+import com.yahoo.test.ManualClock;
+import com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics;
import com.yahoo.vespa.hosted.dockerapi.metrics.Metrics;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
+import java.time.Duration;
+import java.util.Optional;
import java.util.OptionalLong;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -36,7 +41,8 @@ public class DockerEngineTest {
private final DockerClient dockerClient = mock(DockerClient.class);
private final Metrics metrics = new Metrics();
- private final DockerEngine docker = new DockerEngine(dockerClient, metrics);
+ private final ManualClock clock = new ManualClock();
+ private final DockerEngine docker = new DockerEngine(dockerClient, metrics, clock);
@Test
public void testExecuteCompletes() {
@@ -85,7 +91,6 @@ public class DockerEngineTest {
.thenThrow(new NotFoundException("Image not found"))
.thenReturn(inspectImageResponse);
- // Array to make it final
ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
PullImageCmd pullImageCmd = mock(PullImageCmd.class);
when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);
@@ -97,7 +102,9 @@ public class DockerEngineTest {
assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
assertTrue(docker.imageIsDownloaded(image));
+ clock.advance(Duration.ofMinutes(10));
resultCallback.getValue().onComplete();
+ assertPullDuration(Duration.ofMinutes(10), "1.2.3");
assertFalse(docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
}
@@ -109,7 +116,6 @@ public class DockerEngineTest {
InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class);
when(imageInspectCmd.exec()).thenThrow(new NotFoundException("Image not found"));
- // Array to make it final
ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
PullImageCmd pullImageCmd = mock(PullImageCmd.class);
when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);
@@ -118,7 +124,7 @@ public class DockerEngineTest {
when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);
assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
- assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
+ assertTrue("Should return true, the pull is still ongoing", docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
try {
resultCallback.getValue().onComplete();
@@ -128,4 +134,14 @@ public class DockerEngineTest {
assertTrue("Should return true, new pull scheduled", docker.pullImageAsyncIfNeeded(image, RegistryCredentials.none));
}
+ private void assertPullDuration(Duration duration, String tag) {
+ Optional<DimensionMetrics> byTag = metrics.getDefaultMetrics().stream()
+ .filter(metrics -> tag.equals(metrics.getDimensions().asMap().get("tag")))
+ .findFirst();
+ assertTrue("Found metric for tag=" + tag, byTag.isPresent());
+ Number durationInSecs = byTag.get().getMetrics().get("docker.imagePullDurationSecs");
+ assertNotNull(durationInSecs);
+ assertEquals(duration, Duration.ofSeconds(durationInSecs.longValue()));
+ }
+
}