You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2013/03/21 19:53:04 UTC
svn commit: r1459459 - in /hbase/branches/0.89-fb/src:
main/java/org/apache/hadoop/hbase/regionserver/
test/java/org/apache/hadoop/hbase/regionserver/
test/java/org/apache/hadoop/hbase/util/
Author: liyin
Date: Thu Mar 21 18:53:03 2013
New Revision: 1459459
URL: http://svn.apache.org/r1459459
Log:
[HBASE-7276] Fix TestRegionServerMetrics failing test one more time
Author: adela
Summary:
Can't see how we get negative numbers there. I am putting the
test case in a separate class let's see if that will fix the problem
Test Plan: tested on my machine
Reviewers: liyintang, rshroff, manukranthk
Reviewed By: rshroff
CC: hbase-eng@
Differential Revision: https://phabricator.fb.com/D695499
Task ID: 1981461
Added:
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestNumReadsWritesPerRs.java
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/UnitTestRunner.java
Modified:
hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1459459&r1=1459458&r2=1459459&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Thu Mar 21 18:53:03 2013
@@ -356,6 +356,8 @@ public class HRegionServer implements HR
private int numRowRequests = 0;
+ public static boolean runMetrics = true;
+
public static long getResponseSizeLimit() {
return responseSizeLimit;
}
@@ -1334,14 +1336,14 @@ public class HRegionServer implements HR
}
}
- /*
- * @param interval Interval since last time metrics were called.
- */
protected void doMetrics() {
- try {
- metrics();
- } catch (Throwable e) {
- LOG.warn("Failed metrics", e);
+ // for testing purposes we don't want to collect the metrics if runMetrics is false
+ if (runMetrics) {
+ try {
+ metrics();
+ } catch (Throwable e) {
+ LOG.warn("Failed metrics", e);
+ }
}
}
Added: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestNumReadsWritesPerRs.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestNumReadsWritesPerRs.java?rev=1459459&view=auto
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestNumReadsWritesPerRs.java (added)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestNumReadsWritesPerRs.java Thu Mar 21 18:53:03 2013
@@ -0,0 +1,83 @@
+package org.apache.hadoop.hbase.regionserver;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.UnitTestRunner;
+import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+//uncomment these lines if you want to run the unit test more times
+//import org.junit.runner.RunWith;
+
+//@RunWith(UnitTestRunner.class)
+public class TestNumReadsWritesPerRs {
+ private String[] FAMILIES = new String[] { "cf1", "cf2", "anotherCF" };
+ private static final int MAX_VERSIONS = 1;
+ private static final int NUM_COLS_PER_ROW = 15;
+ private static final int NUM_FLUSHES = 3;
+ private static final int NUM_REGIONS = 4;
+
+ private final HBaseTestingUtility testUtil =
+ new HBaseTestingUtility();
+ private Map<String, Long> startingMetrics;
+
+ @Before
+ public void setUp() throws Exception {
+ SchemaMetrics.setUseTableNameInTest(true);
+ startingMetrics = SchemaMetrics.getMetricsSnapshot();
+ testUtil.startMiniCluster();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ testUtil.shutdownMiniCluster();
+ SchemaMetrics.validateMetricChanges(startingMetrics);
+ }
+
+ @Test
+ public void testNumReadsAndWrites() throws IOException, InterruptedException{
+ testUtil.createRandomTable("NumReadsWritesTest", Arrays.asList(FAMILIES),
+ MAX_VERSIONS, NUM_COLS_PER_ROW, NUM_FLUSHES, NUM_REGIONS, 1000);
+ List<RegionServerThread> threads = testUtil.getMiniHBaseCluster()
+ .getLiveRegionServerThreads();
+ HRegionServer rs = threads.get(0).getRegionServer();
+ HRegionServer.runMetrics = false;
+ long preNumRead = 0;
+ long preNumWrite = 0;
+ for (HRegion region : rs.getOnlineRegions()) {
+ HRegionInfo regionInfo = region.getRegionInfo();
+ if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+ preNumRead += region.rowReadCnt.get();
+ preNumWrite += region.rowUpdateCnt.get();
+ }
+ }
+ HRegion[] regions = rs.getOnlineRegionsAsArray();
+ for (int i = 0; i < regions.length; i++) {
+ Get g = new Get(Bytes.toBytes("row" + i));
+ regions[i].get(g, null);
+ }
+ long numRead = 0;
+ long numWrite = 0;
+ for (HRegion region : rs.getOnlineRegions()) {
+ HRegionInfo regionInfo = region.getRegionInfo();
+ if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+ numRead += region.rowReadCnt.get();
+ numWrite += region.rowUpdateCnt.get();
+ }
+ }
+ assertEquals(regions.length - 2, numRead - preNumRead);
+ assertEquals(0, numWrite - preNumWrite);
+ HRegionServer.runMetrics = true;
+ }
+}
Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java?rev=1459459&r1=1459458&r2=1459459&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java Thu Mar 21 18:53:03 2013
@@ -22,9 +22,7 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -33,8 +31,6 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTestConst;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Delete;
@@ -48,7 +44,6 @@ import org.apache.hadoop.hbase.io.hfile.
import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics;
import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics.StoreMetricType;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -222,43 +217,6 @@ public class TestRegionServerMetrics {
}
@Test
- public void testNumReadsAndWrites() throws IOException, InterruptedException{
- testUtil.createRandomTable("NumReadsWritesTest", Arrays.asList(FAMILIES),
- MAX_VERSIONS, NUM_COLS_PER_ROW, NUM_FLUSHES, NUM_REGIONS, 1000);
- List<RegionServerThread> threads = testUtil.getMiniHBaseCluster()
- .getLiveRegionServerThreads();
- HRegionServer rs = threads.get(0).getRegionServer();
- long preNumRead = 0;
- long preNumWrite = 0;
- for (HRegion region : rs.getOnlineRegions()) {
- HRegionInfo regionInfo = region.getRegionInfo();
- if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
- System.out.println(region.getRegionNameAsString());
- preNumRead += region.rowReadCnt.get();
- preNumWrite += region.rowUpdateCnt.get();
- }
- }
-
- HRegion[] regions = rs.getOnlineRegionsAsArray();
- for (int i = 0; i < regions.length; i++) {
- Get g = new Get(Bytes.toBytes("row" + i));
- regions[i].get(g, null);
- }
-
- long numRead = 0;
- long numWrite = 0;
- for (HRegion region : rs.getOnlineRegions()) {
- HRegionInfo regionInfo = region.getRegionInfo();
- if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
- numRead += region.rowReadCnt.get();
- numWrite += region.rowUpdateCnt.get();
- }
- }
- assertEquals(regions.length - 2, numRead - preNumRead);
- assertEquals(0, numWrite - preNumWrite);
- }
-
- @Test
public void testEncodingInCache() throws Exception {
HTable t = null;
try {
Added: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/UnitTestRunner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/UnitTestRunner.java?rev=1459459&view=auto
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/UnitTestRunner.java (added)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/UnitTestRunner.java Thu Mar 21 18:53:03 2013
@@ -0,0 +1,63 @@
+package org.apache.hadoop.hbase.util;
+
+import org.junit.runner.Description;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * Run unit test until it fails or MAX_RUN_COUNT times
+ * http://stackoverflow.com/questions
+ * /1835523/is-there-a-way-to-make-eclipse-run-
+ * a-junit-test-multiple-times-until-failure
+ *
+ *
+ */
+public class UnitTestRunner extends Runner {
+
+ private static final int MAX_RUN_COUNT = 50;
+
+ private BlockJUnit4ClassRunner runner;
+
+ @SuppressWarnings("rawtypes")
+ public UnitTestRunner(final Class testClass) throws InitializationError {
+ runner = new BlockJUnit4ClassRunner(testClass);
+ }
+
+ @Override
+ public Description getDescription() {
+ final Description description = Description
+ .createSuiteDescription("Run many times until failure");
+ description.addChild(runner.getDescription());
+ return description;
+ }
+
+ @Override
+ public void run(final RunNotifier notifier) {
+ class L extends RunListener {
+ boolean shouldContinue = true;
+ int runCount = 0;
+
+ @Override
+ public void testFailure(final Failure failure) throws Exception {
+ shouldContinue = false;
+ }
+
+ @Override
+ public void testFinished(Description description) throws Exception {
+ runCount++;
+ shouldContinue = (shouldContinue && runCount < MAX_RUN_COUNT);
+ }
+ }
+
+ final L listener = new L();
+ notifier.addListener(listener);
+
+ while (listener.shouldContinue) {
+ runner.run(notifier);
+ }
+ }
+}