本文整理汇总了Java中org.apache.hadoop.hbase.ipc.RpcClient.stop方法的典型用法代码示例。如果您正苦于以下问题:Java RpcClient.stop方法的具体用法?Java RpcClient.stop怎么用?Java RpcClient.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.ipc.RpcClient
的用法示例。
在下文中一共展示了RpcClient.stop方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRpcCallWithEnabledKerberosSaslAuth
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
/**
* To run this test, we must specify the following system properties:
*<p>
* <b> hbase.regionserver.kerberos.principal </b>
* <p>
* <b> hbase.regionserver.keytab.file </b>
*/
@Test
public void testRpcCallWithEnabledKerberosSaslAuth() throws Exception {
assumeTrue(isKerberosPropertySetted());
String krbKeytab = getKeytabFileForTesting();
String krbPrincipal = getPrincipalForTesting();
Configuration cnf = new Configuration();
cnf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(cnf);
UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab);
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
UserGroupInformation ugi2 = UserGroupInformation.getCurrentUser();
// check that the login user is okay:
assertSame(ugi, ugi2);
assertEquals(AuthenticationMethod.KERBEROS, ugi.getAuthenticationMethod());
assertEquals(krbPrincipal, ugi.getUserName());
Configuration conf = getSecuredConfiguration();
SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
Mockito.when(securityInfoMock.getServerPrincipal())
.thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
SecurityInfo.addInfo("TestDelayedService", securityInfoMock);
boolean delayReturnValue = false;
InetSocketAddress isa = new InetSocketAddress("localhost", 0);
TestDelayedImplementation instance = new TestDelayedImplementation(delayReturnValue);
BlockingService service =
TestDelayedRpcProtos.TestDelayedService.newReflectiveBlockingService(instance);
rpcServer = new RpcServer(null, "testSecuredDelayedRpc",
Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(service, null)),
isa, conf, new FifoRpcScheduler(conf, 1));
rpcServer.start();
RpcClient rpcClient = new RpcClient(conf, HConstants.DEFAULT_CLUSTER_ID.toString());
try {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
ServerName.valueOf(rpcServer.getListenerAddress().getHostName(),
rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()),
User.getCurrent(), 1000);
TestDelayedRpcProtos.TestDelayedService.BlockingInterface stub =
TestDelayedRpcProtos.TestDelayedService.newBlockingStub(channel);
List<Integer> results = new ArrayList<Integer>();
TestThread th1 = new TestThread(stub, true, results);
th1.start();
Thread.sleep(100);
th1.join();
assertEquals(0xDEADBEEF, results.get(0).intValue());
} finally {
rpcClient.stop();
}
}
示例2: testAdminTimeout
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
/**
* Test that a client that fails an RPC to the master retries properly and
* doesn't throw any unexpected exceptions.
* @throws Exception
*/
@Test
public void testAdminTimeout() throws Exception {
long lastLimit = HConstants.DEFAULT_HBASE_CLIENT_PREFETCH_LIMIT;
HConnection lastConnection = null;
boolean lastFailed = false;
int initialInvocations = RandomTimeoutBlockingRpcChannel.invokations.get();
RpcClient rpcClient = newRandomTimeoutRpcClient();
try {
for (int i = 0; i < 5 || (lastFailed && i < 100); ++i) {
lastFailed = false;
// Ensure the HBaseAdmin uses a new connection by changing Configuration.
Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
conf.setLong(HConstants.HBASE_CLIENT_PREFETCH_LIMIT, ++lastLimit);
HBaseAdmin admin = null;
try {
admin = new HBaseAdmin(conf);
HConnection connection = admin.getConnection();
assertFalse(connection == lastConnection);
lastConnection = connection;
// Override the connection's rpc client for timeout testing
RpcClient oldRpcClient =
((HConnectionManager.HConnectionImplementation)connection).setRpcClient(
rpcClient);
if (oldRpcClient != null) {
oldRpcClient.stop();
}
// run some admin commands
HBaseAdmin.checkHBaseAvailable(conf);
admin.setBalancerRunning(false, false);
} catch (MasterNotRunningException ex) {
// Since we are randomly throwing SocketTimeoutExceptions, it is possible to get
// a MasterNotRunningException. It's a bug if we get other exceptions.
lastFailed = true;
} finally {
admin.close();
if (admin.getConnection().isClosed()) {
rpcClient = newRandomTimeoutRpcClient();
}
}
}
// Ensure the RandomTimeoutRpcEngine is actually being used.
assertFalse(lastFailed);
assertTrue(RandomTimeoutBlockingRpcChannel.invokations.get() > initialInvocations);
} finally {
rpcClient.stop();
}
}
示例3: testRPCException
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
@Test
public void testRPCException() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
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();
}
}
示例4: testAdminTimeout
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
/**
* Test that a client that fails an RPC to the master retries properly and
* doesn't throw any unexpected exceptions.
* @throws Exception
*/
@Test
public void testAdminTimeout() throws Exception {
HConnection lastConnection = null;
boolean lastFailed = false;
int initialInvocations = RandomTimeoutBlockingRpcChannel.invokations.get();
RpcClient rpcClient = newRandomTimeoutRpcClient();
try {
for (int i = 0; i < 5 || (lastFailed && i < 100); ++i) {
lastFailed = false;
// Ensure the HBaseAdmin uses a new connection by changing Configuration.
Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
conf.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
HBaseAdmin admin = null;
try {
admin = new HBaseAdmin(conf);
HConnection connection = admin.getConnection();
assertFalse(connection == lastConnection);
lastConnection = connection;
// Override the connection's rpc client for timeout testing
RpcClient oldRpcClient =
((ConnectionManager.HConnectionImplementation)connection).setRpcClient(
rpcClient);
if (oldRpcClient != null) {
oldRpcClient.stop();
}
// run some admin commands
HBaseAdmin.checkHBaseAvailable(conf);
admin.setBalancerRunning(false, false);
} catch (MasterNotRunningException ex) {
// Since we are randomly throwing SocketTimeoutExceptions, it is possible to get
// a MasterNotRunningException. It's a bug if we get other exceptions.
lastFailed = true;
} finally {
admin.close();
if (admin.getConnection().isClosed()) {
rpcClient = newRandomTimeoutRpcClient();
}
}
}
// Ensure the RandomTimeoutRpcEngine is actually being used.
assertFalse(lastFailed);
assertTrue(RandomTimeoutBlockingRpcChannel.invokations.get() > initialInvocations);
} finally {
rpcClient.stop();
}
}
示例5: testRPCException
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
@Test
public void testRPCException() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
TEST_UTIL.startMiniZKCluster();
Configuration conf = TEST_UTIL.getConfiguration();
conf.set(HConstants.MASTER_PORT, "0");
CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
HMaster hm = new HMaster(conf, cp);
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();
}
}
示例6: testAdminTimeout
import org.apache.hadoop.hbase.ipc.RpcClient; //导入方法依赖的package包/类
/**
* Test that a client that fails an RPC to the master retries properly and
* doesn't throw any unexpected exceptions.
* @throws Exception
*/
@Test
public void testAdminTimeout() throws Exception {
long lastLimit = HConstants.DEFAULT_HBASE_CLIENT_PREFETCH_LIMIT;
HConnection lastConnection = null;
boolean lastFailed = false;
int initialInvocations = RandomTimeoutBlockingRpcChannel.invokations.get();
RpcClient rpcClient = new RpcClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey()) {
// Return my own instance, one that does random timeouts
@Override
public BlockingRpcChannel createBlockingRpcChannel(ServerName sn,
User ticket, int rpcTimeout) {
return new RandomTimeoutBlockingRpcChannel(this, sn, ticket, rpcTimeout);
}
};
try {
for (int i = 0; i < 5 || (lastFailed && i < 100); ++i) {
lastFailed = false;
// Ensure the HBaseAdmin uses a new connection by changing Configuration.
Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
conf.setLong(HConstants.HBASE_CLIENT_PREFETCH_LIMIT, ++lastLimit);
HBaseAdmin admin = null;
try {
admin = new HBaseAdmin(conf);
HConnection connection = admin.getConnection();
assertFalse(connection == lastConnection);
lastConnection = connection;
// Override the connection's rpc client for timeout testing
((HConnectionManager.HConnectionImplementation)connection).setRpcClient(rpcClient);
// run some admin commands
HBaseAdmin.checkHBaseAvailable(conf);
admin.setBalancerRunning(false, false);
} catch (MasterNotRunningException ex) {
// Since we are randomly throwing SocketTimeoutExceptions, it is possible to get
// a MasterNotRunningException. It's a bug if we get other exceptions.
lastFailed = true;
} finally {
admin.close();
}
}
// Ensure the RandomTimeoutRpcEngine is actually being used.
assertFalse(lastFailed);
assertTrue(RandomTimeoutBlockingRpcChannel.invokations.get() > initialInvocations);
} finally {
rpcClient.stop();
}
}