diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java index 5e6007d..1188c43 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java @@ -21,11 +21,11 @@ package org.apache.hadoop.hbase.regionserver; import com.google.common.base.Joiner; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.CategoryBasedTimeout; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; @@ -48,7 +48,17 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdge; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.wal.WALFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; +import org.junit.rules.TestRule; import java.io.IOException; import java.lang.management.ManagementFactory; @@ -61,8 +71,11 @@ import java.util.concurrent.atomic.AtomicReference; /** memstore test case */ @Category({RegionServerTests.class, MediumTests.class}) -public class TestDefaultMemStore extends TestCase { +public class TestDefaultMemStore { private static final Log LOG = LogFactory.getLog(TestDefaultMemStore.class); + @Rule public TestName name = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); private DefaultMemStore memstore; private static final int ROW_COUNT = 10; private static final int QUALIFIER_COUNT = ROW_COUNT; @@ -70,9 +83,12 @@ public class TestDefaultMemStore extends TestCase { private MultiVersionConcurrencyControl mvcc; private AtomicLong startSeqNum = new AtomicLong(0); - @Override + private String getName() { + return this.name.getMethodName(); + } + + @Before public void setUp() throws Exception { - super.setUp(); this.mvcc = new MultiVersionConcurrencyControl(); this.memstore = new DefaultMemStore(); } @@ -387,7 +403,6 @@ public class TestDefaultMemStore extends TestCase { final MultiVersionConcurrencyControl mvcc; final MemStore memstore; - final AtomicLong startSeqNum; AtomicReference caughtException; @@ -402,7 +417,6 @@ public class TestDefaultMemStore extends TestCase { this.memstore = memstore; this.caughtException = caughtException; row = Bytes.toBytes(id); - this.startSeqNum = startSeqNum; } public void run() { @@ -438,6 +452,7 @@ public class TestDefaultMemStore extends TestCase { } } + @Test public void testReadOwnWritesUnderConcurrency() throws Throwable { int NUM_THREADS = 8; @@ -463,6 +478,7 @@ public class TestDefaultMemStore extends TestCase { * Test memstore snapshots * @throws IOException */ + @Test public void testSnapshotting() throws IOException { final int snapshotCount = 5; // Add some rows, run a snapshot. Do it a few times. @@ -473,6 +489,7 @@ public class TestDefaultMemStore extends TestCase { } } + @Test public void testMultipleVersionsSimple() throws Exception { DefaultMemStore m = new DefaultMemStore(new Configuration(), CellComparator.COMPARATOR); byte [] row = Bytes.toBytes("testRow"); @@ -500,6 +517,7 @@ public class TestDefaultMemStore extends TestCase { /** Test getNextRow from memstore * @throws InterruptedException */ + @Test public void testGetNextRow() throws Exception { addRows(this.memstore); // Add more versions to make it a little more interesting. @@ -522,31 +540,33 @@ public class TestDefaultMemStore extends TestCase { Configuration conf = HBaseConfiguration.create(); for (int startRowId = 0; startRowId < ROW_COUNT; startRowId++) { ScanInfo scanInfo = new ScanInfo(conf, FAMILY, 0, 1, Integer.MAX_VALUE, - KeepDeletedCells.FALSE, 0, this.memstore.getComparator()); + KeepDeletedCells.FALSE, 0, this.memstore.getComparator()); ScanType scanType = ScanType.USER_SCAN; - InternalScanner scanner = new StoreScanner(new Scan( + try (InternalScanner scanner = new StoreScanner(new Scan( Bytes.toBytes(startRowId)), scanInfo, scanType, null, - memstore.getScanners(0)); - List results = new ArrayList(); - for (int i = 0; scanner.next(results); i++) { - int rowId = startRowId + i; - Cell left = results.get(0); - byte[] row1 = Bytes.toBytes(rowId); - assertTrue( - "Row name", - CellComparator.COMPARATOR.compareRows(left, row1, 0, row1.length) == 0); - assertEquals("Count of columns", QUALIFIER_COUNT, results.size()); - List row = new ArrayList(); - for (Cell kv : results) { - row.add(kv); + memstore.getScanners(0))) { + List results = new ArrayList(); + for (int i = 0; scanner.next(results); i++) { + int rowId = startRowId + i; + Cell left = results.get(0); + byte[] row1 = Bytes.toBytes(rowId); + assertTrue( + "Row name", + CellComparator.COMPARATOR.compareRows(left, row1, 0, row1.length) == 0); + assertEquals("Count of columns", QUALIFIER_COUNT, results.size()); + List row = new ArrayList(); + for (Cell kv : results) { + row.add(kv); + } + isExpectedRowWithoutTimestamps(rowId, row); + // Clear out set. Otherwise row results accumulate. + results.clear(); } - isExpectedRowWithoutTimestamps(rowId, row); - // Clear out set. Otherwise row results accumulate. - results.clear(); } } } + @Test public void testGet_memstoreAndSnapShot() throws IOException { byte [] row = Bytes.toBytes("testrow"); byte [] fam = Bytes.toBytes("testfamily"); @@ -574,6 +594,7 @@ public class TestDefaultMemStore extends TestCase { ////////////////////////////////////////////////////////////////////////////// // Delete tests ////////////////////////////////////////////////////////////////////////////// + @Test public void testGetWithDelete() throws IOException { byte [] row = Bytes.toBytes("testrow"); byte [] fam = Bytes.toBytes("testfamily"); @@ -608,6 +629,7 @@ public class TestDefaultMemStore extends TestCase { } } + @Test public void testGetWithDeleteColumn() throws IOException { byte [] row = Bytes.toBytes("testrow"); byte [] fam = Bytes.toBytes("testfamily"); @@ -644,7 +666,7 @@ public class TestDefaultMemStore extends TestCase { } } - + @Test public void testGetWithDeleteFamily() throws IOException { byte [] row = Bytes.toBytes("testrow"); byte [] fam = Bytes.toBytes("testfamily"); @@ -684,6 +706,7 @@ public class TestDefaultMemStore extends TestCase { } } + @Test public void testKeepDeleteInmemstore() { byte [] row = Bytes.toBytes("testrow"); byte [] fam = Bytes.toBytes("testfamily"); @@ -697,6 +720,7 @@ public class TestDefaultMemStore extends TestCase { assertEquals(delete, memstore.getActive().first()); } + @Test public void testRetainsDeleteVersion() throws IOException { // add a put to memstore memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care")); @@ -709,6 +733,8 @@ public class TestDefaultMemStore extends TestCase { assertEquals(2, memstore.getActive().getCellsCount()); assertEquals(delete, memstore.getActive().first()); } + + @Test public void testRetainsDeleteColumn() throws IOException { // add a put to memstore memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care")); @@ -721,6 +747,8 @@ public class TestDefaultMemStore extends TestCase { assertEquals(2, memstore.getActive().getCellsCount()); assertEquals(delete, memstore.getActive().first()); } + + @Test public void testRetainsDeleteFamily() throws IOException { // add a put to memstore memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care")); @@ -751,6 +779,7 @@ public class TestDefaultMemStore extends TestCase { * This causes OOME pretty quickly if we use MSLAB for upsert * since each 2M chunk is held onto by a single reference. */ + @Test public void testUpsertMSLAB() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setBoolean(SegmentFactory.USEMSLAB_KEY, true); @@ -793,6 +822,7 @@ public class TestDefaultMemStore extends TestCase { * as older keyvalues are deleted from the memstore. * @throws Exception */ + @Test public void testUpsertMemstoreSize() throws Exception { Configuration conf = HBaseConfiguration.create(); memstore = new DefaultMemStore(conf, CellComparator.COMPARATOR); @@ -832,6 +862,7 @@ public class TestDefaultMemStore extends TestCase { * various edit operations in memstore. * @throws Exception */ + @Test public void testUpdateToTimeOfOldestEdit() throws Exception { try { EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest(); @@ -874,6 +905,7 @@ public class TestDefaultMemStore extends TestCase { * false. * @throws Exception */ + @Test public void testShouldFlush() throws Exception { Configuration conf = new Configuration(); conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 1000); @@ -906,6 +938,7 @@ public class TestDefaultMemStore extends TestCase { } } + @Test public void testShouldFlushMeta() throws Exception { // write an edit in the META and ensure the shouldFlush (that the periodic memstore // flusher invokes) returns true after SYSTEM_CACHE_FLUSH_INTERVAL (even though @@ -1023,7 +1056,6 @@ public class TestDefaultMemStore extends TestCase { } } - static void doScan(MemStore ms, int iteration) throws IOException { long nanos = System.nanoTime(); KeyValueScanner s = ms.getScanners(0).get(0); @@ -1050,5 +1082,4 @@ public class TestDefaultMemStore extends TestCase { for (int i = 0 ; i < 50 ; i++) doScan(ms, i); } -} - +} \ No newline at end of file