Search in sources :

Example 21 with MetaTableLocator

use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.

the class TestMetaTableLocator method testMetaLookup.

/**
   * Test normal operations
   */
@Test
public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException {
    final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
    Mockito.when(client.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).thenReturn(GetResponse.newBuilder().build());
    final MetaTableLocator mtl = new MetaTableLocator();
    assertNull(mtl.getMetaRegionLocation(this.watcher));
    for (RegionState.State state : RegionState.State.values()) {
        if (state.equals(RegionState.State.OPEN))
            continue;
        MetaTableLocator.setMetaLocation(this.watcher, SN, state);
        assertNull(mtl.getMetaRegionLocation(this.watcher));
        assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState());
    }
    MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
    assertEquals(mtl.getMetaRegionLocation(this.watcher), SN);
    assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState());
    mtl.deleteMetaLocation(this.watcher);
    assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName());
    assertEquals(MetaTableLocator.getMetaRegionState(this.watcher).getState(), RegionState.State.OFFLINE);
    assertNull(mtl.getMetaRegionLocation(this.watcher));
}
Also used : RegionState(org.apache.hadoop.hbase.master.RegionState) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) Test(org.junit.Test)

Aggregations

MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)21 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)10 ServerName (org.apache.hadoop.hbase.ServerName)8 Pair (org.apache.hadoop.hbase.util.Pair)7 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)7 Test (org.junit.Test)6 IOException (java.io.IOException)3 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)3 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)3 HashSet (java.util.HashSet)2 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)2 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)2 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1