[ONOS-4127] Backup metric service to ganglia monitoring server
- Initial implementation of metric service reporter
- Unit test for metric service reporter
- Bump up metric lib from 3.1.0 to 3.1.2
Change-Id: Ia178df759d671dfc15cffaacb09d5279ad3d9ad8
diff --git a/apps/metricsreporter/src/test/java/org/onosproject/metrics/reporter/GangliaMetricsReporterTest.java b/apps/metricsreporter/src/test/java/org/onosproject/metrics/reporter/GangliaMetricsReporterTest.java
new file mode 100644
index 0000000..c0eeb1a
--- /dev/null
+++ b/apps/metricsreporter/src/test/java/org/onosproject/metrics/reporter/GangliaMetricsReporterTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.metrics.reporter;
+
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableSet;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit test for metrics reporter of ganglia.
+ */
+public class GangliaMetricsReporterTest {
+
+ private GangliaMetricsReporter gmr;
+
+ private static final String METRIC_NAME1 = "consistentMap.onos-app-ids.putIfAbsent";
+ private static final String METRIC_NAME2 = "consistentMap.onos-hosts.entrySet";
+ private static final String METRIC_NAME3 = "clusterCommunication.endpoint.*";
+ private static final String METRIC_NAME4 = "atomicCounter.onos-app-id-counter.*";
+
+ private static final String PREFIXES1 = "consistentMap";
+ private static final String PREFIXES2 = "topology";
+ private static final String PREFIXES3 = "consistentMap.onos-app-ids";
+ private static final String PREFIXES4 = "consistentMap, clusterCommunication, atomicCounter";
+
+ /**
+ * Initializes ganglia metrics reporter instance.
+ */
+ @Before
+ public void setUp() {
+ gmr = new GangliaMetricsReporter();
+ }
+
+ /**
+ * Tests whether the containsName method can always return the correct result
+ * with the given metric name and a set of prefixes.
+ */
+ @Test
+ public void testContainsName() {
+ assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES1));
+ assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES3));
+ assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES4));
+ assertTrue(gmr.containsName(METRIC_NAME2, PREFIXES4));
+ assertTrue(gmr.containsName(METRIC_NAME3, PREFIXES4));
+ assertTrue(gmr.containsName(METRIC_NAME4, PREFIXES4));
+ assertFalse(gmr.containsName(METRIC_NAME1, PREFIXES2));
+ }
+
+ /**
+ * Tests whether the filter method can always return the correct result.
+ */
+ @Test
+ public void testFilter() {
+ MetricRegistry filtered;
+ MetricRegistry full = new MetricRegistry();
+ full.meter(METRIC_NAME1);
+ full.meter(METRIC_NAME2);
+ full.meter(METRIC_NAME3);
+ full.meter(METRIC_NAME4);
+
+ gmr.monitorAll = true;
+ filtered = gmr.filter(full);
+
+ assertTrue(filtered.getNames()
+ .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2,
+ METRIC_NAME3, METRIC_NAME4)));
+
+ gmr.monitorAll = false;
+ gmr.metricNames = PREFIXES1;
+ filtered = gmr.filter(full);
+
+ assertTrue(filtered.getNames()
+ .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2)));
+ assertFalse(filtered.getNames()
+ .containsAll(ImmutableSet.of(METRIC_NAME3, METRIC_NAME4)));
+
+ gmr.metricNames = PREFIXES2;
+ filtered = gmr.filter(full);
+
+ assertFalse(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME1)));
+
+ gmr.metricNames = PREFIXES3;
+ filtered = gmr.filter(full);
+
+ assertTrue(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME1)));
+ assertFalse(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME2)));
+
+ gmr.metricNames = PREFIXES4;
+ filtered = gmr.filter(full);
+
+ assertTrue(filtered.getNames()
+ .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2,
+ METRIC_NAME3, METRIC_NAME4)));
+ }
+}