Search in sources :

Example 46 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class TestReplicasClient method testLocations.

@Test
public void testLocations() throws Exception {
    byte[] b1 = "testLocations".getBytes();
    openRegion(hriSecondary);
    ClusterConnection hc = (ClusterConnection) HTU.getAdmin().getConnection();
    try {
        hc.clearRegionCache();
        RegionLocations rl = hc.locateRegion(table.getName(), b1, false, false);
        Assert.assertEquals(2, rl.size());
        rl = hc.locateRegion(table.getName(), b1, true, false);
        Assert.assertEquals(2, rl.size());
        hc.clearRegionCache();
        rl = hc.locateRegion(table.getName(), b1, true, false);
        Assert.assertEquals(2, rl.size());
        rl = hc.locateRegion(table.getName(), b1, false, false);
        Assert.assertEquals(2, rl.size());
    } finally {
        closeRegion(hriSecondary);
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) Test(org.junit.Test)

Example 47 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class HConnectionTestingUtility method getMockedConnectionAndDecorate.

/**
   * Calls {@link #getMockedConnection(Configuration)} and then mocks a few
   * more of the popular {@link ClusterConnection} methods so they do 'normal'
   * operation (see return doc below for list). Be sure to shutdown the
   * connection when done by calling {@link Connection#close()} else it will stick around;
   * this is probably not what you want.
   *
   * @param conf Configuration to use
   * @param admin An AdminProtocol; can be null but is usually
   * itself a mock.
   * @param client A ClientProtocol; can be null but is usually
   * itself a mock.
   * @param sn ServerName to include in the region location returned by this
   * <code>connection</code>
   * @param hri HRegionInfo to include in the location returned when
   * getRegionLocator is called on the mocked connection
   * @return Mock up a connection that returns a {@link Configuration} when
   * {@link ClusterConnection#getConfiguration()} is called, a 'location' when
   * {@link ClusterConnection#getRegionLocation(org.apache.hadoop.hbase.TableName, byte[], boolean)}
   * is called,
   * and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
   * {@link ClusterConnection#getAdmin(ServerName)} is called, returns the passed
   * {@link ClientProtos.ClientService.BlockingInterface} instance when
   * {@link ClusterConnection#getClient(ServerName)} is called (Be sure to call
   * {@link Connection#close()} when done with this mocked Connection.
   * @throws IOException
   */
public static ClusterConnection getMockedConnectionAndDecorate(final Configuration conf, final AdminProtos.AdminService.BlockingInterface admin, final ClientProtos.ClientService.BlockingInterface client, final ServerName sn, final HRegionInfo hri) throws IOException {
    ConnectionImplementation c = Mockito.mock(ConnectionImplementation.class);
    Mockito.when(c.getConfiguration()).thenReturn(conf);
    Mockito.doNothing().when(c).close();
    // Make it so we return a particular location when asked.
    final HRegionLocation loc = new HRegionLocation(hri, sn);
    Mockito.when(c.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean())).thenReturn(loc);
    Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).thenReturn(loc);
    Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(new RegionLocations(loc));
    if (admin != null) {
        // If a call to getAdmin, return this implementation.
        Mockito.when(c.getAdmin(Mockito.any(ServerName.class))).thenReturn(admin);
    }
    if (client != null) {
        // If a call to getClient, return this client.
        Mockito.when(c.getClient(Mockito.any(ServerName.class))).thenReturn(client);
    }
    NonceGenerator ng = Mockito.mock(NonceGenerator.class);
    Mockito.when(c.getNonceGenerator()).thenReturn(ng);
    Mockito.when(c.getAsyncProcess()).thenReturn(new AsyncProcess(c, conf, RpcRetryingCallerFactory.instantiate(conf), false, RpcControllerFactory.instantiate(conf)));
    Mockito.when(c.getNewRpcRetryingCallerFactory(conf)).thenReturn(RpcRetryingCallerFactory.instantiate(conf, RetryingCallerInterceptorFactory.NO_OP_INTERCEPTOR, null));
    Mockito.when(c.getRpcControllerFactory()).thenReturn(Mockito.mock(RpcControllerFactory.class));
    Table t = Mockito.mock(Table.class);
    Mockito.when(c.getTable((TableName) Mockito.any())).thenReturn(t);
    ResultScanner rs = Mockito.mock(ResultScanner.class);
    Mockito.when(t.getScanner((Scan) Mockito.any())).thenReturn(rs);
    return c;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory)

Aggregations

RegionLocations (org.apache.hadoop.hbase.RegionLocations)47 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)28 ServerName (org.apache.hadoop.hbase.ServerName)18 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 Test (org.junit.Test)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)7 ArrayList (java.util.ArrayList)6 Result (org.apache.hadoop.hbase.client.Result)6 TableName (org.apache.hadoop.hbase.TableName)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 MetaTableAccessor (org.apache.hadoop.hbase.MetaTableAccessor)4 Pair (org.apache.hadoop.hbase.util.Pair)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2