You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2013/10/29 18:05:09 UTC
svn commit: r1536812 -
/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
Author: tedyu
Date: Tue Oct 29 17:05:08 2013
New Revision: 1536812
URL: http://svn.apache.org/r1536812
Log:
HBASE-9836 Fix flakey TestRegionObserverScannerOpenHook test
Modified:
hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java?rev=1536812&r1=1536811&r2=1536812&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java (original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java Tue Oct 29 17:05:08 2013
@@ -30,6 +30,7 @@ import java.util.NavigableSet;
import java.util.concurrent.CountDownLatch;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.Coprocessor;
@@ -53,9 +54,12 @@ import org.apache.hadoop.hbase.regionser
import org.apache.hadoop.hbase.regionserver.InternalScanner;
import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.regionserver.ScanType;
import org.apache.hadoop.hbase.regionserver.Store;
import org.apache.hadoop.hbase.regionserver.StoreScanner;
+import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
+import org.apache.hadoop.hbase.regionserver.wal.HLog;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -202,6 +206,31 @@ public class TestRegionObserverScannerOp
+ r, r.listCells());
}
+ /*
+ * Custom HRegion which uses CountDownLatch to signal the completion of compaction
+ */
+ public static class CompactionCompletionNotifyingRegion extends HRegion {
+ private static volatile CountDownLatch compactionStateChangeLatch = null;
+
+ @SuppressWarnings("deprecation")
+ public CompactionCompletionNotifyingRegion(Path tableDir, HLog log,
+ FileSystem fs, Configuration confParam, HRegionInfo info,
+ HTableDescriptor htd, RegionServerServices rsServices) {
+ super(tableDir, log, fs, confParam, info, htd, rsServices);
+ }
+
+ public CountDownLatch getCompactionStateChangeLatch() {
+ if (compactionStateChangeLatch == null) compactionStateChangeLatch = new CountDownLatch(1);
+ return compactionStateChangeLatch;
+ }
+ @Override
+ public boolean compact(CompactionContext compaction, Store store) throws IOException {
+ boolean ret = super.compact(compaction, store);
+ if (ret) compactionStateChangeLatch.countDown();
+ return ret;
+ }
+ }
+
/**
* Unfortunately, the easiest way to test this is to spin up a mini-cluster since we want to do
* the usual compaction mechanism on the region, rather than going through the backdoor to the
@@ -211,6 +240,7 @@ public class TestRegionObserverScannerOp
public void testRegionObserverCompactionTimeStacking() throws Exception {
// setup a mini cluster so we can do a real compaction on a region
Configuration conf = UTIL.getConfiguration();
+ conf.setClass(HConstants.REGION_IMPL, CompactionCompletionNotifyingRegion.class, HRegion.class);
conf.setInt("hbase.hstore.compaction.min", 2);
UTIL.startMiniCluster();
String tableName = "testRegionObserverCompactionTimeStacking";
@@ -238,7 +268,9 @@ public class TestRegionObserverScannerOp
assertEquals("More than 1 region serving test table with 1 row", 1, regions.size());
HRegion region = regions.get(0);
admin.flush(region.getRegionName());
-
+ CountDownLatch latch = ((CompactionCompletionNotifyingRegion)region)
+ .getCompactionStateChangeLatch();
+
// put another row and flush that too
put = new Put(Bytes.toBytes("anotherrow"));
put.add(A, A, A);
@@ -248,7 +280,7 @@ public class TestRegionObserverScannerOp
// run a compaction, which normally would should get rid of the data
// wait for the compaction checker to complete
- Thread.sleep(1000);
+ latch.await();
// check both rows to ensure that they aren't there
Get get = new Get(ROW);
Result r = table.get(get);
@@ -265,4 +297,4 @@ public class TestRegionObserverScannerOp
table.close();
UTIL.shutdownMiniCluster();
}
-}
\ No newline at end of file
+}