From d2176177ea4c6ece5b474414b51d2d99ea43cf5b Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Tue, 17 Jan 2012 10:44:19 -0800 Subject: [PATCH] Fixing thrift tests added a tests for getregioninfo --- .../hadoop/hbase/thrift/TestThriftServer.java | 72 +++++++++++++++----- 1 files changed, 55 insertions(+), 17 deletions(-) diff --git src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java index 12247d0..4b15cd3 100644 --- src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java +++ src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java @@ -26,12 +26,15 @@ import java.util.ArrayList; import java.util.List; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.thrift.generated.BatchMutation; import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor; import org.apache.hadoop.hbase.thrift.generated.Hbase; import org.apache.hadoop.hbase.thrift.generated.Mutation; import org.apache.hadoop.hbase.thrift.generated.TCell; +import org.apache.hadoop.hbase.thrift.generated.TRegionInfo; import org.apache.hadoop.hbase.thrift.generated.TRowResult; import org.apache.hadoop.hbase.util.Bytes; import org.junit.AfterClass; @@ -75,23 +78,6 @@ public class TestThriftServer { } /** - * Runs all of the tests under a single JUnit test method. We - * consolidate all testing to one method because HBaseClusterTestCase - * is prone to OutOfMemoryExceptions when there are three or more - * JUnit test methods. - * - * @throws Exception - */ - public void testAll() throws Exception { - // Run all tests - doTestTableCreateDrop(); - doTestTableMutations(); - doTestTableTimestampsAndColumns(); - doTestTableScanners(); - doTestGetTableRegions(); - } - - /** * Tests for creating, enabling, disabling, and deleting tables. Also * tests that creating a table with an invalid column name yields an * IllegalArgument exception. @@ -138,6 +124,7 @@ public class TestThriftServer { * * @throws Exception */ + @Test public void doTestTableMutations() throws Exception { // Setup ThriftServer.HBaseHandler handler = @@ -211,6 +198,7 @@ public class TestThriftServer { * * @throws Exception */ + @Test public void doTestTableTimestampsAndColumns() throws Exception { // Setup ThriftServer.HBaseHandler handler = @@ -290,6 +278,7 @@ public class TestThriftServer { * * @throws Exception */ + @Test public void doTestTableScanners() throws Exception { // Setup ThriftServer.HBaseHandler handler = @@ -359,6 +348,7 @@ public class TestThriftServer { * * @throws Exception */ + @Test public void doTestGetTableRegions() throws Exception { ThriftServer.HBaseHandler handler = new ThriftServer.HBaseHandler(UTIL.getConfiguration()); @@ -461,6 +451,54 @@ public class TestThriftServer { handler.scannerClose(scannerId); } + + /** + * Tests for getting the region associated with a table/row. + * + * @throws Exception + */ + @Test + public void doTestGetRegionInfo() throws Exception { + ThriftServer.HBaseHandler handler = + new ThriftServer.HBaseHandler(UTIL.getConfiguration()); + + createTestTables(handler); + + ByteBuffer searchRow; + byte[] startRow; + byte[] tableName; + TRegionInfo regionInfo; + + startRow = HTableDescriptor.getStartRow(tableAname.array(), + "".getBytes()); + searchRow = ByteBuffer.wrap(startRow); + regionInfo = handler.getRegionInfo(searchRow); + tableName = HRegionInfo.parseRegionName(regionInfo.getName())[0]; + assertArrayEquals(tableAname.array(), tableName); + + startRow = HTableDescriptor.getStartRow(tableAname.array(), + "zzzzz".getBytes()); + searchRow = ByteBuffer.wrap(startRow); + regionInfo = handler.getRegionInfo(searchRow); + tableName = HRegionInfo.parseRegionName(regionInfo.getName())[0]; + assertArrayEquals(tableAname.array(), tableName); + + startRow = HTableDescriptor.getStartRow(tableBname.array(), + "".getBytes()); + searchRow = ByteBuffer.wrap(startRow); + regionInfo = handler.getRegionInfo(searchRow); + tableName = HRegionInfo.parseRegionName(regionInfo.getName())[0]; + assertArrayEquals(tableBname.array(), tableName); + + startRow = HTableDescriptor.getStartRow(tableBname.array(), + "zzzzz".getBytes()); + searchRow = ByteBuffer.wrap(startRow); + regionInfo = handler.getRegionInfo(searchRow); + tableName = HRegionInfo.parseRegionName(regionInfo.getName())[0]; + assertArrayEquals(tableBname.array(), tableName); + dropTestTables(handler); + } + @org.junit.Rule public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = new org.apache.hadoop.hbase.ResourceCheckerJUnitRule(); -- 1.7.4.4