Search in sources :

Example 1 with EMPTY_END_ROW

use of org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW in project hbase by apache.

the class TestAsyncNonMetaRegionLocator method testLocateAfter.

// usually locate after will return the same result, so we add a test to make it return different
// result.
@Test
public void testLocateAfter() throws IOException, InterruptedException, ExecutionException {
    byte[] row = Bytes.toBytes("1");
    byte[] splitKey = Arrays.copyOf(row, 2);
    TEST_UTIL.createTable(TABLE_NAME, FAMILY, new byte[][] { splitKey });
    TEST_UTIL.waitTableAvailable(TABLE_NAME);
    HRegionLocation currentLoc = LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.CURRENT).get();
    ServerName currentServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    assertLocEquals(EMPTY_START_ROW, splitKey, currentServerName, currentLoc);
    HRegionLocation afterLoc = LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER).get();
    ServerName afterServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs.getOnlineRegions(TABLE_NAME).stream().anyMatch(r -> Bytes.equals(splitKey, r.getRegionInfo().getStartKey()))).findAny().get().getServerName();
    assertLocEquals(splitKey, EMPTY_END_ROW, afterServerName, afterLoc);
    assertSame(afterLoc, LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER).get());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) After(org.junit.After) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 2 with EMPTY_END_ROW

use of org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW in project hbase by apache.

the class TestAsyncNonMetaRegionLocator method testRegionMove.

@Test
public void testRegionMove() throws IOException, InterruptedException, ExecutionException {
    createSingleRegionTable();
    ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    HRegionLocation loc = LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT).get();
    assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, loc);
    ServerName newServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny().get();
    TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegionInfo().getEncodedName()), Bytes.toBytes(newServerName.getServerName()));
    while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName().equals(newServerName)) {
        Thread.sleep(100);
    }
    // Should be same as it is in cache
    assertSame(loc, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT).get());
    LOCATOR.updateCachedLocation(loc, null);
    // null error will not trigger a cache cleanup
    assertSame(loc, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT).get());
    LOCATOR.updateCachedLocation(loc, new NotServingRegionException());
    assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT).get());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) After(org.junit.After) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 Collectors.toList (java.util.stream.Collectors.toList)2 IntStream (java.util.stream.IntStream)2 IOUtils (org.apache.commons.io.IOUtils)2 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)2 EMPTY_END_ROW (org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW)2 EMPTY_START_ROW (org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)2 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableName (org.apache.hadoop.hbase.TableName)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 User (org.apache.hadoop.hbase.security.User)2 ClientTests (org.apache.hadoop.hbase.testclassification.ClientTests)2