/** * Method to check whether the cached region location is non-empty for the given table. It repeats * the same check several times as clearing of cache by some async operations may not reflect * immediately. */ private void checkRegionLocationIsCached(final TableName tableName, final Connection conn) throws InterruptedException, IOException { for (int count = 0; count < 50; count++) { int number = ((ConnectionImplementation) conn).getNumberOfCachedRegionLocations(tableName); assertNotEquals("Expected non-zero number of cached region locations", 0, number); Thread.sleep(100); } }
@Test public void testRegionCache() throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); htd.addFamily(fam); byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd, KEYS); HRegionLocator locator = (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName()); List<HRegionLocation> results = locator.getAllRegionLocations(); int number = ((ConnectionImplementation)admin.getConnection()) .getNumberOfCachedRegionLocations(htd.getTableName()); assertEquals(results.size(), number); ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection()); assertNotNull("Can't get cached location for row aaa", conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa"))); for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){ assertNotNull("Can't get cached location for row "+ Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey))); } }
Assert.assertEquals(0, conn.getNumberOfCachedRegionLocations(TABLE_NAME3));
Assert.assertEquals(0, conn.getNumberOfCachedRegionLocations(TABLE_NAME)); Put put2 = new Put(ROW); put2.addColumn(FAM_NAM, ROW, ROW);
/** * Method to check whether the cached region location is non-empty for the given table. It repeats * the same check several times as clearing of cache by some async operations may not reflect * immediately. */ private void checkRegionLocationIsCached(final TableName tableName, final Connection conn) throws InterruptedException, IOException { for (int count = 0; count < 50; count++) { int number = ((ConnectionImplementation) conn).getNumberOfCachedRegionLocations(tableName); assertNotEquals("Expected non-zero number of cached region locations", 0, number); Thread.sleep(100); } }
@Test public void testRegionCache() throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); htd.addFamily(fam); byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd, KEYS); HRegionLocator locator = (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName()); List<HRegionLocation> results = locator.getAllRegionLocations(); int number = ((ConnectionImplementation)admin.getConnection()) .getNumberOfCachedRegionLocations(htd.getTableName()); assertEquals(results.size(), number); ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection()); assertNotNull("Can't get cached location for row aaa", conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa"))); for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){ assertNotNull("Can't get cached location for row "+ Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey))); } }
Assert.assertEquals(0, conn.getNumberOfCachedRegionLocations(TABLE_NAME3));
Assert.assertEquals(0, conn.getNumberOfCachedRegionLocations(TABLE_NAME)); Put put2 = new Put(ROW); put2.addColumn(FAM_NAM, ROW, ROW);