diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-11-23 09:50:10 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-11-23 09:50:10 +0100 |
commit | c404cb9beebdf9cdb6eba563eef220cfe4f318a1 (patch) | |
tree | 333de2813c6377e6bc064d74041c91d25348d216 /clustercontroller-reindexer/src/test | |
parent | ea0c57ca65864ee3261e00c795fcc5cef91c24b2 (diff) |
Revert "Revert "Jonmv/reindexing rest api""
This reverts commit 278967c98483da6b1308d34bd7b2b77e2f690288.
Diffstat (limited to 'clustercontroller-reindexer/src/test')
-rw-r--r-- | clustercontroller-reindexer/src/test/java/ai/vespa/reindexing/http/ReindexingV1ApiTest.java | 80 |
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()); + + } + +} |