diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-17 22:03:07 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-17 22:03:07 +0100 |
commit | cc857482b85c46d08de6eebce243ebe3a43de544 (patch) | |
tree | 8c01875ac45bf462d5c9e64441ac49d91dbc5b30 /metrics-proxy/src/test | |
parent | 6eb1cbbd54c9e309264961bf16128263a702390b (diff) |
Handle that metrics can arrive with a dimension set to null. Skip and log it as debug.
Let exceptions through in the tests so that we do not hide errors there.
Diffstat (limited to 'metrics-proxy/src/test')
-rw-r--r-- | metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java index b25d3af2c20..56e78e3930c 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java @@ -6,24 +6,27 @@ import ai.vespa.metricsproxy.metric.Metric; import ai.vespa.metricsproxy.metric.Metrics; import org.junit.Test; +import java.io.IOException; + import static ai.vespa.metricsproxy.metric.model.MetricId.toMetricId; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** */ public class MetricsFetcherTest { private static final int port = 9; //port number is not used in this test - private static final double EPSILON = 0.00000000001; - private class MetricsConsumer implements MetricsParser.Consumer { + private static class MetricsConsumer implements MetricsParser.Consumer { Metrics metrics = new Metrics(); @Override public void consume(Metric metric) { metrics.add(metric); } } - Metrics fetch(String data) { + Metrics fetch(String data) throws IOException { RemoteMetricsFetcher fetcher = new RemoteMetricsFetcher(new DummyService(0, "dummy/id/0"), port); MetricsConsumer consumer = new MetricsConsumer(); fetcher.createMetrics(data, consumer, 0); @@ -31,7 +34,7 @@ public class MetricsFetcherTest { } @Test - public void testStateFormatMetricsParse() { + public void testStateFormatMetricsParse() throws IOException { String jsonData = TestUtil.getFileContents("metrics-state.json"); Metrics metrics = fetch(jsonData); assertEquals(10, metrics.size()); @@ -41,20 +44,25 @@ public class MetricsFetcherTest { } @Test - public void testEmptyJson() { + public void testEmptyJson() throws IOException { String jsonData = "{}"; Metrics metrics = fetch(jsonData); assertEquals(0, metrics.size()); } @Test - public void testErrors() { + public void testErrors() throws IOException { String jsonData; - Metrics metrics; + Metrics metrics = null; jsonData = ""; - metrics = fetch(jsonData); - assertEquals(0, metrics.size()); + try { + metrics = fetch(jsonData); + fail("Should have an IOException instead"); + } catch (IOException e) { + assertEquals("Expected start of object, got null", e.getMessage()); + } + assertNull(metrics); jsonData = "{\n" + "\"status\" : {\n" + @@ -91,8 +99,14 @@ public class MetricsFetcherTest { "}\n" + "}"; - metrics = fetch(jsonData); - assertEquals(0, metrics.size()); + metrics = null; + try { + metrics = fetch(jsonData); + fail("Should have an IOException instead"); + } catch (IllegalArgumentException e) { + assertEquals("Value for aggregator 'count' is not a number", e.getMessage()); + } + assertNull(metrics); } public Metric getMetric(String metric, Metrics metrics) { |