/** * Shutdown the Peer */ public void shutdown() { // set the zookeeper server to null self.cnxnFactory.setZooKeeperServer(null); // clear all the connections self.cnxnFactory.closeAll(); // shutdown previous zookeeper if (zk != null) { zk.shutdown(); } }
self.cnxnFactory.closeAll();
/** {@inheritDoc} */ @Override public void kill() { try { if (quorumPeer != null) { Field cnxnFactoryField = QuorumPeer.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(quorumPeer); cnxnFactory.closeAll(); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); } close(); } catch (Exception e) { e.printStackTrace(); } }
@Override public synchronized void shutdown() { if (!canShutdown()) { LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); return; } shutdown = true; unregisterJMX(this); // set peer's server to null self.cnxnFactory.setZooKeeperServer(null); // clear all the connections self.cnxnFactory.closeAll(); // shutdown the server itself super.shutdown(); }
@Override public void kill() { try { if ( quorumPeer != null ) { Field cnxnFactoryField = QuorumPeer.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(quorumPeer); cnxnFactory.closeAll(); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); } close(); } catch ( Exception e ) { e.printStackTrace(); } }
@Override public void kill() { try { Field cnxnFactoryField = ZooKeeperServerMain.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(this); cnxnFactory.closeAll(); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); close(); } catch ( Exception e ) { e.printStackTrace(); // just ignore - this class is only for testing } }
ServerCnxnFactory sf = this.serverFactory.getAndSet(null); if (sf != null) { sf.closeAll(); sf.shutdown();
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
/** * Have the services fail their health checks half the time, * causing the master role to bounce back and forth in the * cluster. Meanwhile, causes ZK to disconnect clients every * 50ms, to trigger the retry code and failures to become active. */ @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000) public void testRandomHealthAndDisconnects() throws Exception { long runFor = STRESS_RUNTIME_SECS * 1000; Mockito.doAnswer(new RandomlyThrow(0)) .when(cluster.getService(0).proxy).monitorHealth(); Mockito.doAnswer(new RandomlyThrow(1)) .when(cluster.getService(1).proxy).monitorHealth(); conf.setInt(CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY, 100); // Don't start until after the above mocking. Otherwise we can get // Mockito errors if the HM calls the proxy in the middle of // setting up the mock. cluster.start(); long st = Time.now(); while (Time.now() - st < runFor) { cluster.getTestContext().checkException(); serverFactory.closeAll(); Thread.sleep(50); } }
/** * Have the services fail their health checks half the time, * causing the master role to bounce back and forth in the * cluster. Meanwhile, causes ZK to disconnect clients every * 50ms, to trigger the retry code and failures to become active. */ @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000) public void testRandomHealthAndDisconnects() throws Exception { long runFor = STRESS_RUNTIME_SECS * 1000; Mockito.doAnswer(new RandomlyThrow(0)) .when(cluster.getService(0).proxy).monitorHealth(); Mockito.doAnswer(new RandomlyThrow(1)) .when(cluster.getService(1).proxy).monitorHealth(); conf.setInt(CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_KEY, 100); // Don't start until after the above mocking. Otherwise we can get // Mockito errors if the HM calls the proxy in the middle of // setting up the mock. cluster.start(); long st = Time.now(); while (Time.now() - st < runFor) { cluster.getTestContext().checkException(); serverFactory.closeAll(); Thread.sleep(50); } }