|
| 1 | +package org.apache.hadoop.hbase.client; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import org.apache.commons.logging.Log; |
| 5 | +import org.apache.commons.logging.LogFactory; |
| 6 | +import org.apache.hadoop.hbase.HBaseTestingUtility; |
| 7 | +import org.apache.hadoop.hbase.HColumnDescriptor; |
| 8 | +import org.apache.hadoop.hbase.HConstants; |
| 9 | +import org.apache.hadoop.hbase.HRegionInfo; |
| 10 | +import org.apache.hadoop.hbase.HTableDescriptor; |
| 11 | +import org.apache.hadoop.hbase.TableName; |
| 12 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 13 | +import org.apache.hadoop.hbase.util.Bytes; |
| 14 | +import org.junit.After; |
| 15 | +import org.junit.BeforeClass; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.experimental.categories.Category; |
| 18 | + |
| 19 | +@Category(MediumTests.class) |
| 20 | +public class TestLookupRegionMetaFamilyFilter { |
| 21 | + private static final Log LOG = LogFactory.getLog(TestLookupRegionMetaFamilyFilter.class); |
| 22 | + |
| 23 | + private static String EXTRA_CF = "test"; |
| 24 | + private static byte[] EXTRA_CF_BYTES = Bytes.toBytes(EXTRA_CF); |
| 25 | + |
| 26 | + private static TableName TABLE = TableName.valueOf("foo"); |
| 27 | + private static HBaseTestingUtility TEST_UTIL; |
| 28 | + |
| 29 | + @BeforeClass |
| 30 | + public static void beforeClass() throws Exception { |
| 31 | + if (TEST_UTIL != null) { |
| 32 | + // We reached end of a parameterized run, clean up. |
| 33 | + TEST_UTIL.shutdownMiniCluster(); |
| 34 | + } |
| 35 | + TEST_UTIL = new HBaseTestingUtility(); |
| 36 | + TEST_UTIL.startMiniCluster(1); |
| 37 | + } |
| 38 | + |
| 39 | + @After |
| 40 | + public void tearDown() throws Exception { |
| 41 | + TEST_UTIL.shutdownMiniCluster(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testCatalogFamilyFilter() throws IOException, InterruptedException { |
| 46 | + |
| 47 | + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); |
| 48 | + admin.createTable(new HTableDescriptor(TABLE).addFamily(new HColumnDescriptor(EXTRA_CF))); |
| 49 | + admin.split(TABLE, Bytes.toBytes("55555")); |
| 50 | + |
| 51 | + while (admin.getTableRegions(TABLE).size() != 2) { |
| 52 | + LOG.info("Waiting for 2 regions in table"); |
| 53 | + Thread.sleep(1000); |
| 54 | + } |
| 55 | + |
| 56 | + byte[] testRow = Bytes.toBytes("44444"); |
| 57 | + |
| 58 | + admin.addColumn(TableName.META_TABLE_NAME, new HColumnDescriptor(EXTRA_CF)); |
| 59 | + |
| 60 | + Table metaTable = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); |
| 61 | + try { |
| 62 | + byte[] metaKey = HRegionInfo.createRegionName(TABLE, testRow, HConstants.NINES, false); |
| 63 | + Put put = new Put(metaKey); |
| 64 | + put.addColumn(EXTRA_CF_BYTES, EXTRA_CF_BYTES, Bytes.toBytes("unused val")); |
| 65 | + metaTable.put(put); |
| 66 | + } finally { |
| 67 | + metaTable.close(); |
| 68 | + } |
| 69 | + |
| 70 | + Table table = TEST_UTIL.getConnection().getTable(TABLE); |
| 71 | + |
| 72 | + try { |
| 73 | + Get get = new Get(testRow); |
| 74 | + // we don't expect or care about a result here. |
| 75 | + // instead, we just want it to succeed, which proves that meta is |
| 76 | + // properly filtering on the correct family |
| 77 | + table.get(get); |
| 78 | + } finally { |
| 79 | + table.close(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments