1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.metrics;
20
21 import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
22 import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertSame;
29
30
31
32
33 public class TestBaseSourceImpl {
34
35 private static BaseSourceImpl bmsi;
36
37 @BeforeClass
38 public static void setUp() throws Exception {
39 bmsi = new BaseSourceImpl("TestName", "test description", "testcontext", "TestContext");
40 }
41
42 @Test
43 public void testSetGauge() throws Exception {
44 String key = "testset";
45 bmsi.setGauge(key, 100);
46 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
47 assertEquals(key, g.name);
48 bmsi.setGauge(key, 110);
49 assertSame(g, bmsi.metricsRegistry.get(key));
50
51 }
52
53 @Test
54 public void testIncGauge() throws Exception {
55 String key = "testincgauge";
56 bmsi.incGauge(key, 100);
57 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
58 assertEquals(key, g.name);
59 bmsi.incGauge(key, 10);
60 assertSame(g, bmsi.metricsRegistry.get(key));
61 }
62
63 @Test
64 public void testDecGauge() throws Exception {
65 String key = "testdec";
66 bmsi.decGauge(key, 100);
67 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
68 assertEquals(key, g.name);
69 bmsi.decGauge(key, 100);
70 assertSame(g, bmsi.metricsRegistry.get(key));
71 }
72
73 @Test
74 public void testIncCounters() throws Exception {
75 String key = "testinccounter";
76 bmsi.incCounters(key, 100);
77 MetricMutableCounterLong c = (MetricMutableCounterLong) bmsi.metricsRegistry.get(key);
78 assertEquals(key, c.name);
79 bmsi.incCounters(key, 100);
80 assertSame(c, bmsi.metricsRegistry.get(key));
81 }
82
83 @Test
84 public void testRemoveMetric() throws Exception {
85 bmsi.setGauge("testrm", 100);
86 bmsi.removeMetric("testrm");
87 assertNull(bmsi.metricsRegistry.get("testrm"));
88
89 }
90
91 }