summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-06-28 12:50:10 +0200
committerMartin Polden <mpolden@mpolden.no>2018-06-28 12:54:50 +0200
commitb463175a87bd893865ac8d8e937f0eafd5c6cffc (patch)
tree935aa287e6711b134adf092858211e7599fe06ab /configserver
parent6ddc5165fdb3cc3d8e0f178b1c68ece8489ce832 (diff)
Handle varying SocketTimeoutException message
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java32
1 files changed, 23 insertions, 9 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java
index 2472965ab97..487e96f17b2 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java
@@ -23,9 +23,9 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
-import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;
+import java.util.function.Consumer;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
@@ -33,6 +33,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author Ulf Lilleengen
@@ -182,10 +183,13 @@ public class ConfigConvergenceCheckerTest {
.withFixedDelay((int) Duration.ofSeconds(10).toMillis())
.withBody("response too slow")));
HttpResponse response = checker.checkService(application, hostAndPort(service), requestUrl, Duration.ofMillis(1));
- assertResponse("{\"url\":\"" + requestUrl.toString() + "\",\"host\":\"" + hostAndPort(requestUrl) +
- "\",\"wantedGeneration\":3,\"error\":\"java.net.SocketTimeoutException: Read timed out\"}",
- 404,
- response);
+ // Message contained in a SocketTimeoutException may differ across platforms, so we do a partial match of the response here
+ assertResponse((responseBody) -> {
+ assertTrue("Response matches", responseBody.startsWith(
+ "{\"url\":\"" + requestUrl.toString() + "\",\"host\":\"" + hostAndPort(requestUrl) +
+ "\",\"wantedGeneration\":3,\"error\":\"java.net.SocketTimeoutException") &&
+ responseBody.endsWith("\"}"));
+ }, 404, response);
}
private URI testServer() {
@@ -196,13 +200,23 @@ public class ConfigConvergenceCheckerTest {
return uri.getHost() + ":" + uri.getPort();
}
- private static void assertResponse(String body, int status, HttpResponse response) {
+ private static void assertResponse(String json, int status, HttpResponse response) {
+ assertResponse((responseBody) -> {
+ Slime expected = SlimeUtils.jsonToSlime(json.getBytes());
+ Slime actual = SlimeUtils.jsonToSlime(responseBody.getBytes());
+ try {
+ assertEquals(new String((SlimeUtils.toJsonBytes(expected))), new String(SlimeUtils.toJsonBytes(actual)));
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }, status, response);
+ }
+
+ private static void assertResponse(Consumer<String> assertFunc, int status, HttpResponse response) {
ByteArrayOutputStream responseBody = new ByteArrayOutputStream();
try {
response.render(responseBody);
- Slime expected = SlimeUtils.jsonToSlime(body.getBytes(StandardCharsets.UTF_8));
- Slime actual = SlimeUtils.jsonToSlime(responseBody.toByteArray());
- assertEquals(new String((SlimeUtils.toJsonBytes(expected))), new String(SlimeUtils.toJsonBytes(actual)));
+ assertFunc.accept(responseBody.toString());
} catch (IOException e) {
throw new UncheckedIOException(e);
}