TEST_UTIL.startMiniZKCluster();
Configuration conf = TEST_UTIL.getConfiguration();
conf.set(HConstants.MASTER_PORT, "0");
HMaster hm = new HMaster(conf);
ServerName sm = hm.getServerName();
RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT);
try {
int i = 0;
//retry the RPC a few times; we have seen SocketTimeoutExceptions if we
//try to connect too soon. Retry on SocketTimeoutException.
while (i < 20) {
try {
BlockingRpcChannel channel =
rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
MasterProtos.MasterService.BlockingInterface stub =
MasterProtos.MasterService.newBlockingStub(channel);
stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
fail();
} catch (ServiceException ex) {
IOException ie = ProtobufUtil.getRemoteException(ex);
if (!(ie instanceof SocketTimeoutException)) {
if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
"ServerNotRunningYetException: Server is not running yet")) {
// Done. Got the exception we wanted.
System.out.println("Expected exception: " + ie.getMessage());
return;
} else {
throw ex;
}
} else {
System.err.println("Got SocketTimeoutException. Will retry. ");
}
} catch (Throwable t) {
fail("Unexpected throwable: " + t);
}
Thread.sleep(100);
i++;
}
fail();
} finally {
rpcClient.stop();
}
}