use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class TestFromClientSide method testNonCachedGetRegionLocation.
@Test
public /**
* Tests the non cached version of getRegionLocator by moving a region.
*/
void testNonCachedGetRegionLocation() throws Exception {
// Test Initialization.
final TableName tableName = TableName.valueOf(name.getMethodName());
byte[] family1 = Bytes.toBytes("f1");
byte[] family2 = Bytes.toBytes("f2");
try (Table table = TEST_UTIL.createTable(tableName, new byte[][] { family1, family2 }, 10);
Admin admin = TEST_UTIL.getAdmin();
RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
List<HRegionLocation> allRegionLocations = locator.getAllRegionLocations();
assertEquals(1, allRegionLocations.size());
HRegionInfo regionInfo = allRegionLocations.get(0).getRegionInfo();
ServerName addrBefore = allRegionLocations.get(0).getServerName();
// Verify region location before move.
HRegionLocation addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
HRegionLocation addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(), true);
assertEquals(addrBefore.getPort(), addrCache.getPort());
assertEquals(addrBefore.getPort(), addrNoCache.getPort());
ServerName addrAfter = null;
// Now move the region to a different server.
for (int i = 0; i < SLAVES; i++) {
HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(i);
ServerName addr = regionServer.getServerName();
if (addr.getPort() != addrBefore.getPort()) {
admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(addr.toString()));
// Wait for the region to move.
Thread.sleep(5000);
addrAfter = addr;
break;
}
}
// Verify the region was moved.
addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(), true);
assertNotNull(addrAfter);
assertTrue(addrAfter.getPort() != addrCache.getPort());
assertEquals(addrAfter.getPort(), addrNoCache.getPort());
}
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class TestPrefixTree method setUp.
@Before
public void setUp() throws Exception {
TableName tableName = TableName.valueOf(getClass().getSimpleName());
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor(fam).setDataBlockEncoding(DataBlockEncoding.PREFIX_TREE));
HRegionInfo info = new HRegionInfo(tableName, null, null, false);
Path path = testUtil.getDataTestDir(getClass().getSimpleName());
region = HBaseTestingUtility.createRegionAndWAL(info, path, testUtil.getConfiguration(), htd);
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class TestRegionPlan method test.
@Test
public void test() {
HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName()));
ServerName source = ServerName.valueOf("source", 1234, 2345);
ServerName dest = ServerName.valueOf("dest", 1234, 2345);
// Identiy equality
RegionPlan plan = new RegionPlan(hri, source, dest);
assertEquals(plan.hashCode(), new RegionPlan(hri, source, dest).hashCode());
assertEquals(plan, new RegionPlan(hri, source, dest));
// Source and destination not used for equality
assertEquals(plan.hashCode(), new RegionPlan(hri, dest, source).hashCode());
assertEquals(plan, new RegionPlan(hri, dest, source));
// HRI is used for equality
HRegionInfo other = new HRegionInfo(TableName.valueOf(name.getMethodName() + "other"));
assertNotEquals(plan.hashCode(), new RegionPlan(other, source, dest).hashCode());
assertNotEquals(plan, new RegionPlan(other, source, dest));
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class TestRegionState method test.
@Test
public void test() {
RegionState state1 = new RegionState(new HRegionInfo(TableName.valueOf(name.getMethodName())), RegionState.State.OPENING);
ClusterStatusProtos.RegionState protobuf1 = state1.convert();
RegionState state2 = RegionState.convert(protobuf1);
ClusterStatusProtos.RegionState protobuf2 = state1.convert();
assertEquals(state1, state2);
assertEquals(protobuf1, protobuf2);
}
use of org.apache.hadoop.hbase.HRegionInfo in project hbase by apache.
the class TestRegionStates method createFakeRegion.
private HRegionInfo createFakeRegion() {
HRegionInfo info = mock(HRegionInfo.class);
when(info.getEncodedName()).thenReturn(UUID.randomUUID().toString());
return info;
}
Aggregations