aboutsummaryrefslogtreecommitdiffstats
path: root/filedistribution/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2018-01-18 14:10:37 +0100
committerHarald Musum <musum@oath.com>2018-01-18 14:10:37 +0100
commit0cc21a63596b2fcfbf48c39c67c07ab5d4e6dfc5 (patch)
tree6c65ea10cd2e7715a1447fa45a3b5f9520e96895 /filedistribution/src/test
parentf1318f3fba415f31874269966a1b13d04c451449 (diff)
Add client for file distribution API
Diffstat (limited to 'filedistribution/src/test')
-rw-r--r--filedistribution/src/test/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClientTest.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClientTest.java b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClientTest.java
new file mode 100644
index 00000000000..fcbe880bfc7
--- /dev/null
+++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClientTest.java
@@ -0,0 +1,59 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package com.yahoo.vespa.filedistribution.status;
+
+import org.junit.Test;
+
+import static com.yahoo.vespa.filedistribution.status.FileDistributionStatusClient.CommandLineArguments;
+import static org.junit.Assert.assertEquals;
+
+public class FileDistributionStatusClientTest {
+
+ private static final CommandLineArguments arguments = createArguments("--tenant", "foo", "--application", "bar");
+ private final FileDistributionStatusClient client = new FileDistributionStatusClient(arguments);
+
+ @Test
+ public void finishedForAllHosts() {
+ String output = client.parseAndGenerateOutput("{\"status\":\"FINISHED\"}");
+ assertEquals("File distribution finished", output);
+ }
+
+ @Test
+ public void unknownForAllHosts() {
+ String output = client.parseAndGenerateOutput("{\"status\":\"UNKNOWN\", \"message\":\"Something went wrong\"}");
+ assertEquals("File distribution status unknown: Something went wrong", output);
+ }
+
+ @Test
+ public void manyHostsVariousStates() {
+ String statusForTwoHosts = createStatusForTwoHosts();
+ System.out.println(statusForTwoHosts);
+ String output = client.parseAndGenerateOutput(statusForTwoHosts);
+ assertEquals("File distribution in progress:\nlocalhost1: IN_PROGRESS (1 of 2 finished)\nlocalhost2: UNKNOWN (Connection timed out)", output);
+ }
+
+ private static CommandLineArguments createArguments(String... args) {
+ return CommandLineArguments.build(args);
+ }
+
+ private String createStatusForTwoHosts() {
+ return "{\"status\":\"IN_PROGRESS\"," +
+ "\"hosts\":[" + createInProgressStatusForHost("localhost1") + "," + createUnknownStatusForHost("localhost2") + "]" +
+ "}";
+ }
+
+ private String createInProgressStatusForHost(String hostname) {
+ return "{\"hostname\":\"" + hostname + "\"," +
+ "\"status\":\"IN_PROGRESS\"," +
+ "\"message\":\"\"," +
+ "\"fileReferences\":[" +
+ "{\"1234\":0.2}, {\"abcd\":1.0}]}";
+ }
+
+ private String createUnknownStatusForHost(String hostname) {
+ return "{\"hostname\":\"" + hostname + "\"," +
+ "\"status\":\"UNKNOWN\"," +
+ "\"message\":\"Connection timed out\"}";
+ }
+
+}