use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestCoprocessorEndpoint method testCoprocessorServiceNullResponse.
@Test
public void testCoprocessorServiceNullResponse() throws Throwable {
Table table = util.getConnection().getTable(TEST_TABLE);
List<HRegionLocation> regions;
try (RegionLocator rl = util.getConnection().getRegionLocator(TEST_TABLE)) {
regions = rl.getAllRegionLocations();
}
final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build();
try {
// scan: for all regions
final RpcController controller = new ServerRpcController();
// test that null results are supported
Map<byte[], String> results = table.coprocessorService(TestRpcServiceProtos.TestProtobufRpcProto.class, ROWS[0], ROWS[ROWS.length - 1], new Batch.Call<TestRpcServiceProtos.TestProtobufRpcProto, String>() {
public String call(TestRpcServiceProtos.TestProtobufRpcProto instance) throws IOException {
CoprocessorRpcUtils.BlockingRpcCallback<TestProtos.EchoResponseProto> callback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
instance.echo(controller, request, callback);
TestProtos.EchoResponseProto response = callback.get();
LOG.debug("Batch.Call got result " + response);
return null;
}
});
for (Map.Entry<byte[], String> e : results.entrySet()) {
LOG.info("Got value " + e.getValue() + " for region " + Bytes.toStringBinary(e.getKey()));
}
assertEquals(3, results.size());
for (HRegionLocation region : regions) {
HRegionInfo info = region.getRegionInfo();
LOG.info("Region info is " + info.getRegionNameAsString());
assertTrue(results.containsKey(info.getRegionName()));
assertNull(results.get(info.getRegionName()));
}
} finally {
table.close();
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestServerCustomProtocol method testSingleMethod.
@Test
public void testSingleMethod() throws Throwable {
try (Table table = util.getConnection().getTable(TEST_TABLE);
RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
Map<byte[], String> results = table.coprocessorService(PingProtos.PingService.class, null, ROW_A, new Batch.Call<PingProtos.PingService, String>() {
@Override
public String call(PingProtos.PingService instance) throws IOException {
CoprocessorRpcUtils.BlockingRpcCallback<PingProtos.PingResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
instance.ping(null, PingProtos.PingRequest.newBuilder().build(), rpcCallback);
return rpcCallback.get().getPong();
}
});
// Should have gotten results for 1 of the three regions only since we specified
// rows from 1 region
assertEquals(1, results.size());
verifyRegionResults(locator, results, ROW_A);
final String name = "NAME";
results = hello(table, name, null, ROW_A);
// Should have gotten results for 1 of the three regions only since we specified
// rows from 1 region
assertEquals(1, results.size());
verifyRegionResults(locator, results, "Hello, NAME", ROW_A);
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestCoprocessorEndpoint method testCoprocessorService.
@Test
public void testCoprocessorService() throws Throwable {
Table table = util.getConnection().getTable(TEST_TABLE);
List<HRegionLocation> regions;
try (RegionLocator rl = util.getConnection().getRegionLocator(TEST_TABLE)) {
regions = rl.getAllRegionLocations();
}
final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello").build();
final Map<byte[], String> results = Collections.synchronizedMap(new TreeMap<byte[], String>(Bytes.BYTES_COMPARATOR));
try {
// scan: for all regions
final RpcController controller = new ServerRpcController();
table.coprocessorService(TestRpcServiceProtos.TestProtobufRpcProto.class, ROWS[0], ROWS[ROWS.length - 1], new Batch.Call<TestRpcServiceProtos.TestProtobufRpcProto, TestProtos.EchoResponseProto>() {
public TestProtos.EchoResponseProto call(TestRpcServiceProtos.TestProtobufRpcProto instance) throws IOException {
LOG.debug("Default response is " + TestProtos.EchoRequestProto.getDefaultInstance());
CoprocessorRpcUtils.BlockingRpcCallback<TestProtos.EchoResponseProto> callback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
instance.echo(controller, request, callback);
TestProtos.EchoResponseProto response = callback.get();
LOG.debug("Batch.Call returning result " + response);
return response;
}
}, new Batch.Callback<TestProtos.EchoResponseProto>() {
public void update(byte[] region, byte[] row, TestProtos.EchoResponseProto result) {
assertNotNull(result);
assertEquals("hello", result.getMessage());
results.put(region, result.getMessage());
}
});
for (Map.Entry<byte[], String> e : results.entrySet()) {
LOG.info("Got value " + e.getValue() + " for region " + Bytes.toStringBinary(e.getKey()));
}
assertEquals(3, results.size());
for (HRegionLocation info : regions) {
LOG.info("Region info is " + info.getRegionInfo().getRegionNameAsString());
assertTrue(results.containsKey(info.getRegionInfo().getRegionName()));
}
results.clear();
// scan: for region 2 and region 3
table.coprocessorService(TestRpcServiceProtos.TestProtobufRpcProto.class, ROWS[rowSeperator1], ROWS[ROWS.length - 1], new Batch.Call<TestRpcServiceProtos.TestProtobufRpcProto, TestProtos.EchoResponseProto>() {
public TestProtos.EchoResponseProto call(TestRpcServiceProtos.TestProtobufRpcProto instance) throws IOException {
LOG.debug("Default response is " + TestProtos.EchoRequestProto.getDefaultInstance());
CoprocessorRpcUtils.BlockingRpcCallback<TestProtos.EchoResponseProto> callback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
instance.echo(controller, request, callback);
TestProtos.EchoResponseProto response = callback.get();
LOG.debug("Batch.Call returning result " + response);
return response;
}
}, new Batch.Callback<TestProtos.EchoResponseProto>() {
public void update(byte[] region, byte[] row, TestProtos.EchoResponseProto result) {
assertNotNull(result);
assertEquals("hello", result.getMessage());
results.put(region, result.getMessage());
}
});
for (Map.Entry<byte[], String> e : results.entrySet()) {
LOG.info("Got value " + e.getValue() + " for region " + Bytes.toStringBinary(e.getKey()));
}
assertEquals(2, results.size());
} finally {
table.close();
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestServerCustomProtocol method testCompoundCall.
@Test
public void testCompoundCall() throws Throwable {
try (Table table = util.getConnection().getTable(TEST_TABLE);
RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
Map<byte[], String> results = compoundOfHelloAndPing(table, ROW_A, ROW_C);
verifyRegionResults(locator, results, "Hello, pong", ROW_A);
verifyRegionResults(locator, results, "Hello, pong", ROW_B);
verifyRegionResults(locator, results, "Hello, pong", ROW_C);
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class DistributedHBaseCluster method getServerHoldingRegion.
@Override
public ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException {
HRegionLocation regionLoc = null;
try (RegionLocator locator = connection.getRegionLocator(tn)) {
regionLoc = locator.getRegionLocation(regionName, true);
}
if (regionLoc == null) {
LOG.warn("Cannot find region server holding region " + Bytes.toString(regionName) + ", start key [" + Bytes.toString(HRegionInfo.getStartKey(regionName)) + "]");
return null;
}
AdminProtos.AdminService.BlockingInterface client = ((ClusterConnection) this.connection).getAdmin(regionLoc.getServerName());
ServerInfo info = ProtobufUtil.getServerInfo(null, client);
return ProtobufUtil.toServerName(info.getServerName());
}
Aggregations