Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B5DDF10A6E for ; Thu, 3 Oct 2013 19:47:48 +0000 (UTC) Received: (qmail 12681 invoked by uid 500); 3 Oct 2013 19:47:47 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 12649 invoked by uid 500); 3 Oct 2013 19:47:46 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 12638 invoked by uid 99); 3 Oct 2013 19:47:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Oct 2013 19:47:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Oct 2013 19:47:33 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8D5112388AC8; Thu, 3 Oct 2013 19:47:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1528985 [2/3] - in /hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase: ./ io/hfile/ master/handler/ regionserver/ security/access/ Date: Thu, 03 Oct 2013 19:47:09 -0000 To: commits@hbase.apache.org From: jmhsieh@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131003194710.8D5112388AC8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java?rev=1528985&r1=1528984&r2=1528985&view=diff ============================================================================== --- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java (original) +++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java Thu Oct 3 19:47:09 2013 @@ -18,6 +18,21 @@ */ package org.apache.hadoop.hbase.regionserver; + +import static org.apache.hadoop.hbase.HBaseTestingUtility.COLUMNS; +import static org.apache.hadoop.hbase.HBaseTestingUtility.FIRST_CHAR; +import static org.apache.hadoop.hbase.HBaseTestingUtility.LAST_CHAR; +import static org.apache.hadoop.hbase.HBaseTestingUtility.START_KEY; +import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1; +import static org.apache.hadoop.hbase.HBaseTestingUtility.fam2; +import static org.apache.hadoop.hbase.HBaseTestingUtility.fam3; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; @@ -51,7 +66,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CompatibilitySingletonFactory; -import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestCase; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; @@ -109,70 +123,81 @@ import org.apache.hadoop.hbase.util.FSUt import org.apache.hadoop.hbase.util.IncrementingEnvironmentEdge; import org.apache.hadoop.hbase.util.PairOfSameType; import org.apache.hadoop.hbase.util.Threads; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; import org.mockito.Mockito; import com.google.common.collect.Lists; /** * Basic stand-alone testing of HRegion. - * - * A lot of the meta information for an HRegion now lives inside other - * HRegions or in the HBaseMaster, so only basic testing is possible. + * + * A lot of the meta information for an HRegion now lives inside other HRegions + * or in the HBaseMaster, so only basic testing is possible. */ @Category(MediumTests.class) @SuppressWarnings("deprecation") -public class TestHRegion extends HBaseTestCase { - // Do not spin up clusters in here. If you need to spin up a cluster, do it +public class TestHRegion { + // Do not spin up clusters in here. If you need to spin up a cluster, do it // over in TestHRegionOnCluster. static final Log LOG = LogFactory.getLog(TestHRegion.class); + @Rule public TestName name = new TestName(); private static final String COLUMN_FAMILY = "MyCF"; HRegion region = null; - private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - private static final String DIR = TEST_UTIL.getDataTestDir("TestHRegion").toString(); - + private static HBaseTestingUtility TEST_UTIL; // do not run unit tests in parallel + public static Configuration conf ; + private String DIR; + private static FileSystem fs; private final int MAX_VERSIONS = 2; // Test names - protected final byte[] tableName = Bytes.toBytes("testtable");; + protected byte[] tableName; + protected String method; protected final byte[] qual1 = Bytes.toBytes("qual1"); protected final byte[] qual2 = Bytes.toBytes("qual2"); protected final byte[] qual3 = Bytes.toBytes("qual3"); protected final byte[] value1 = Bytes.toBytes("value1"); protected final byte[] value2 = Bytes.toBytes("value2"); - protected final byte [] row = Bytes.toBytes("rowA"); - protected final byte [] row2 = Bytes.toBytes("rowB"); + protected final byte[] row = Bytes.toBytes("rowA"); + protected final byte[] row2 = Bytes.toBytes("rowB"); - protected final MetricsAssertHelper metricsAssertHelper = - CompatibilitySingletonFactory.getInstance(MetricsAssertHelper.class); + protected final MetricsAssertHelper metricsAssertHelper = CompatibilitySingletonFactory + .getInstance(MetricsAssertHelper.class); - /** - * @see org.apache.hadoop.hbase.HBaseTestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setup() throws IOException { + this.TEST_UTIL = HBaseTestingUtility.createLocalHTU(); + this.fs = TEST_UTIL.getTestFileSystem(); + this.conf = TEST_UTIL.getConfiguration(); + this.DIR = TEST_UTIL.getDataTestDir("TestHRegion").toString(); + method = name.getMethodName(); + tableName = Bytes.toBytes(name.getMethodName()); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { EnvironmentEdgeManagerTestHelper.reset(); } - ////////////////////////////////////////////////////////////////////////////// + String getName() { + return name.getMethodName(); + } + + // //////////////////////////////////////////////////////////////////////////// // New tests that doesn't spin up a mini cluster but rather just test the // individual code pieces in the HRegion. Putting files locally in // /tmp/testtable - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// + @Test public void testCompactionAffectedByScanners() throws Exception { - String method = "testCompactionAffectedByScanners"; - byte[] tableName = Bytes.toBytes(method); byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); @@ -181,7 +206,6 @@ public class TestHRegion extends HBaseTe region.put(put); region.flushcache(); - Scan scan = new Scan(); scan.setMaxVersions(3); // open the first scanner @@ -221,9 +245,7 @@ public class TestHRegion extends HBaseTe } @Test - public void testToShowNPEOnRegionScannerReseek() throws Exception{ - String method = "testToShowNPEOnRegionScannerReseek"; - byte[] tableName = Bytes.toBytes(method); + public void testToShowNPEOnRegionScannerReseek() throws Exception { byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); @@ -235,7 +257,6 @@ public class TestHRegion extends HBaseTe region.put(put); region.flushcache(); - Scan scan = new Scan(); scan.setMaxVersions(3); // open the first scanner @@ -253,10 +274,10 @@ public class TestHRegion extends HBaseTe scanner1.close(); } + @Test public void testSkipRecoveredEditsReplay() throws Exception { String method = "testSkipRecoveredEditsReplay"; - TableName tableName = - TableName.valueOf(method); + TableName tableName = TableName.valueOf(method); byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); try { @@ -276,16 +297,15 @@ public class TestHRegion extends HBaseTe long time = System.nanoTime(); WALEdit edit = new WALEdit(); - edit.add(new KeyValue(row, family, Bytes.toBytes(i), - time, KeyValue.Type.Put, Bytes.toBytes(i))); - writer.append(new HLog.Entry(new HLogKey(regionName, tableName, - i, time, HConstants.DEFAULT_CLUSTER_ID), edit)); + edit.add(new KeyValue(row, family, Bytes.toBytes(i), time, KeyValue.Type.Put, Bytes + .toBytes(i))); + writer.append(new HLog.Entry(new HLogKey(regionName, tableName, i, time, + HConstants.DEFAULT_CLUSTER_ID), edit)); writer.close(); } MonitoredTask status = TaskMonitor.get().createStatus(method); - Map maxSeqIdInStores = new TreeMap( - Bytes.BYTES_COMPARATOR); + Map maxSeqIdInStores = new TreeMap(Bytes.BYTES_COMPARATOR); for (Store store : region.getStores().values()) { maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), minSeqId - 1); } @@ -296,7 +316,7 @@ public class TestHRegion extends HBaseTe for (long i = minSeqId; i <= maxSeqId; i += 10) { List kvs = result.getColumnCells(family, Bytes.toBytes(i)); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); + assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); } } finally { HRegion.closeHRegion(this.region); @@ -304,10 +324,10 @@ public class TestHRegion extends HBaseTe } } + @Test public void testSkipRecoveredEditsReplaySomeIgnored() throws Exception { String method = "testSkipRecoveredEditsReplaySomeIgnored"; - TableName tableName = - TableName.valueOf(method); + TableName tableName = TableName.valueOf(method); byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); try { @@ -327,20 +347,18 @@ public class TestHRegion extends HBaseTe long time = System.nanoTime(); WALEdit edit = new WALEdit(); - edit.add(new KeyValue(row, family, Bytes.toBytes(i), - time, KeyValue.Type.Put, Bytes.toBytes(i))); - writer.append(new HLog.Entry(new HLogKey(regionName, tableName, - i, time, HConstants.DEFAULT_CLUSTER_ID), edit)); + edit.add(new KeyValue(row, family, Bytes.toBytes(i), time, KeyValue.Type.Put, Bytes + .toBytes(i))); + writer.append(new HLog.Entry(new HLogKey(regionName, tableName, i, time, + HConstants.DEFAULT_CLUSTER_ID), edit)); writer.close(); } long recoverSeqId = 1030; MonitoredTask status = TaskMonitor.get().createStatus(method); - Map maxSeqIdInStores = new TreeMap( - Bytes.BYTES_COMPARATOR); + Map maxSeqIdInStores = new TreeMap(Bytes.BYTES_COMPARATOR); for (Store store : region.getStores().values()) { - maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), - recoverSeqId - 1); + maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), recoverSeqId - 1); } long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, status); assertEquals(maxSeqId, seqId); @@ -352,7 +370,7 @@ public class TestHRegion extends HBaseTe assertEquals(0, kvs.size()); } else { assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); + assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); } } } finally { @@ -361,9 +379,8 @@ public class TestHRegion extends HBaseTe } } + @Test public void testSkipRecoveredEditsReplayAllIgnored() throws Exception { - String method = "testSkipRecoveredEditsReplayAllIgnored"; - byte[] tableName = Bytes.toBytes(method); byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); try { @@ -373,23 +390,20 @@ public class TestHRegion extends HBaseTe Path recoveredEditsDir = HLogUtil.getRegionDirRecoveredEditsDir(regiondir); for (int i = 1000; i < 1050; i += 10) { Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", i)); - FSDataOutputStream dos= fs.create(recoveredEdits); + FSDataOutputStream dos = fs.create(recoveredEdits); dos.writeInt(i); dos.close(); } long minSeqId = 2000; - Path recoveredEdits = new Path( - recoveredEditsDir, String.format("%019d", minSeqId-1)); - FSDataOutputStream dos= fs.create(recoveredEdits); + Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", minSeqId - 1)); + FSDataOutputStream dos = fs.create(recoveredEdits); dos.close(); - Map maxSeqIdInStores = new TreeMap( - Bytes.BYTES_COMPARATOR); + Map maxSeqIdInStores = new TreeMap(Bytes.BYTES_COMPARATOR); for (Store store : region.getStores().values()) { maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), minSeqId); } - long seqId = region.replayRecoveredEditsIfAny(regiondir, - maxSeqIdInStores, null, null); + long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null); assertEquals(minSeqId, seqId); } finally { HRegion.closeHRegion(this.region); @@ -399,9 +413,8 @@ public class TestHRegion extends HBaseTe @Test public void testRecoveredEditsReplayCompaction() throws Exception { - String method = "testRecoveredEditsReplayCompaction"; - TableName tableName = - TableName.valueOf(method); + String method = name.getMethodName(); + TableName tableName = TableName.valueOf(method); byte[] family = Bytes.toBytes("family"); this.region = initHRegion(tableName, method, conf, family); try { @@ -419,34 +432,34 @@ public class TestHRegion extends HBaseTe region.flushcache(); } - //this will create a region with 3 files + // this will create a region with 3 files assertEquals(3, region.getStore(family).getStorefilesCount()); List storeFiles = new ArrayList(3); for (StoreFile sf : region.getStore(family).getStorefiles()) { storeFiles.add(sf.getPath()); } - //disable compaction completion - conf.setBoolean("hbase.hstore.compaction.complete",false); + // disable compaction completion + conf.setBoolean("hbase.hstore.compaction.complete", false); region.compactStores(); - //ensure that nothing changed + // ensure that nothing changed assertEquals(3, region.getStore(family).getStorefilesCount()); - //now find the compacted file, and manually add it to the recovered edits + // now find the compacted file, and manually add it to the recovered edits Path tmpDir = region.getRegionFileSystem().getTempDir(); FileStatus[] files = FSUtils.listStatus(fs, tmpDir); - String errorMsg = "Expected to find 1 file in the region temp directory " + - "from the compaction, could not find any"; + String errorMsg = "Expected to find 1 file in the region temp directory " + + "from the compaction, could not find any"; assertNotNull(errorMsg, files); assertEquals(errorMsg, 1, files.length); - //move the file inside region dir - Path newFile = region.getRegionFileSystem().commitStoreFile(Bytes.toString(family), files[0].getPath()); - - CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor( - this.region.getRegionInfo(), family, - storeFiles, Lists.newArrayList(newFile), - region.getRegionFileSystem().getStoreDir(Bytes.toString(family))); + // move the file inside region dir + Path newFile = region.getRegionFileSystem().commitStoreFile(Bytes.toString(family), + files[0].getPath()); + + CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(this.region + .getRegionInfo(), family, storeFiles, Lists.newArrayList(newFile), region + .getRegionFileSystem().getStoreDir(Bytes.toString(family))); HLogUtil.writeCompactionMarker(region.getLog(), this.region.getTableDesc(), this.region.getRegionInfo(), compactionDescriptor); @@ -459,31 +472,30 @@ public class TestHRegion extends HBaseTe long time = System.nanoTime(); - writer.append(new HLog.Entry(new HLogKey(regionName, tableName, 10, time, HConstants.DEFAULT_CLUSTER_ID), - WALEdit.createCompaction(compactionDescriptor))); + writer.append(new HLog.Entry(new HLogKey(regionName, tableName, 10, time, + HConstants.DEFAULT_CLUSTER_ID), WALEdit.createCompaction(compactionDescriptor))); writer.close(); - //close the region now, and reopen again + // close the region now, and reopen again HTableDescriptor htd = region.getTableDesc(); HRegionInfo info = region.getRegionInfo(); region.close(); - region = HRegion.openHRegion(conf, fs, new Path(DIR+method),info, htd, null); + region = HRegion.openHRegion(region, null); - //now check whether we have only one store file, the compacted one + // now check whether we have only one store file, the compacted one Collection sfs = region.getStore(family).getStorefiles(); for (StoreFile sf : sfs) { LOG.info(sf.getPath()); } assertEquals(1, region.getStore(family).getStorefilesCount()); files = FSUtils.listStatus(fs, tmpDir); - assertTrue("Expected to find 0 files inside " + tmpDir, - files == null || files.length == 0); + assertTrue("Expected to find 0 files inside " + tmpDir, files == null || files.length == 0); for (long i = minSeqId; i < maxSeqId; i++) { Get get = new Get(Bytes.toBytes(i)); Result result = region.get(get); byte[] value = result.getValue(family, Bytes.toBytes(i)); - assertEquals(Bytes.toBytes(i), value); + assertArrayEquals(Bytes.toBytes(i), value); } } finally { HRegion.closeHRegion(this.region); @@ -491,13 +503,15 @@ public class TestHRegion extends HBaseTe } } + @Test public void testGetWhileRegionClose() throws IOException { + TableName tableName = TableName.valueOf(name.getMethodName()); Configuration hc = initSplit(); int numRows = 100; - byte [][] families = {fam1, fam2, fam3}; + byte[][] families = { fam1, fam2, fam3 }; - //Setting up region - String method = this.getName(); + // Setting up region + String method = name.getMethodName(); this.region = initHRegion(tableName, method, hc, families); try { // Put data in region @@ -505,15 +519,13 @@ public class TestHRegion extends HBaseTe putData(startRow, numRows, qual1, families); putData(startRow, numRows, qual2, families); putData(startRow, numRows, qual3, families); - // this.region.flushcache(); final AtomicBoolean done = new AtomicBoolean(false); final AtomicInteger gets = new AtomicInteger(0); - GetTillDoneOrException [] threads = new GetTillDoneOrException[10]; + GetTillDoneOrException[] threads = new GetTillDoneOrException[10]; try { // Set ten threads running concurrently getting from the region. for (int i = 0; i < threads.length / 2; i++) { - threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), - done, gets); + threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets); threads[i].setDaemon(true); threads[i].start(); } @@ -521,8 +533,7 @@ public class TestHRegion extends HBaseTe // I can't make the issue happen with a call to region.close(). this.region.closing.set(true); for (int i = threads.length / 2; i < threads.length; i++) { - threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), - done, gets); + threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets); threads[i].setDaemon(true); threads[i].start(); } @@ -532,7 +543,7 @@ public class TestHRegion extends HBaseTe } } done.set(true); - for (GetTillDoneOrException t: threads) { + for (GetTillDoneOrException t : threads) { try { t.join(); } catch (InterruptedException e) { @@ -540,8 +551,7 @@ public class TestHRegion extends HBaseTe } if (t.e != null) { LOG.info("Exception=" + t.e); - assertFalse("Found a NPE in " + t.getName(), - t.e instanceof NullPointerException); + assertFalse("Found a NPE in " + t.getName(), t.e instanceof NullPointerException); } } } finally { @@ -551,7 +561,7 @@ public class TestHRegion extends HBaseTe } /* - * Thread that does get on single row until 'done' flag is flipped. If an + * Thread that does get on single row until 'done' flag is flipped. If an * exception causes us to fail, it records it. */ class GetTillDoneOrException extends Thread { @@ -560,8 +570,7 @@ public class TestHRegion extends HBaseTe private final AtomicInteger count; private Exception e; - GetTillDoneOrException(final int i, final byte[] r, final AtomicBoolean d, - final AtomicInteger c) { + GetTillDoneOrException(final int i, final byte[] r, final AtomicBoolean d, final AtomicInteger c) { super("getter." + i); this.g = new Get(r); this.done = d; @@ -583,24 +592,23 @@ public class TestHRegion extends HBaseTe } /* - * An involved filter test. Has multiple column families and deletes in mix. + * An involved filter test. Has multiple column families and deletes in mix. */ + @Test public void testWeirdCacheBehaviour() throws Exception { byte[] TABLE = Bytes.toBytes("testWeirdCacheBehaviour"); - byte[][] FAMILIES = new byte[][] { Bytes.toBytes("trans-blob"), - Bytes.toBytes("trans-type"), Bytes.toBytes("trans-date"), - Bytes.toBytes("trans-tags"), Bytes.toBytes("trans-group") }; + byte[][] FAMILIES = new byte[][] { Bytes.toBytes("trans-blob"), Bytes.toBytes("trans-type"), + Bytes.toBytes("trans-date"), Bytes.toBytes("trans-tags"), Bytes.toBytes("trans-group") }; this.region = initHRegion(TABLE, getName(), conf, FAMILIES); try { String value = "this is the value"; String value2 = "this is some other value"; - String keyPrefix1 = "prefix1"; // UUID.randomUUID().toString(); - String keyPrefix2 = "prefix2"; // UUID.randomUUID().toString(); - String keyPrefix3 = "prefix3"; // UUID.randomUUID().toString(); + String keyPrefix1 = "prefix1"; + String keyPrefix2 = "prefix2"; + String keyPrefix3 = "prefix3"; putRows(this.region, 3, value, keyPrefix1); putRows(this.region, 3, value, keyPrefix2); putRows(this.region, 3, value, keyPrefix3); - // this.region.flushCommits(); putRows(this.region, 3, value2, keyPrefix1); putRows(this.region, 3, value2, keyPrefix2); putRows(this.region, 3, value2, keyPrefix3); @@ -617,18 +625,19 @@ public class TestHRegion extends HBaseTe deleteColumns(this.region, value2, keyPrefix2); deleteColumns(this.region, value2, keyPrefix3); System.out.println("Starting important checks....."); - assertEquals("Got back incorrect number of rows from scan: " + keyPrefix1, - 0, getNumberOfRows(keyPrefix1, value2, this.region)); - assertEquals("Got back incorrect number of rows from scan: " + keyPrefix2, - 0, getNumberOfRows(keyPrefix2, value2, this.region)); - assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, - 0, getNumberOfRows(keyPrefix3, value2, this.region)); + assertEquals("Got back incorrect number of rows from scan: " + keyPrefix1, 0, + getNumberOfRows(keyPrefix1, value2, this.region)); + assertEquals("Got back incorrect number of rows from scan: " + keyPrefix2, 0, + getNumberOfRows(keyPrefix2, value2, this.region)); + assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, 0, + getNumberOfRows(keyPrefix3, value2, this.region)); } finally { HRegion.closeHRegion(this.region); this.region = null; } } + @Test public void testAppendWithReadOnlyTable() throws Exception { byte[] TABLE = Bytes.toBytes("readOnlyTable"); this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily")); @@ -648,6 +657,7 @@ public class TestHRegion extends HBaseTe assertTrue(exceptionCaught == true); } + @Test public void testIncrWithReadOnlyTable() throws Exception { byte[] TABLE = Bytes.toBytes("readOnlyTable"); this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily")); @@ -666,8 +676,7 @@ public class TestHRegion extends HBaseTe assertTrue(exceptionCaught == true); } - private void deleteColumns(HRegion r, String value, String keyPrefix) - throws IOException { + private void deleteColumns(HRegion r, String value, String keyPrefix) throws IOException { InternalScanner scanner = buildScanner(keyPrefix, value, r); int count = 0; boolean more = false; @@ -693,24 +702,25 @@ public class TestHRegion extends HBaseTe boolean more = false; do { more = resultScanner.next(results); - if (results != null && !results.isEmpty()) numberOfResults++; - else break; - for (Cell kv: results) { + if (results != null && !results.isEmpty()) + numberOfResults++; + else + break; + for (Cell kv : results) { System.out.println("kv=" + kv.toString() + ", " + Bytes.toString(CellUtil.cloneValue(kv))); } results.clear(); - } while(more); + } while (more); return numberOfResults; } private InternalScanner buildScanner(String keyPrefix, String value, HRegion r) - throws IOException { + throws IOException { // Defaults FilterList.Operator.MUST_PASS_ALL. FilterList allFilters = new FilterList(); allFilters.addFilter(new PrefixFilter(Bytes.toBytes(keyPrefix))); // Only return rows where this column value exists in the row. - SingleColumnValueFilter filter = - new SingleColumnValueFilter(Bytes.toBytes("trans-tags"), + SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("trans-tags"), Bytes.toBytes("qual2"), CompareOp.EQUAL, Bytes.toBytes(value)); filter.setFilterIfMissing(true); allFilters.addFilter(filter); @@ -724,34 +734,29 @@ public class TestHRegion extends HBaseTe return r.getScanner(scan); } - private void putRows(HRegion r, int numRows, String value, String key) - throws IOException { + private void putRows(HRegion r, int numRows, String value, String key) throws IOException { for (int i = 0; i < numRows; i++) { String row = key + "_" + i/* UUID.randomUUID().toString() */; - System.out.println(String.format("Saving row: %s, with value %s", row, - value)); + System.out.println(String.format("Saving row: %s, with value %s", row, value)); Put put = new Put(Bytes.toBytes(row)); put.setDurability(Durability.SKIP_WAL); - put.add(Bytes.toBytes("trans-blob"), null, - Bytes.toBytes("value for blob")); + put.add(Bytes.toBytes("trans-blob"), null, Bytes.toBytes("value for blob")); put.add(Bytes.toBytes("trans-type"), null, Bytes.toBytes("statement")); - put.add(Bytes.toBytes("trans-date"), null, - Bytes.toBytes("20090921010101999")); - put.add(Bytes.toBytes("trans-tags"), Bytes.toBytes("qual2"), - Bytes.toBytes(value)); - put.add(Bytes.toBytes("trans-group"), null, - Bytes.toBytes("adhocTransactionGroupId")); + put.add(Bytes.toBytes("trans-date"), null, Bytes.toBytes("20090921010101999")); + put.add(Bytes.toBytes("trans-tags"), Bytes.toBytes("qual2"), Bytes.toBytes(value)); + put.add(Bytes.toBytes("trans-group"), null, Bytes.toBytes("adhocTransactionGroupId")); r.put(put); } } + @Test public void testFamilyWithAndWithoutColon() throws Exception { - byte [] b = Bytes.toBytes(getName()); - byte [] cf = Bytes.toBytes(COLUMN_FAMILY); + byte[] b = Bytes.toBytes(getName()); + byte[] cf = Bytes.toBytes(COLUMN_FAMILY); this.region = initHRegion(b, getName(), conf, cf); try { Put p = new Put(b); - byte [] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":"); + byte[] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":"); p.add(cfwithcolon, cfwithcolon, cfwithcolon); boolean exception = false; try { @@ -761,11 +766,12 @@ public class TestHRegion extends HBaseTe } assertTrue(exception); } finally { - HRegion.closeHRegion(this.region); + HRegion.closeHRegion(this.region); this.region = null; } } + @Test public void testBatchPut() throws Exception { byte[] b = Bytes.toBytes(getName()); byte[] cf = Bytes.toBytes(COLUMN_FAMILY); @@ -787,19 +793,17 @@ public class TestHRegion extends HBaseTe OperationStatus[] codes = this.region.batchMutate(puts); assertEquals(10, codes.length); for (int i = 0; i < 10; i++) { - assertEquals(OperationStatusCode.SUCCESS, codes[i] - .getOperationStatusCode()); + assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode()); } metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source); - LOG.info("Next a batch put with one invalid family"); puts[5].add(Bytes.toBytes("BAD_CF"), qual, val); codes = this.region.batchMutate(puts); assertEquals(10, codes.length); for (int i = 0; i < 10; i++) { - assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : - OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode()); + assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS, + codes[i].getOperationStatusCode()); } metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source); @@ -807,10 +811,8 @@ public class TestHRegion extends HBaseTe LOG.info("Next a batch put that has to break into two batches to avoid a lock"); RowLock rowLock = region.getRowLock(Bytes.toBytes("row_2")); - MultithreadedTestUtil.TestContext ctx = - new MultithreadedTestUtil.TestContext(conf); - final AtomicReference retFromThread = - new AtomicReference(); + MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(conf); + final AtomicReference retFromThread = new AtomicReference(); TestThread putter = new TestThread(ctx) { @Override public void doWork() throws IOException { @@ -823,7 +825,7 @@ public class TestHRegion extends HBaseTe LOG.info("...waiting for put thread to sync first time"); long startWait = System.currentTimeMillis(); - while (metricsAssertHelper.getCounter("syncTimeNumOps", source) == syncs +2 ) { + while (metricsAssertHelper.getCounter("syncTimeNumOps", source) == syncs + 2) { Thread.sleep(100); if (System.currentTimeMillis() - startWait > 10000) { fail("Timed out waiting for thread to sync first minibatch"); @@ -837,28 +839,28 @@ public class TestHRegion extends HBaseTe metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 4, source); codes = retFromThread.get(); for (int i = 0; i < 10; i++) { - assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : - OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode()); + assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS, + codes[i].getOperationStatusCode()); } } finally { HRegion.closeHRegion(this.region); - this.region = null; + this.region = null; } } + @Test public void testBatchPutWithTsSlop() throws Exception { byte[] b = Bytes.toBytes(getName()); byte[] cf = Bytes.toBytes(COLUMN_FAMILY); byte[] qual = Bytes.toBytes("qual"); byte[] val = Bytes.toBytes("val"); - Configuration conf = HBaseConfiguration.create(this.conf); // add data with a timestamp that is too recent for range. Ensure assert conf.setInt("hbase.hregion.keyvalue.timestamp.slop.millisecs", 1000); this.region = initHRegion(b, getName(), conf, cf); - try{ + try { MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class); long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source); metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source); @@ -872,8 +874,7 @@ public class TestHRegion extends HBaseTe OperationStatus[] codes = this.region.batchMutate(puts); assertEquals(10, codes.length); for (int i = 0; i < 10; i++) { - assertEquals(OperationStatusCode.SANITY_CHECK_FAILURE, codes[i] - .getOperationStatusCode()); + assertEquals(OperationStatusCode.SANITY_CHECK_FAILURE, codes[i].getOperationStatusCode()); } metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source); @@ -884,77 +885,77 @@ public class TestHRegion extends HBaseTe } - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// // checkAndMutate tests - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// + @Test public void testCheckAndMutate_WithEmptyRowValue() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] qf1 = Bytes.toBytes("qualifier"); - byte [] emptyVal = new byte[] {}; - byte [] val1 = Bytes.toBytes("value1"); - byte [] val2 = Bytes.toBytes("value2"); + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] qf1 = Bytes.toBytes("qualifier"); + byte[] emptyVal = new byte[] {}; + byte[] val1 = Bytes.toBytes("value1"); + byte[] val2 = Bytes.toBytes("value2"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { - //Putting empty data in key + // Putting empty data in key Put put = new Put(row1); put.add(fam1, qf1, emptyVal); - //checkAndPut with empty value - boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(emptyVal), put, true); + // checkAndPut with empty value + boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator( + emptyVal), put, true); assertTrue(res); - //Putting data in key + // Putting data in key put = new Put(row1); put.add(fam1, qf1, val1); - //checkAndPut with correct value - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(emptyVal), put, true); + // checkAndPut with correct value + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal), + put, true); assertTrue(res); // not empty anymore - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(emptyVal), put, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal), + put, true); assertFalse(res); Delete delete = new Delete(row1); delete.deleteColumn(fam1, qf1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(emptyVal), delete, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal), + delete, true); assertFalse(res); put = new Put(row1); put.add(fam1, qf1, val2); - //checkAndPut with correct value - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val1), put, true); + // checkAndPut with correct value + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1), + put, true); assertTrue(res); - //checkAndDelete with correct value + // checkAndDelete with correct value delete = new Delete(row1); delete.deleteColumn(fam1, qf1); delete.deleteColumn(fam1, qf1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val2), delete, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2), + delete, true); assertTrue(res); delete = new Delete(row1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(emptyVal), delete, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal), + delete, true); assertTrue(res); - //checkAndPut looking for a null value + // checkAndPut looking for a null value put = new Put(row1); put.add(fam1, qf1, val1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new NullComparator(), put, true); + res = region + .checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new NullComparator(), put, true); assertTrue(res); } finally { HRegion.closeHRegion(this.region); @@ -962,33 +963,33 @@ public class TestHRegion extends HBaseTe } } - public void testCheckAndMutate_WithWrongValue() throws IOException{ - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] qf1 = Bytes.toBytes("qualifier"); - byte [] val1 = Bytes.toBytes("value1"); - byte [] val2 = Bytes.toBytes("value2"); + @Test + public void testCheckAndMutate_WithWrongValue() throws IOException { + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] qf1 = Bytes.toBytes("qualifier"); + byte[] val1 = Bytes.toBytes("value1"); + byte[] val2 = Bytes.toBytes("value2"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { - //Putting data in key + // Putting data in key Put put = new Put(row1); put.add(fam1, qf1, val1); region.put(put); - //checkAndPut with wrong value - boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val2), put, true); + // checkAndPut with wrong value + boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator( + val2), put, true); assertEquals(false, res); - //checkAndDelete with wrong value + // checkAndDelete with wrong value Delete delete = new Delete(row1); delete.deleteFamily(fam1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val2), delete, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2), + delete, true); assertEquals(false, res); } finally { HRegion.closeHRegion(this.region); @@ -996,32 +997,32 @@ public class TestHRegion extends HBaseTe } } - public void testCheckAndMutate_WithCorrectValue() throws IOException{ - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] qf1 = Bytes.toBytes("qualifier"); - byte [] val1 = Bytes.toBytes("value1"); + @Test + public void testCheckAndMutate_WithCorrectValue() throws IOException { + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] qf1 = Bytes.toBytes("qualifier"); + byte[] val1 = Bytes.toBytes("value1"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { - //Putting data in key + // Putting data in key Put put = new Put(row1); put.add(fam1, qf1, val1); region.put(put); - //checkAndPut with correct value - boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val1), put, true); + // checkAndPut with correct value + boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator( + val1), put, true); assertEquals(true, res); - //checkAndDelete with correct value + // checkAndDelete with correct value Delete delete = new Delete(row1); delete.deleteColumn(fam1, qf1); - res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val1), put, true); + res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1), + put, true); assertEquals(true, res); } finally { HRegion.closeHRegion(this.region); @@ -1029,49 +1030,49 @@ public class TestHRegion extends HBaseTe } } - public void testCheckAndPut_ThatPutWasWritten() throws IOException{ - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("fam2"); - byte [] qf1 = Bytes.toBytes("qualifier"); - byte [] val1 = Bytes.toBytes("value1"); - byte [] val2 = Bytes.toBytes("value2"); + @Test + public void testCheckAndPut_ThatPutWasWritten() throws IOException { + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("fam2"); + byte[] qf1 = Bytes.toBytes("qualifier"); + byte[] val1 = Bytes.toBytes("value1"); + byte[] val2 = Bytes.toBytes("value2"); - byte [][] families = {fam1, fam2}; + byte[][] families = { fam1, fam2 }; - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { - //Putting data in the key to check + // Putting data in the key to check Put put = new Put(row1); put.add(fam1, qf1, val1); region.put(put); - //Creating put to add + // Creating put to add long ts = System.currentTimeMillis(); KeyValue kv = new KeyValue(row1, fam2, qf1, ts, KeyValue.Type.Put, val2); put = new Put(row1); put.add(kv); - //checkAndPut with wrong value + // checkAndPut with wrong value HStore store = (HStore) region.getStore(fam1); store.memstore.kvset.size(); - boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, - new BinaryComparator(val1), put, true); + boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator( + val1), put, true); assertEquals(true, res); store.memstore.kvset.size(); Get get = new Get(row1); get.addColumn(fam2, qf1); - Cell [] actual = region.get(get).rawCells(); + Cell[] actual = region.get(get).rawCells(); - Cell [] expected = {kv}; + Cell[] expected = { kv }; assertEquals(expected.length, actual.length); - for(int i=0; i kvs = new ArrayList(); + List kvs = new ArrayList(); kvs.add(new KeyValue(row1, fam4, null, null)); - - //testing existing family - byte [] family = fam2; + // testing existing family + byte[] family = fam2; try { - NavigableMap> deleteMap = - new TreeMap>(Bytes.BYTES_COMPARATOR); + NavigableMap> deleteMap = new TreeMap>( + Bytes.BYTES_COMPARATOR); deleteMap.put(family, kvs); region.delete(deleteMap, Durability.SYNC_WAL); } catch (Exception e) { - assertTrue("Family " +new String(family)+ " does not exist", false); + assertTrue("Family " + new String(family) + " does not exist", false); } - //testing non existing family + // testing non existing family boolean ok = false; family = fam4; try { - NavigableMap> deleteMap = - new TreeMap>(Bytes.BYTES_COMPARATOR); + NavigableMap> deleteMap = new TreeMap>( + Bytes.BYTES_COMPARATOR); deleteMap.put(family, kvs); region.delete(deleteMap, Durability.SYNC_WAL); } catch (Exception e) { ok = true; } - assertEquals("Family " +new String(family)+ " does exist", true, ok); + assertEquals("Family " + new String(family) + " does exist", true, ok); } finally { HRegion.closeHRegion(this.region); this.region = null; } } + @Test public void testDelete_mixed() throws IOException, InterruptedException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] fam = Bytes.toBytes("info"); - byte [][] families = {fam}; + byte[] fam = Bytes.toBytes("info"); + byte[][] families = { fam }; String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge()); - byte [] row = Bytes.toBytes("table_name"); + byte[] row = Bytes.toBytes("table_name"); // column names - byte [] serverinfo = Bytes.toBytes("serverinfo"); - byte [] splitA = Bytes.toBytes("splitA"); - byte [] splitB = Bytes.toBytes("splitB"); + byte[] serverinfo = Bytes.toBytes("serverinfo"); + byte[] splitA = Bytes.toBytes("splitA"); + byte[] splitB = Bytes.toBytes("splitB"); // add some data: Put put = new Put(row); @@ -1323,20 +1325,20 @@ public class TestHRegion extends HBaseTe } } + @Test public void testDeleteRowWithFutureTs() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] fam = Bytes.toBytes("info"); - byte [][] families = {fam}; + byte[] fam = Bytes.toBytes("info"); + byte[][] families = { fam }; String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { - byte [] row = Bytes.toBytes("table_name"); + byte[] row = Bytes.toBytes("table_name"); // column names - byte [] serverinfo = Bytes.toBytes("serverinfo"); + byte[] serverinfo = Bytes.toBytes("serverinfo"); // add data in the far future Put put = new Put(row); - put.add(fam, serverinfo, HConstants.LATEST_TIMESTAMP-5,Bytes.toBytes("value")); + put.add(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value")); region.put(put); // now delete something in the present @@ -1349,7 +1351,7 @@ public class TestHRegion extends HBaseTe assertEquals(1, result.size()); // delete the future row - delete = new Delete(row,HConstants.LATEST_TIMESTAMP-3); + delete = new Delete(row, HConstants.LATEST_TIMESTAMP - 3); region.delete(delete); // make sure it is gone @@ -1363,19 +1365,19 @@ public class TestHRegion extends HBaseTe } /** - * Tests that the special LATEST_TIMESTAMP option for puts gets - * replaced by the actual timestamp + * Tests that the special LATEST_TIMESTAMP option for puts gets replaced by + * the actual timestamp */ + @Test public void testPutWithLatestTS() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] fam = Bytes.toBytes("info"); - byte [][] families = {fam}; + byte[] fam = Bytes.toBytes("info"); + byte[][] families = { fam }; String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { - byte [] row = Bytes.toBytes("row1"); + byte[] row = Bytes.toBytes("row1"); // column names - byte [] qual = Bytes.toBytes("qual"); + byte[] qual = Bytes.toBytes("qual"); // add data with LATEST_TIMESTAMP, put without WAL Put put = new Put(row); @@ -1413,18 +1415,16 @@ public class TestHRegion extends HBaseTe } - /** * Tests that there is server-side filtering for invalid timestamp upper * bound. Note that the timestamp lower bound is automatically handled for us * by the TTL field. */ + @Test public void testPutWithTsSlop() throws IOException { - byte[] tableName = Bytes.toBytes("testtable"); byte[] fam = Bytes.toBytes("info"); byte[][] families = { fam }; String method = this.getName(); - Configuration conf = HBaseConfiguration.create(this.conf); // add data with a timestamp that is too recent for range. Ensure assert conf.setInt("hbase.hregion.keyvalue.timestamp.slop.millisecs", 1000); @@ -1433,11 +1433,9 @@ public class TestHRegion extends HBaseTe try { try { // no TS specified == use latest. should not error - region.put(new Put(row).add(fam, Bytes.toBytes("qual"), Bytes - .toBytes("value"))); + region.put(new Put(row).add(fam, Bytes.toBytes("qual"), Bytes.toBytes("value"))); // TS out of range. should error - region.put(new Put(row).add(fam, Bytes.toBytes("qual"), - System.currentTimeMillis() + 2000, + region.put(new Put(row).add(fam, Bytes.toBytes("qual"), System.currentTimeMillis() + 2000, Bytes.toBytes("value"))); fail("Expected IOE for TS out of configured timerange"); } catch (FailedSanityCheckException ioe) { @@ -1451,16 +1449,16 @@ public class TestHRegion extends HBaseTe } } + @Test public void testScanner_DeleteOneFamilyNotAnother() throws IOException { - byte [] tableName = Bytes.toBytes("test_table"); - byte [] fam1 = Bytes.toBytes("columnA"); - byte [] fam2 = Bytes.toBytes("columnB"); + byte[] fam1 = Bytes.toBytes("columnA"); + byte[] fam2 = Bytes.toBytes("columnB"); this.region = initHRegion(tableName, getName(), conf, fam1, fam2); try { - byte [] rowA = Bytes.toBytes("rowA"); - byte [] rowB = Bytes.toBytes("rowB"); + byte[] rowA = Bytes.toBytes("rowA"); + byte[] rowB = Bytes.toBytes("rowB"); - byte [] value = Bytes.toBytes("value"); + byte[] value = Bytes.toBytes("value"); Delete delete = new Delete(rowA); delete.deleteFamily(fam1); @@ -1493,21 +1491,22 @@ public class TestHRegion extends HBaseTe } } - public void testDeleteColumns_PostInsert() throws IOException, - InterruptedException { + @Test + public void testDeleteColumns_PostInsert() throws IOException, InterruptedException { Delete delete = new Delete(row); delete.deleteColumns(fam1, qual1); doTestDelete_AndPostInsert(delete); } + @Test public void testDeleteFamily_PostInsert() throws IOException, InterruptedException { Delete delete = new Delete(row); delete.deleteFamily(fam1); doTestDelete_AndPostInsert(delete); } - public void doTestDelete_AndPostInsert(Delete delete) - throws IOException, InterruptedException { + public void doTestDelete_AndPostInsert(Delete delete) throws IOException, InterruptedException { + TableName tableName = TableName.valueOf(name.getMethodName()); this.region = initHRegion(tableName, getName(), conf, fam1); try { EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge()); @@ -1518,7 +1517,6 @@ public class TestHRegion extends HBaseTe // now delete the value: region.delete(delete); - // ok put data: put = new Put(row); put.add(fam1, qual1, value2); @@ -1530,7 +1528,7 @@ public class TestHRegion extends HBaseTe Result r = region.get(get); assertEquals(1, r.size()); - assertByteEquals(value2, r.getValue(fam1, qual1)); + assertArrayEquals(value2, r.getValue(fam1, qual1)); // next: Scan scan = new Scan(row); @@ -1542,35 +1540,36 @@ public class TestHRegion extends HBaseTe assertEquals(1, results.size()); Cell kv = results.get(0); - assertByteEquals(value2, CellUtil.cloneValue(kv)); - assertByteEquals(fam1, CellUtil.cloneFamily(kv)); - assertByteEquals(qual1, CellUtil.cloneQualifier(kv)); - assertByteEquals(row, CellUtil.cloneRow(kv)); + assertArrayEquals(value2, CellUtil.cloneValue(kv)); + assertArrayEquals(fam1, CellUtil.cloneFamily(kv)); + assertArrayEquals(qual1, CellUtil.cloneQualifier(kv)); + assertArrayEquals(row, CellUtil.cloneRow(kv)); } finally { HRegion.closeHRegion(this.region); this.region = null; } } - public void testDelete_CheckTimestampUpdated() - throws IOException { - byte [] row1 = Bytes.toBytes("row1"); - byte [] col1 = Bytes.toBytes("col1"); - byte [] col2 = Bytes.toBytes("col2"); - byte [] col3 = Bytes.toBytes("col3"); + @Test + public void testDelete_CheckTimestampUpdated() throws IOException { + TableName tableName = TableName.valueOf(name.getMethodName()); + byte[] row1 = Bytes.toBytes("row1"); + byte[] col1 = Bytes.toBytes("col1"); + byte[] col2 = Bytes.toBytes("col2"); + byte[] col3 = Bytes.toBytes("col3"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { - //Building checkerList - List kvs = new ArrayList(); + // Building checkerList + List kvs = new ArrayList(); kvs.add(new KeyValue(row1, fam1, col1, null)); kvs.add(new KeyValue(row1, fam1, col2, null)); kvs.add(new KeyValue(row1, fam1, col3, null)); - NavigableMap> deleteMap = - new TreeMap>(Bytes.BYTES_COMPARATOR); + NavigableMap> deleteMap = new TreeMap>( + Bytes.BYTES_COMPARATOR); deleteMap.put(fam1, kvs); region.delete(deleteMap, Durability.SYNC_WAL); @@ -1590,24 +1589,24 @@ public class TestHRegion extends HBaseTe } } - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// // Get tests - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// + @Test public void testGet_FamilyChecker() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("False"); - byte [] col1 = Bytes.toBytes("col1"); + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("False"); + byte[] col1 = Bytes.toBytes("col1"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { Get get = new Get(row1); get.addColumn(fam2, col1); - //Test + // Test try { region.get(get); } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) { @@ -1621,21 +1620,21 @@ public class TestHRegion extends HBaseTe } } + @Test public void testGet_Basic() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] col1 = Bytes.toBytes("col1"); - byte [] col2 = Bytes.toBytes("col2"); - byte [] col3 = Bytes.toBytes("col3"); - byte [] col4 = Bytes.toBytes("col4"); - byte [] col5 = Bytes.toBytes("col5"); + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] col1 = Bytes.toBytes("col1"); + byte[] col2 = Bytes.toBytes("col2"); + byte[] col3 = Bytes.toBytes("col3"); + byte[] col4 = Bytes.toBytes("col4"); + byte[] col5 = Bytes.toBytes("col5"); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, fam1); try { - //Add to memstore + // Add to memstore Put put = new Put(row1); put.add(fam1, col1, null); put.add(fam1, col2, null); @@ -1647,15 +1646,15 @@ public class TestHRegion extends HBaseTe Get get = new Get(row1); get.addColumn(fam1, col2); get.addColumn(fam1, col4); - //Expected result + // Expected result KeyValue kv1 = new KeyValue(row1, fam1, col2); KeyValue kv2 = new KeyValue(row1, fam1, col4); - KeyValue [] expected = {kv1, kv2}; + KeyValue[] expected = { kv1, kv2 }; - //Test + // Test Result res = region.get(get); assertEquals(expected.length, res.size()); - for(int i=0; i result = null; SplitTransaction st = new SplitTransaction(parent, midkey); // If prepare does not return true, for some reason -- logged inside in - // the prepare call -- we are not ready to split just now. Just return. - if (!st.prepare()) return null; + // the prepare call -- we are not ready to split just now. Just return. + if (!st.prepare()) + return null; try { result = st.execute(null, null); } catch (IOException ioe) { try { - LOG.info("Running rollback of failed split of " + - parent.getRegionNameAsString() + "; " + ioe.getMessage()); + LOG.info("Running rollback of failed split of " + parent.getRegionNameAsString() + "; " + + ioe.getMessage()); st.rollback(null, null); - LOG.info("Successful rollback of failed split of " + - parent.getRegionNameAsString()); + LOG.info("Successful rollback of failed split of " + parent.getRegionNameAsString()); return null; } catch (RuntimeException e) { // If failed rollback, kill this server to avoid having a hole in table. - LOG.info("Failed rollback of failed split of " + - parent.getRegionNameAsString() + " -- aborting server", e); + LOG.info("Failed rollback of failed split of " + parent.getRegionNameAsString() + + " -- aborting server", e); } } - return new HRegion [] {result.getFirst(), result.getSecond()}; + return new HRegion[] { result.getFirst(), result.getSecond() }; } - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// // Scanner tests - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// + @Test public void testGetScanner_WithOkFamilies() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("fam2"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("fam2"); - byte [][] families = {fam1, fam2}; + byte[][] families = { fam1, fam2 }; - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { @@ -1802,14 +1802,14 @@ public class TestHRegion extends HBaseTe } } + @Test public void testGetScanner_WithNotOkFamilies() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("fam2"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("fam2"); - byte [][] families = {fam1}; + byte[][] families = { fam1 }; - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { @@ -1828,22 +1828,22 @@ public class TestHRegion extends HBaseTe } } + @Test public void testGetScanner_WithNoFamilies() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("fam2"); - byte [] fam3 = Bytes.toBytes("fam3"); - byte [] fam4 = Bytes.toBytes("fam4"); + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("fam2"); + byte[] fam3 = Bytes.toBytes("fam3"); + byte[] fam4 = Bytes.toBytes("fam4"); - byte [][] families = {fam1, fam2, fam3, fam4}; + byte[][] families = { fam1, fam2, fam3, fam4 }; - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { - //Putting data in Region + // Putting data in Region Put put = new Put(row1); put.add(fam1, null, null); put.add(fam2, null, null); @@ -1854,20 +1854,20 @@ public class TestHRegion extends HBaseTe Scan scan = null; HRegion.RegionScannerImpl is = null; - //Testing to see how many scanners that is produced by getScanner, starting - //with known number, 2 - current = 1 + // Testing to see how many scanners that is produced by getScanner, + // starting + // with known number, 2 - current = 1 scan = new Scan(); scan.addFamily(fam2); scan.addFamily(fam4); is = (RegionScannerImpl) region.getScanner(scan); MultiVersionConsistencyControl.resetThreadReadPoint(region.getMVCC()); - assertEquals(1, ((RegionScannerImpl)is).storeHeap.getHeap().size()); + assertEquals(1, ((RegionScannerImpl) is).storeHeap.getHeap().size()); scan = new Scan(); is = (RegionScannerImpl) region.getScanner(scan); MultiVersionConsistencyControl.resetThreadReadPoint(region.getMVCC()); - assertEquals(families.length -1, - ((RegionScannerImpl)is).storeHeap.getHeap().size()); + assertEquals(families.length - 1, ((RegionScannerImpl) is).storeHeap.getHeap().size()); } finally { HRegion.closeHRegion(this.region); this.region = null; @@ -1876,16 +1876,17 @@ public class TestHRegion extends HBaseTe /** * This method tests https://issues.apache.org/jira/browse/HBASE-2516. + * * @throws IOException */ + @Test public void testGetScanner_WithRegionClosed() throws IOException { - byte[] tableName = Bytes.toBytes("testtable"); byte[] fam1 = Bytes.toBytes("fam1"); byte[] fam2 = Bytes.toBytes("fam2"); - byte[][] families = {fam1, fam2}; + byte[][] families = { fam1, fam2 }; - //Setting up region + // Setting up region String method = this.getName(); try { this.region = initHRegion(tableName, method, conf, families); @@ -1899,7 +1900,7 @@ public class TestHRegion extends HBaseTe region.getScanner(null); fail("Expected to get an exception during getScanner on a region that is closed"); } catch (NotServingRegionException e) { - //this is the correct exception that is expected + // this is the correct exception that is expected } catch (IOException e) { fail("Got wrong type of exception - should be a NotServingRegionException, but was an IOException: " + e.getMessage()); @@ -1910,23 +1911,23 @@ public class TestHRegion extends HBaseTe } } + @Test public void testRegionScanner_Next() throws IOException { - byte [] tableName = Bytes.toBytes("testtable"); - byte [] row1 = Bytes.toBytes("row1"); - byte [] row2 = Bytes.toBytes("row2"); - byte [] fam1 = Bytes.toBytes("fam1"); - byte [] fam2 = Bytes.toBytes("fam2"); - byte [] fam3 = Bytes.toBytes("fam3"); - byte [] fam4 = Bytes.toBytes("fam4"); + byte[] row1 = Bytes.toBytes("row1"); + byte[] row2 = Bytes.toBytes("row2"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] fam2 = Bytes.toBytes("fam2"); + byte[] fam3 = Bytes.toBytes("fam3"); + byte[] fam4 = Bytes.toBytes("fam4"); - byte [][] families = {fam1, fam2, fam3, fam4}; + byte[][] families = { fam1, fam2, fam3, fam4 }; long ts = System.currentTimeMillis(); - //Setting up region + // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, conf, families); try { - //Putting data in Region + // Putting data in Region Put put = null; put = new Put(row1); put.add(fam1, null, ts, null); @@ -1949,7 +1950,7 @@ public class TestHRegion extends HBaseTe List res = null; - //Result 1 + // Result 1 List expected1 = new ArrayList(); expected1.add(new KeyValue(row1, fam2, null, ts, KeyValue.Type.Put, null)); expected1.add(new KeyValue(row1, fam4, null, ts, KeyValue.Type.Put, null)); @@ -1960,14 +1961,14 @@ public class TestHRegion extends HBaseTe assertTrue(CellComparator.equalsIgnoreMvccVersion(expected1.get(i), res.get(i))); } - //Result 2 + // Result 2 List expected2 = new ArrayList(); expected2.add(new KeyValue(row2, fam2, null, ts, KeyValue.Type.Put, null)); expected2.add(new KeyValue(row2, fam4, null, ts, KeyValue.Type.Put, null)); res = new ArrayList(); is.next(res); - for(int i=0; i expected = new ArrayList(); expected.add(kv13); expected.add(kv12); @@ -2026,8 +2026,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i expected = new ArrayList(); expected.add(kv13); expected.add(kv12); @@ -2090,8 +2089,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i expected = new ArrayList(); expected.add(kv14); expected.add(kv13); @@ -2173,8 +2171,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i expected = new ArrayList(); expected.add(kv13); expected.add(kv12); @@ -2235,8 +2232,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i expected = new ArrayList(); expected.add(kv13); expected.add(kv12); @@ -2297,8 +2293,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i expected = new ArrayList(); expected.add(kv14); expected.add(kv13); @@ -2456,8 +2448,8 @@ public class TestHRegion extends HBaseTe boolean hasNext = scanner.next(actual); assertEquals(false, hasNext); - //Verify result - for(int i=0; i