Search in sources :

Example 86 with HRegionInfo

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());
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 87 with HRegionInfo

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);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Before(org.junit.Before)

Example 88 with HRegionInfo

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));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 89 with HRegionInfo

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);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ClusterStatusProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos) Test(org.junit.Test)

Example 90 with HRegionInfo

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;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)408 ServerName (org.apache.hadoop.hbase.ServerName)153 Test (org.junit.Test)141 TableName (org.apache.hadoop.hbase.TableName)118 ArrayList (java.util.ArrayList)86 IOException (java.io.IOException)83 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)75 Path (org.apache.hadoop.fs.Path)63 List (java.util.List)59 HashMap (java.util.HashMap)57 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)49 Table (org.apache.hadoop.hbase.client.Table)47 Map (java.util.Map)43 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)41 FileSystem (org.apache.hadoop.fs.FileSystem)40 Configuration (org.apache.hadoop.conf.Configuration)38 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)35 TreeMap (java.util.TreeMap)26 HashSet (java.util.HashSet)23 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)22