1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.hadoop.hbase.regionserver;
17
18
19 import java.io.IOException;
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.hbase.HBaseTestingUtility;
22 import org.apache.hadoop.hbase.HConstants;
23 import org.apache.hadoop.hbase.TableName;
24 import org.apache.hadoop.hbase.client.Admin;
25 import org.apache.hadoop.hbase.client.Table;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
28 import org.junit.AfterClass;
29 import org.junit.Assert;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33
34
35
36
37 @Category({ RegionServerTests.class, MediumTests.class })
38 public class TestRequestsPerSecondMetric {
39
40 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
41 private static final long METRICS_PERIOD = 2000L;
42 private static Configuration conf;
43
44
45 @BeforeClass
46 public static void setup() throws Exception {
47 conf = UTIL.getConfiguration();
48 conf.setLong(HConstants.REGIONSERVER_METRICS_PERIOD, METRICS_PERIOD);
49 UTIL.startMiniCluster(1);
50 }
51
52 @AfterClass
53 public static void teardown() throws Exception {
54 UTIL.shutdownMiniCluster();
55 }
56
57
58 @Test
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public void testNoNegativeSignAtRequestsPerSecond() throws IOException, InterruptedException {
73 final TableName TABLENAME = TableName.valueOf("t");
74 final String FAMILY = "f";
75 Admin admin = UTIL.getHBaseAdmin();
76 UTIL.createMultiRegionTable(TABLENAME, FAMILY.getBytes(),25);
77 Table table = admin.getConnection().getTable(TABLENAME);
78 HRegionServer regionServer = UTIL.getMiniHBaseCluster().getRegionServer(0);
79 MetricsRegionServerWrapperImpl metricsWrapper =
80 new MetricsRegionServerWrapperImpl(regionServer);
81 MetricsRegionServerWrapperImpl.RegionServerMetricsWrapperRunnable metricsServer
82 = metricsWrapper.new RegionServerMetricsWrapperRunnable();
83 metricsServer.run();
84 UTIL.loadNumericRows(table, FAMILY.getBytes(), 1, 2000);
85 Thread.sleep(METRICS_PERIOD);
86 metricsServer.run();
87 admin.disableTable(TABLENAME);
88 Thread.sleep(METRICS_PERIOD);
89 metricsServer.run();
90 Assert.assertTrue(metricsWrapper.getRequestsPerSecond() > -1);
91 }
92 }