Add a test: changing timeout using a pipe
Change-Id: I07e8bce8bd563a6eebc08c6d89e180bfa87d1e84
diff --git a/Changes b/Changes
index a299fe5..b256950 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
# version 0.79
+- Add a test: changing timeout using a pipe
+- Implement timeout rewrite
+
# version 0.78.2
- Update LDAP logs using JLog to include timestamp and move it from system.out
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
index 8ddebae..8f58c16 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
@@ -41,7 +41,7 @@
private int port = 6071;
- private String pipeJson, pipeWithParamJson;
+ private String pipeJson, pipeWithParamJson, pipeTimeout;
private String glemmUri = "http://localhost:" + port + "/glemm";
@@ -50,6 +50,10 @@
ClassLoader.getSystemResourceAsStream(
"pipe-output/test-pipes.jsonld"),
StandardCharsets.UTF_8);
+ pipeTimeout = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/test-timeout.jsonld"),
+ StandardCharsets.UTF_8);
pipeWithParamJson = IOUtils.toString(
ClassLoader.getSystemResourceAsStream(
"pipe-output/with-param.jsonld"),
@@ -57,13 +61,13 @@
}
@BeforeEach
- public void startMockServer () {
+ public void startMockServer() {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer () {
+ public void stopMockServer() {
mockServer.stop();
}
@@ -131,8 +135,8 @@
}
@Test
- public void testSearchWithUrlEncodedPipes ()
- throws IOException, KustvaktException {
+ public void testTimeoutWithPipes ()
+ throws IOException, KustvaktException, URISyntaxException {
mockClient.reset()
.when(request().withMethod("POST").withPath("/glemm")
.withHeaders(
@@ -142,16 +146,38 @@
.respond(response()
.withHeader(new Header("Content-Type",
"application/json; charset=utf-8"))
- .withBody(pipeJson).withStatusCode(200));
- glemmUri = URLEncoder.encode(glemmUri, "utf-8");
+ .withBody(pipeTimeout).withStatusCode(200));
Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("pipes", glemmUri).request().get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(2, node.at("/query/wrap/key").size());
+ assertEquals(10000, node.at("/meta/timeout").asInt());
}
+ @Test
+ public void testSearchWithUrlEncodedPipes ()
+ throws IOException, KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ glemmUri = URLEncoder.encode(glemmUri, "utf-8");
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(2, node.at("/query/wrap/key").size());
+ }
+
@Test
public void testSearchWithMultiplePipes () throws KustvaktException {
mockClient.reset()
diff --git a/src/test/resources/pipe-output/test-timeout.jsonld b/src/test/resources/pipe-output/test-timeout.jsonld
new file mode 100644
index 0000000..93c6309
--- /dev/null
+++ b/src/test/resources/pipe-output/test-timeout.jsonld
@@ -0,0 +1,25 @@
+{
+ "meta": {
+ "snippets": true,
+ "timeout": 90000
+ },
+ "query": {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "match": "match:eq",
+ "key": [
+ "der",
+ "das"
+ ],
+ "layer": "orth",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Glemm",
+ "operation": "operation:override",
+ "scope": "key"
+ }]
+ }
+ },
+ "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld"
+}