import org.apache.hadoop.hbase.rest.metrics.RESTMetrics; //导入依赖的package包/类
@Test
public void testRESTMetrics() throws InterruptedException {
long timeout = 2000;
RESTMetrics test = new RESTMetrics();
int incrementSucessfulGet = 20000;
int incrementSucessfulDelete = 3000000;
int incrementSucessfulPut = 3000000;
int incrementRequest = incrementSucessfulGet + incrementSucessfulDelete + incrementSucessfulPut;
int incrementFailedGetRequests = 100;
int incrementFailedDeleteRequests = 30;
int incrementFailedPutRequests = 2;
long start1 = System.currentTimeMillis();
test.doUpdates(null);
// started value
assertEquals(0, test.getRequests(), 0.01);
assertEquals(0, test.getSucessfulDeleteCount(), 0.01);
assertEquals(0, test.getSucessfulPutCount(), 0.01);
assertEquals(0, test.getSucessfulGetCount(), 0.01);
assertEquals(0, test.getFailedDeleteCount(), 0.01);
assertEquals(0, test.getFailedGetCount(), 0.01);
assertEquals(0, test.getFailedPutCount(), 0.01);
// sleep some seconds
Thread.sleep(timeout);
test.incrementRequests(incrementRequest);
test.incrementSucessfulGetRequests(incrementSucessfulGet);
test.incrementSucessfulDeleteRequests(incrementSucessfulDelete);
test.incrementSucessfulPutRequests(incrementSucessfulPut);
test.incrementFailedGetRequests(incrementFailedGetRequests);
test.incrementFailedDeleteRequests(incrementFailedDeleteRequests);
test.incrementFailedPutRequests(incrementFailedPutRequests);
test.doUpdates(null);
// The maximum time for stability test
long tmax = System.currentTimeMillis() - start1;
testData(tmax, timeout, test.getRequests(), incrementRequest);
testData(tmax, timeout, test.getSucessfulGetCount(), incrementSucessfulGet);
testData(tmax, timeout, test.getSucessfulDeleteCount(), incrementSucessfulDelete);
testData(tmax, timeout, test.getSucessfulPutCount(), incrementSucessfulPut);
testData(tmax, timeout, test.getFailedGetCount(), incrementFailedGetRequests);
testData(tmax, timeout, test.getFailedDeleteCount(), incrementFailedDeleteRequests);
testData(tmax, timeout, test.getFailedPutCount(), incrementFailedPutRequests);
test.shutdown();
}
请发表评论