1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.rest;
20
21 import org.apache.hadoop.hbase.SmallTests;
22 import org.apache.hadoop.hbase.rest.metrics.RESTMetrics;
23 import org.junit.Test;
24 import org.junit.experimental.categories.Category;
25 import static org.junit.Assert.*;
26
27
28
29
30 @Category(SmallTests.class)
31 public class TestRESTMetrics {
32
33 @Test
34 public void testRESTMetrics() throws InterruptedException {
35 long timeout = 2000;
36 RESTMetrics test = new RESTMetrics();
37 int incrementSucessfulGet = 20000;
38 int incrementSucessfulDelete = 3000000;
39 int incrementSucessfulPut = 3000000;
40 int incrementRequest = incrementSucessfulGet + incrementSucessfulDelete + incrementSucessfulPut;
41
42 int incrementFailedGetRequests = 100;
43 int incrementFailedDeleteRequests = 30;
44 int incrementFailedPutRequests = 2;
45
46 long start1 = System.currentTimeMillis();
47 test.doUpdates(null);
48
49
50 assertEquals(0, test.getRequests(), 0.01);
51 assertEquals(0, test.getSucessfulDeleteCount(), 0.01);
52 assertEquals(0, test.getSucessfulPutCount(), 0.01);
53 assertEquals(0, test.getSucessfulGetCount(), 0.01);
54 assertEquals(0, test.getFailedDeleteCount(), 0.01);
55 assertEquals(0, test.getFailedGetCount(), 0.01);
56 assertEquals(0, test.getFailedPutCount(), 0.01);
57
58
59 Thread.sleep(timeout);
60 test.incrementRequests(incrementRequest);
61 test.incrementSucessfulGetRequests(incrementSucessfulGet);
62 test.incrementSucessfulDeleteRequests(incrementSucessfulDelete);
63 test.incrementSucessfulPutRequests(incrementSucessfulPut);
64 test.incrementFailedGetRequests(incrementFailedGetRequests);
65 test.incrementFailedDeleteRequests(incrementFailedDeleteRequests);
66 test.incrementFailedPutRequests(incrementFailedPutRequests);
67
68 test.doUpdates(null);
69
70
71 long tmax = System.currentTimeMillis() - start1;
72
73 testData(tmax, timeout, test.getRequests(), incrementRequest);
74 testData(tmax, timeout, test.getSucessfulGetCount(), incrementSucessfulGet);
75 testData(tmax, timeout, test.getSucessfulDeleteCount(), incrementSucessfulDelete);
76 testData(tmax, timeout, test.getSucessfulPutCount(), incrementSucessfulPut);
77 testData(tmax, timeout, test.getFailedGetCount(), incrementFailedGetRequests);
78 testData(tmax, timeout, test.getFailedDeleteCount(), incrementFailedDeleteRequests);
79 testData(tmax, timeout, test.getFailedPutCount(), incrementFailedPutRequests);
80
81 test.shutdown();
82 }
83
84
85 private void testData(double tmax, long tmin, float value, double requests) {
86 assertTrue((requests / tmax) * 1000 <= value);
87 assertTrue((requests / tmin) * 1000 >= value);
88
89 }
90 }