From eb6be2946b2578d787b42bbedb0f930c98f3bcdd Mon Sep 17 00:00:00 2001 From: Jiyang Date: Wed, 13 Mar 2024 17:25:12 -0500 Subject: [PATCH] Add 5 exceptional-behavior tests --- .../java/org/opennms/newts/aggregate/ComputeTest.java | 9 +++++++++ .../java/org/opennms/newts/aggregate/ExportTest.java | 10 ++++++++++ .../org/opennms/newts/aggregate/PrimaryDataTest.java | 5 +++++ .../java/org/opennms/newts/aggregate/RateTest.java | 6 ++++++ .../org/opennms/newts/api/TimestampDurationTest.java | 5 +++++ 5 files changed, 35 insertions(+) diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/ComputeTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/ComputeTest.java index 87a5d626..aecd0a4f 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/ComputeTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/ComputeTest.java @@ -152,4 +152,13 @@ public void testBlacklist() { compute.next().getElement("sum"); } } + + @Test(expected = UnsupportedOperationException.class) + public void testRemove() { + Iterator> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).row(600).element("in", 6).element("out", 4).build(); + ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", AVERAGE).datasource("out", AVERAGE).calculate("total", PLUS, "in", "out"); + Iterator> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).element("total", 4).row(600).element("in", 6).element("out", 4).element("total", 10).build(); + Compute compute = new Compute(rDescriptor, testData); + compute.remove(); +} } diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/ExportTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/ExportTest.java index deaaa524..c63eadfe 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/ExportTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/ExportTest.java @@ -53,4 +53,14 @@ public void test() { } + @Test(expected = UnsupportedOperationException.class) + public void testRemove() { + Iterator> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m0", 1).element("m1", 2).element("m2", 3).row(300).element("m0", 1).element("m1", 2).element("m2", 3).row(600).element("m0", 1).element("m1", 2).element("m2", 3).build(); + ResultDescriptor rDescriptor = new ResultDescriptor().datasource("m1", null).export("m1"); + Iterator> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m1", 2).row(300).element("m1", 2).row(600).element("m1", 2).build(); + assertRowsEqual(expected, new Export(rDescriptor.getExports(), testData)); + Iterator> it = new Export(rDescriptor.getExports(), testData); + it.remove(); + } + } diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataTest.java index 0112147c..842fb759 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataTest.java @@ -430,4 +430,9 @@ public void testHeartbeatNaNs() { assertRowsEqual(expected, primaryData); } + + @Test(expected = UnsupportedOperationException.class) + public void testRemove() { + new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(0), Timestamp.fromEpochSeconds(1000), new ResultDescriptor(), new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).row(100).element("m0", 1).build()).remove(); + } } diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/RateTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/RateTest.java index 4d2de91c..3415f77a 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/RateTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/RateTest.java @@ -237,6 +237,12 @@ public void testNanOnCounterWrap() { } } + @Test(expected = UnsupportedOperationException.class) + public void testRemove() { + Iterator> input = new Rate(new Results().iterator(), getMetrics(2)).iterator(); + input.remove(); + } + private Set getMetrics(int number) { return Sets.newHashSet(Arrays.copyOf(m_metrics, number)); } diff --git a/api/src/test/java/org/opennms/newts/api/TimestampDurationTest.java b/api/src/test/java/org/opennms/newts/api/TimestampDurationTest.java index 11f272ad..5f1facec 100644 --- a/api/src/test/java/org/opennms/newts/api/TimestampDurationTest.java +++ b/api/src/test/java/org/opennms/newts/api/TimestampDurationTest.java @@ -118,4 +118,9 @@ public void test() { } + @Test(expected = IllegalArgumentException.class) + public void testInvalidDuration() { + Duration.parse("100d 100w"); + } + }