diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/metrics')
7 files changed, 92 insertions, 96 deletions
diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java index cc5d110d423..11cc8b86a09 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java @@ -1,7 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.List; @@ -12,10 +13,9 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableMap; import com.yahoo.metrics.simple.UntypedMetric.AssumedType; @@ -28,18 +28,18 @@ import com.yahoo.metrics.simple.UntypedMetric.AssumedType; public class BucketTest { private Bucket bucket; - @Before + @BeforeEach public void setUp() throws Exception { bucket = new Bucket(); } - @After + @AfterEach public void tearDown() throws Exception { bucket = null; } @Test - public final void testEntrySet() { + final void testEntrySet() { assertEquals(0, bucket.entrySet().size()); for (int i = 0; i < 4; ++i) { bucket.put(new Sample(new Measurement(i), new Identifier("nalle_" + i, null), AssumedType.GAUGE)); @@ -47,7 +47,7 @@ public class BucketTest { assertEquals(4, bucket.entrySet().size()); for (int i = 0; i < 4; ++i) { bucket.put(new Sample(new Measurement(i), new Identifier("nalle", - new Point(new ImmutableMap.Builder<String, Integer>().put("dim", Integer.valueOf(i)).build())), + new Point(new ImmutableMap.Builder<String, Integer>().put("dim", Integer.valueOf(i)).build())), AssumedType.GAUGE)); } assertEquals(8, bucket.entrySet().size()); @@ -55,23 +55,23 @@ public class BucketTest { for (Entry<Identifier, UntypedMetric> x : bucket.entrySet()) { String metricName = x.getKey().getName(); switch (metricName) { - case "nalle": - ++nalle; - break; - case "nalle_0": - ++nalle0; - break; - case "nalle_1": - ++nalle1; - break; - case "nalle_2": - ++nalle2; - break; - case "nalle_3": - ++nalle3; - break; - default: - throw new IllegalStateException(); + case "nalle": + ++nalle; + break; + case "nalle_0": + ++nalle0; + break; + case "nalle_1": + ++nalle1; + break; + case "nalle_2": + ++nalle2; + break; + case "nalle_3": + ++nalle3; + break; + default: + throw new IllegalStateException(); } } assertEquals(4, nalle); @@ -82,7 +82,7 @@ public class BucketTest { } @Test - public final void testPutSampleWithUnsupportedType() { + final void testPutSampleWithUnsupportedType() { boolean caughtIt = false; try { bucket.put(new Sample(new Measurement(1), new Identifier("nalle", null), AssumedType.NONE)); @@ -93,7 +93,7 @@ public class BucketTest { } @Test - public final void testPutIdentifierUntypedValue() { + final void testPutIdentifierUntypedValue() { UntypedMetric v = new UntypedMetric(null); v.add(2); bucket.put(new Sample(new Measurement(3), new Identifier("nalle", null), AssumedType.GAUGE)); @@ -106,10 +106,10 @@ public class BucketTest { } @Test - public final void testHasIdentifier() { + final void testHasIdentifier() { for (int i = 0; i < 4; ++i) { bucket.put(new Sample(new Measurement(i), new Identifier("nalle_" + i, new Point( - new ImmutableMap.Builder<String, Integer>().put(String.valueOf(i), Integer.valueOf(i)).build())), + new ImmutableMap.Builder<String, Integer>().put(String.valueOf(i), Integer.valueOf(i)).build())), AssumedType.GAUGE)); } for (int i = 0; i < 4; ++i) { @@ -119,7 +119,7 @@ public class BucketTest { } @Test - public final void testOkMerge() { + final void testOkMerge() { bucket.put(new Sample(new Measurement(2), new Identifier("nalle", null), AssumedType.GAUGE)); Bucket otherNew = new Bucket(); otherNew.put(new Sample(new Measurement(3), new Identifier("nalle", null), AssumedType.GAUGE)); @@ -138,7 +138,7 @@ public class BucketTest { } @Test - public final void testMergeDifferentMetrics() { + final void testMergeDifferentMetrics() { bucket.put(new Sample(new Measurement(2), new Identifier("nalle", null), AssumedType.GAUGE)); Bucket otherNew = new Bucket(); otherNew.put(new Sample(new Measurement(3), new Identifier("other", null), AssumedType.GAUGE)); @@ -188,7 +188,7 @@ public class BucketTest { } @Test - public final void testMismatchedMerge() { + final void testMismatchedMerge() { Logger log = Logger.getLogger(Bucket.class.getName()); boolean[] loggingMarker = new boolean[1]; loggingMarker[0] = false; @@ -205,7 +205,7 @@ public class BucketTest { } @Test - public final void testGetAllMetricNames() { + final void testGetAllMetricNames() { twoMetricsUniqueDimensions(); Collection<String> names = bucket.getAllMetricNames(); assertEquals(2, names.size()); @@ -214,7 +214,7 @@ public class BucketTest { } @Test - public final void testGetValuesForMetric() { + final void testGetValuesForMetric() { twoMetricsUniqueDimensions(); Collection<Entry<Point, UntypedMetric>> values = bucket.getValuesForMetric("nalle"); assertEquals(4, values.size()); @@ -231,7 +231,7 @@ public class BucketTest { } @Test - public final void testGetValuesByMetricName() { + final void testGetValuesByMetricName() { twoMetricsUniqueDimensions(); Map<String, List<Entry<Point, UntypedMetric>>> values = bucket.getValuesByMetricName(); assertEquals(2, values.size()); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java index f579b1584aa..45a76078619 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import static org.junit.Assert.*; - import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -10,9 +8,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Functional tests for counters. @@ -23,18 +22,18 @@ public class CounterTest { MetricReceiver receiver; - @Before + @BeforeEach public void setUp() throws Exception { receiver = new MetricReceiver.MockReceiver(); } - @After + @AfterEach public void tearDown() throws Exception { receiver = null; } @Test - public final void testAdd() throws InterruptedException { + final void testAdd() throws InterruptedException { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); c.add(); @@ -48,7 +47,7 @@ public class CounterTest { } @Test - public final void testAddLong() throws InterruptedException { + final void testAddLong() throws InterruptedException { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); final long twoToThePowerOfFourtyeight = 65536L * 65536L * 65536L; @@ -63,7 +62,7 @@ public class CounterTest { } @Test - public final void testAddPoint() throws InterruptedException { + final void testAddPoint() throws InterruptedException { final String metricName = "unitTestCounter"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Counter c = receiver.declareCounter(metricName, p); @@ -75,10 +74,10 @@ public class CounterTest { assertEquals(1, x.size()); assertEquals(p, x.get(0).getKey()); assertEquals(1, x.get(0).getValue().getCount()); - } + } @Test - public final void testAddLongPoint() throws InterruptedException { + final void testAddLongPoint() throws InterruptedException { final String metricName = "unitTestCounter"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Counter c = receiver.declareCounter(metricName, p); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/DimensionsCacheTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/DimensionsCacheTest.java index b1b1ff28aeb..267ca1d575d 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/DimensionsCacheTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/DimensionsCacheTest.java @@ -1,17 +1,17 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.metrics.simple.UntypedMetric.AssumedType; /** @@ -24,18 +24,18 @@ public class DimensionsCacheTest { private static final int POINTS_TO_KEEP = 3; DimensionCache cache; - @Before + @BeforeEach public void setUp() throws Exception { cache = new DimensionCache(POINTS_TO_KEEP); } - @After + @AfterEach public void tearDown() throws Exception { cache = null; } @Test - public final void smokeTest() { + final void smokeTest() { String metricName = "testMetric"; Bucket first = new Bucket(); for (int i = 0; i < 4; ++i) { @@ -53,11 +53,11 @@ public class DimensionsCacheTest { newestFound = true; } } - assertTrue("Kept newest measurement when padding points.", newestFound); + assertTrue(newestFound, "Kept newest measurement when padding points."); } @Test - public final void testNoBoomWithEmptyBuckets() { + final void testNoBoomWithEmptyBuckets() { Bucket check = new Bucket(); cache.updateDimensionPersistence(null, new Bucket()); cache.updateDimensionPersistence(null, new Bucket()); @@ -66,7 +66,7 @@ public class DimensionsCacheTest { } @Test - public final void testUpdateWithNullThenDataThenData() { + final void testUpdateWithNullThenDataThenData() { Bucket first = new Bucket(); populateDimensionLessValue("one", first, 2); cache.updateDimensionPersistence(null, first); @@ -80,7 +80,7 @@ public class DimensionsCacheTest { } @Test - public final void requireThatOldDataIsForgotten() { + final void requireThatOldDataIsForgotten() { Bucket first = new Bucket(); // "now" as timestamp populateDimensionLessValue("one", first, 2); cache.updateDimensionPersistence(first, new Bucket()); @@ -96,7 +96,7 @@ public class DimensionsCacheTest { } @Test - public final void testUpdateWithNullThenDataThenNoDataThenData() { + final void testUpdateWithNullThenDataThenNoDataThenData() { Bucket first = new Bucket(); Bucket second = new Bucket(); populateDimensionLessValue("first", first, 1.0d); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/GaugeTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/GaugeTest.java index 0d4d6360f20..8147f9a53cc 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/GaugeTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/GaugeTest.java @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import static org.junit.Assert.*; - import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -10,10 +8,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.metrics.ManagerConfig; /** @@ -25,18 +23,18 @@ public class GaugeTest { MetricReceiver receiver; - @Before + @BeforeEach public void setUp() throws Exception { receiver = new MetricReceiver.MockReceiver(); } - @After + @AfterEach public void tearDown() throws Exception { receiver = null; } @Test - public final void testSampleDouble() throws InterruptedException { + final void testSampleDouble() throws InterruptedException { final String metricName = "unitTestGauge"; Gauge g = receiver.declareGauge(metricName); g.sample(1.0d); @@ -51,7 +49,7 @@ public class GaugeTest { } @Test - public final void testSampleDoublePoint() throws InterruptedException { + final void testSampleDoublePoint() throws InterruptedException { final String metricName = "unitTestGauge"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Gauge g = receiver.declareGauge(metricName, p); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java index c8a5f17fdfb..f64998f0be4 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java @@ -1,17 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.metrics.simple.jdisc.JdiscMetricsFactory; import com.yahoo.metrics.simple.jdisc.SimpleMetricConsumer; @@ -23,19 +22,19 @@ import com.yahoo.metrics.simple.jdisc.SimpleMetricConsumer; public class MetricsTest extends UnitTestSetup { SimpleMetricConsumer metricApi; - @Before + @BeforeEach public void setUp() throws Exception { super.init(); metricApi = (SimpleMetricConsumer) new JdiscMetricsFactory(metricManager.get()).newInstance(); } - @After + @AfterEach public void tearDown() throws Exception { super.fini(); } @Test - public final void smokeTest() throws InterruptedException { + final void smokeTest() throws InterruptedException { final String metricName = "testMetric"; metricApi.set(metricName, Double.valueOf(1.0d), null); updater.gotData.await(10, TimeUnit.SECONDS); @@ -49,7 +48,7 @@ public class MetricsTest extends UnitTestSetup { } @Test - public final void testRedefinition() { + final void testRedefinition() { MetricReceiver r = metricManager.get(); final String metricName = "gah"; r.addMetricDefinition(metricName, new MetricSettings.Builder().build()); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/PointTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/PointTest.java index ca680c805ef..e6cb70db07a 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/PointTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/PointTest.java @@ -1,20 +1,20 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics.simple; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author bratseth */ public class PointTest { - + @Test - public void testPointEquality() { + void testPointEquality() { Point a = new Point(Collections.emptyMap()); Point b = new Point(new HashMap<>(0)); assertEquals(a.hashCode(), b.hashCode()); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java index 4d4229e8369..7981e5904f3 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java @@ -12,14 +12,14 @@ import com.yahoo.metrics.simple.Identifier; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.metrics.simple.Point; import com.yahoo.metrics.simple.UntypedMetric; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bratseth @@ -27,10 +27,10 @@ import static org.junit.Assert.assertTrue; public class SnapshotConverterTest { @Test - public void testPointConversion() { + void testPointConversion() { MetricDimensions a = SnapshotConverter.convert(new Point(Collections.emptyMap())); MetricDimensions b = SnapshotConverter.convert(new Point(new HashMap<>(0))); - MetricDimensions c = SnapshotConverter.convert((Point)null); + MetricDimensions c = SnapshotConverter.convert((Point) null); assertEquals(a.hashCode(), b.hashCode()); assertEquals(a, b); assertEquals(a.hashCode(), c.hashCode()); @@ -40,11 +40,11 @@ public class SnapshotConverterTest { } @Test - public void testConversion() { + void testConversion() { MetricReceiver mock = new MetricReceiver.MockReceiver(); mock.declareCounter("foo").add(1); mock.declareGauge("quuux").sample(42.25); - mock.declareCounter("bar", new Point(new HashMap<String,String>())).add(4); + mock.declareCounter("bar", new Point(new HashMap<String, String>())).add(4); MetricSnapshot snapshot = new SnapshotConverter(mock.getSnapshot()).convert(); @@ -58,14 +58,14 @@ public class SnapshotConverterTest { ++cnt; if ("foo".equals(mv.getKey())) { assertTrue(mv.getValue() instanceof CountMetric); - assertEquals(1, ((CountMetric)mv.getValue()).getCount()); + assertEquals(1, ((CountMetric) mv.getValue()).getCount()); } else if ("bar".equals(mv.getKey())) { assertTrue(mv.getValue() instanceof CountMetric); - assertEquals(4, ((CountMetric)mv.getValue()).getCount()); + assertEquals(4, ((CountMetric) mv.getValue()).getCount()); } else if ("quuux".equals(mv.getKey())) { assertTrue(mv.getValue() instanceof GaugeMetric); - assertEquals(42.25, ((GaugeMetric)mv.getValue()).getLast(), 0.001); - assertEquals(1, ((GaugeMetric)mv.getValue()).getCount()); + assertEquals(42.25, ((GaugeMetric) mv.getValue()).getLast(), 0.001); + assertEquals(1, ((GaugeMetric) mv.getValue()).getCount()); } else { assertTrue(false); } |