aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-reindexer/src/test
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-11-20 16:01:38 +0100
committerJon Marius Venstad <venstad@gmail.com>2020-11-20 16:01:38 +0100
commit13688b5f283b095e1680e35c295fec4bb6ad4db0 (patch)
treeff4f71f7f334617182588f9409ab17c21f04fba7 /clustercontroller-reindexer/src/test
parentdb8eaae67a69e77e450eeed34cf6a813ac674d6b (diff)
Add reindexing API to inspect status for each cluster
Diffstat (limited to 'clustercontroller-reindexer/src/test')
-rw-r--r--clustercontroller-reindexer/src/test/java/ai/vespa/reindexing/http/ReindexingV1ApiTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/clustercontroller-reindexer/src/test/java/ai/vespa/reindexing/http/ReindexingV1ApiTest.java b/clustercontroller-reindexer/src/test/java/ai/vespa/reindexing/http/ReindexingV1ApiTest.java
new file mode 100644
index 00000000000..1b6379d21e5
--- /dev/null
+++ b/clustercontroller-reindexer/src/test/java/ai/vespa/reindexing/http/ReindexingV1ApiTest.java
@@ -0,0 +1,80 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.reindexing.http;
+
+import ai.vespa.reindexing.Reindexing;
+import ai.vespa.reindexing.Reindexing.Status;
+import ai.vespa.reindexing.ReindexingCurator;
+import com.yahoo.container.jdisc.RequestHandlerTestDriver;
+import com.yahoo.document.DocumentType;
+import com.yahoo.document.DocumentTypeManager;
+import com.yahoo.document.config.DocumentmanagerConfig;
+import com.yahoo.documentapi.ProgressToken;
+import com.yahoo.jdisc.test.MockMetric;
+import com.yahoo.searchdefinition.derived.Deriver;
+import com.yahoo.vespa.curator.mock.MockCurator;
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.util.concurrent.Executors;
+
+import static com.yahoo.jdisc.http.HttpRequest.Method.POST;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author jonmv
+ */
+class ReindexingV1ApiTest {
+
+ DocumentmanagerConfig musicConfig = Deriver.getDocumentManagerConfig("src/test/resources/schemas/music.sd").build();
+ DocumentTypeManager manager = new DocumentTypeManager(musicConfig);
+ DocumentType musicType = manager.getDocumentType("music");
+ ReindexingCurator database = new ReindexingCurator(new MockCurator(), "cluster", manager);
+ ReindexingV1ApiHandler handler = new ReindexingV1ApiHandler(Executors.newSingleThreadExecutor(), new MockMetric(), database);
+
+ @Test
+ void testResponses() {
+ RequestHandlerTestDriver driver = new RequestHandlerTestDriver(handler);
+
+ // GET at root
+ var response = driver.sendRequest("http://localhost/reindexing/v1/");
+ assertEquals("{\"resources\":[{\"url\":\"/reindexing/v1/status\"}]}", response.readAll());
+ assertEquals("application/json; charset=UTF-8", response.getResponse().headers().getFirst("Content-Type"));
+ assertEquals(200, response.getStatus());
+
+ // GET at status with empty database
+ response = driver.sendRequest("http://localhost/reindexing/v1/status");
+ assertEquals("{\"status\":[]}", response.readAll());
+ assertEquals(200, response.getStatus());
+
+ // GET at status with a failed status
+ database.writeReindexing(Reindexing.empty().with(musicType, Status.ready(Instant.EPOCH)
+ .running()
+ .progressed(new ProgressToken())
+ .failed(Instant.ofEpochMilli(123), "ヽ(。_°)ノ")));
+ response = driver.sendRequest("http://localhost/reindexing/v1/status");
+ assertEquals("{\"status\":[{" +
+ "\"type\":\"music\"," +
+ "\"startedMillis\":0," +
+ "\"endedMillis\":123," +
+ "\"progress\":\"" + new ProgressToken().serializeToString() + "\"," +
+ "\"state\":\"failed\"," +
+ "\"message\":\"ヽ(。_°)ノ\"}" +
+ "]}",
+ response.readAll());
+ assertEquals(200, response.getStatus());
+
+ // POST at root
+ response = driver.sendRequest("http://localhost/reindexing/v1/status", POST);
+ assertEquals("{\"error-code\":\"METHOD_NOT_ALLOWED\",\"message\":\"Only GET is supported under /reindexing/v1/\"}",
+ response.readAll());
+ assertEquals(405, response.getStatus());
+
+ // GET at non-existent path
+ response = driver.sendRequest("http://localhost/reindexing/v1/moo");
+ assertEquals("{\"error-code\":\"NOT_FOUND\",\"message\":\"Nothing at /reindexing/v1/moo\"}",
+ response.readAll());
+ assertEquals(404, response.getStatus());
+
+ }
+
+}