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.MutableCounterLong;
22 import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
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
29
30
31
32 public class TestBaseSourceImpl {
33
34 private static BaseSourceImpl bmsi;
35
36 @BeforeClass
37 public static void setUp() throws Exception {
38 bmsi = new BaseSourceImpl("TestName", "test description", "testcontext", "TestContext");
39 }
40
41 @Test
42 public void testSetGauge() throws Exception {
43 bmsi.setGauge("testset", 100);
44 assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());
45 bmsi.setGauge("testset", 300);
46 assertEquals(300, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());
47
48 }
49
50 @Test
51 public void testIncGauge() throws Exception {
52 bmsi.incGauge("testincgauge", 100);
53 assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());
54 bmsi.incGauge("testincgauge", 100);
55 assertEquals(200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());
56
57 }
58
59 @Test
60 public void testDecGauge() throws Exception {
61 bmsi.decGauge("testdec", 100);
62 assertEquals(-100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());
63 bmsi.decGauge("testdec", 100);
64 assertEquals(-200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());
65
66 }
67
68 @Test
69 public void testIncCounters() throws Exception {
70 bmsi.incCounters("testinccounter", 100);
71 assertEquals(100, ((MutableCounterLong) bmsi.metricsRegistry.get("testinccounter")).value());
72 bmsi.incCounters("testinccounter", 100);
73 assertEquals(200, ((MutableCounterLong) bmsi.metricsRegistry.get("testinccounter")).value());
74
75 }
76
77 @Test
78 public void testRemoveMetric() throws Exception {
79 bmsi.setGauge("testrmgauge", 100);
80 bmsi.removeMetric("testrmgauge");
81 assertNull(bmsi.metricsRegistry.get("testrmgauge"));
82 }
83
84 }