summaryrefslogtreecommitdiffstats
path: root/node-maintainer
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@yahoo-inc.com>2017-08-10 10:58:57 +0200
committerOla Aunrønning <olaa@yahoo-inc.com>2017-08-15 12:29:44 +0200
commit683e12217e87ce45642b245cb09a9f5faa6b4e75 (patch)
treeb64505a2b63ecb1fd6e1ae6e4c399939e553d5d7 /node-maintainer
parent13ab32446140b3f69b6f7a32c70464889959a7e1 (diff)
Made test for ReportSender
Diffstat (limited to 'node-maintainer')
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSender.java2
-rw-r--r--node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSenderTest.java69
-rw-r--r--node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java1
-rw-r--r--node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json4
4 files changed, 73 insertions, 3 deletions
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSender.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSender.java
index 73c8d7b9b80..2dbb1ab7d9f 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSender.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSender.java
@@ -20,7 +20,7 @@ public class ReportSender {
else {
report = "{\"hardwareDivergence\": \"" + om.writeValueAsString(hardwareDivergenceReport) + "\"}";
}
- System.out.println(om.writeValueAsString(report));
+ System.out.print(report);
}
public static void reportBenchmarkResults(BenchmarkReport benchmarkReport, ArrayList<URL> nodeInfoUrls) throws IOException {
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSenderTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSenderTest.java
new file mode 100644
index 00000000000..81c7dcd1291
--- /dev/null
+++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/report/ReportSenderTest.java
@@ -0,0 +1,69 @@
+package com.yahoo.vespa.hosted.node.verification.commons.report;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+
+public class ReportSenderTest {
+
+ private final ByteArrayOutputStream println = new ByteArrayOutputStream();
+ private static final String ABSOLUTE_PATH = Paths.get(".").toAbsolutePath().normalize().toString();
+ private static final String RESOURCE_PATH = "src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json";
+ private static final String URL_RESOURCE_PATH = "file://" + ABSOLUTE_PATH + "/" + RESOURCE_PATH;
+ private static ArrayList<URL> nodeInfoUrls;
+
+ @Before
+ public void setup() throws IOException {
+ System.setOut(new PrintStream(println));
+ URL nodeInfoUrlWithAlreadyExistingHardwareDivergence = new URL(URL_RESOURCE_PATH);
+ nodeInfoUrls = new ArrayList<>(Arrays.asList(nodeInfoUrlWithAlreadyExistingHardwareDivergence));
+ }
+
+ @After
+ public void cleanUpStream() {
+ System.setOut(System.out);
+ }
+
+ @Test
+ public void reportBenchmarkResults_should_update_already_existing_hardwareDivergence_changing_existing_values() throws Exception {
+ BenchmarkReport benchmarkReport = new BenchmarkReport();
+ double cpuCyclesPerSec = 0.3;
+ double memoryReadSpeedGBs = 0.1;
+ benchmarkReport.setCpuCyclesPerSec(cpuCyclesPerSec);
+ benchmarkReport.setMemoryReadSpeedGBs(memoryReadSpeedGBs);
+ String expectedReport = "{\"hardwareDivergence\": \"{\"benchmarkReport\":{\"cpuCyclesPerSec\":0.3,\"memoryReadSpeedGBs\":0.1}}\"}";
+ ReportSender.reportBenchmarkResults(benchmarkReport,nodeInfoUrls);
+ assertEquals(expectedReport, println.toString());
+ }
+
+ @Test
+ public void reportBenchmarkResults_should_should_update_already_existing_hardwareDivergence_prints_null_when_empty_benchmarkReport() throws Exception {
+ BenchmarkReport benchmarkReport = new BenchmarkReport();
+ String expectedReport = "{\"hardwareDivergence\": null}";
+ ReportSender.reportBenchmarkResults(benchmarkReport, nodeInfoUrls);
+ assertEquals(expectedReport, println.toString());
+ }
+
+ @Test
+ public void reportSpecVerificationResults_should_update_already_existing_hardwareDivergence_adding_report_type() throws Exception {
+ SpecVerificationReport specVerificationReport = new SpecVerificationReport();
+ double actualDiskSpaceAvailable = 150D;
+ boolean actualIpv6Connection = false;
+ specVerificationReport.setActualDiskSpaceAvailable(actualDiskSpaceAvailable);
+ specVerificationReport.setActualIpv6Connection(actualIpv6Connection);
+ String expectedReport = "{\"hardwareDivergence\": \"{\"specVerificationReport\":{\"actualDiskSpaceAvailable\":150.0,\"actualIpv6Connection\":false},\"benchmarkReport\":{\"cpuCyclesPerSec\":0.5}}\"}";
+ ReportSender.reportSpecVerificationResults(specVerificationReport, nodeInfoUrls);
+ assertEquals(expectedReport, println.toString());
+ }
+
+} \ No newline at end of file
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java
index c0e5cc62b6e..e215ad7355c 100644
--- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java
+++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java
@@ -7,7 +7,6 @@ import com.yahoo.vespa.hosted.node.verification.commons.noderepo.NodeRepoJsonMod
import com.yahoo.vespa.hosted.node.verification.spec.retrievers.HardwareInfo;
import com.yahoo.vespa.hosted.node.verification.commons.report.SpecVerificationReport;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json
index bd698bca19a..216991846b0 100644
--- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json
+++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/nodeInfoTest.json
@@ -44,5 +44,7 @@
"ipAddresses": [
"10.200.66.16"
],
- "additionalIpAddresses": []
+ "additionalIpAddresses": [],
+
+ "hardwareDivergence": "{\"benchmarkReport\": {\"cpuCyclesPerSec\": 0.5}}"
} \ No newline at end of file