diff options
Diffstat (limited to 'node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java')
-rw-r--r-- | node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java index 6848fc045e2..13e13f1f83f 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java @@ -1,52 +1,77 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.node.verification.hardware; +import com.yahoo.vespa.hosted.node.verification.Main; import com.yahoo.vespa.hosted.node.verification.mock.MockCommandExecutor; -import org.junit.Before; import org.junit.Test; -import java.net.URL; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; - -import static org.junit.Assert.assertTrue; - -/** - * @author sgrostad - * @author olaaun - */ +import static org.junit.Assert.assertEquals; public class HardwareBenchmarkerTest { - private MockCommandExecutor mockCommandExecutor; private static final String RESOURCE_PATH = "src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/resources/"; private static final String VALID_DISK_BENCHMARK_PATH = RESOURCE_PATH + "diskBenchmarkValidOutput"; + private static final String VALID_SLOW_DISK_BENCHMARK_PATH = RESOURCE_PATH + "diskBenchmarkValidSlowOutput"; private static final String VALID_CPU_BENCHMARK_PATH = RESOURCE_PATH + "cpuCyclesWithCommasTimeWithDotTest.txt"; private static final String VALID_MEMORY_WRITE_BENCHMARK_PATH = RESOURCE_PATH + "validMemoryWriteSpeed"; private static final String VALID_MEMORY_READ_BENCHMARK_PATH = RESOURCE_PATH + "validMemoryReadSpeed"; - private static final String ABSOLUTE_PATH = Paths.get(".").toAbsolutePath().normalize().toString(); - private static final String VALID_NODE_REPO_JSON_WITHOUT_HARDWARE_DIVERGENCE = RESOURCE_PATH + "nodeRepoWithoutHardwareDivergence.json"; - private static final String URL_TO_NODE_REPO_JSON = "file://" + ABSOLUTE_PATH + "/" + VALID_NODE_REPO_JSON_WITHOUT_HARDWARE_DIVERGENCE; + private final MockCommandExecutor commandExecutor = new MockCommandExecutor(); + + @Test + public void benchmark_with_no_failures() throws Exception { + commandExecutor.addCommand("cat " + VALID_DISK_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_CPU_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); + commandExecutor.addCommand("cat " + VALID_MEMORY_WRITE_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_MEMORY_READ_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); - @Before - public void setup() { - mockCommandExecutor = new MockCommandExecutor(); + String result = Main.execute(new String[] { + "benchmark", + }, commandExecutor); + assertEquals("null", result); } @Test - public void hardwareBenchmarks_should_return_true() throws Exception { - mockCommandExecutor.addCommand("cat " + VALID_DISK_BENCHMARK_PATH); - mockCommandExecutor.addCommand("cat " + VALID_CPU_BENCHMARK_PATH); - mockCommandExecutor.addDummyCommand(); - mockCommandExecutor.addDummyCommand(); - mockCommandExecutor.addCommand("cat " + VALID_MEMORY_WRITE_BENCHMARK_PATH); - mockCommandExecutor.addCommand("cat " + VALID_MEMORY_READ_BENCHMARK_PATH); - mockCommandExecutor.addDummyCommand(); - mockCommandExecutor.addDummyCommand(); - assertTrue(HardwareBenchmarker.hardwareBenchmarks(mockCommandExecutor, new ArrayList<URL>(Arrays.asList(new URL(URL_TO_NODE_REPO_JSON))))); + public void disk_benchmark_failure() throws Exception { + commandExecutor.addCommand("cat " + VALID_SLOW_DISK_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_CPU_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); + commandExecutor.addCommand("cat " + VALID_MEMORY_WRITE_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_MEMORY_READ_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); + + String result = Main.execute(new String[]{ + "benchmark", + }, commandExecutor); + + assertEquals("{\"benchmarkReport\":{\"diskSpeedMbs\":49.0}}", result); } + @Test + public void preserve_previous_spec_verifier_result() throws Exception { + commandExecutor.addCommand("cat " + VALID_DISK_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_CPU_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); + commandExecutor.addCommand("cat " + VALID_MEMORY_WRITE_BENCHMARK_PATH); + commandExecutor.addCommand("cat " + VALID_MEMORY_READ_BENCHMARK_PATH); + commandExecutor.addDummyCommand(); + commandExecutor.addDummyCommand(); + + final String previousResult = "{\"specVerificationReport\":{\"actualMemoryAvailable\":4.042128}}"; + + String result = Main.execute(new String[] { + "benchmark", + "-h", previousResult + }, commandExecutor); + + assertEquals(previousResult, result); + } } |