/** * Shutdown the serving instance */ protected void shutdown() { if (cnxnFactory != null) { cnxnFactory.shutdown(); } }
public void shutdownInprocessZookeeper(ServerCnxnFactory handle) { handle.shutdown(); }
/** * Shutdown the serving instance */ protected void shutdown() { if (containerManager != null) { containerManager.stop(); } if (cnxnFactory != null) { cnxnFactory.shutdown(); } if (secureCnxnFactory != null) { secureCnxnFactory.shutdown(); } try { if (adminServer != null) { adminServer.shutdown(); } } catch (AdminServerException e) { LOG.warn("Problem stopping AdminServer", e); } }
@Override public void close() throws IOException { if (started.get() && !stopped.getAndSet(true)) { cnxnFactory.shutdown(); try { cnxnFactory.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (zkServer.isRunning()) { zkServer.shutdown(); } deleteRecursively(zkDataDir.toPath(), ALLOW_INSECURE); } }
@After public void teardown() throws Exception { if (servcnxnf != null) { servcnxnf.shutdown(); } if (zks != null) { zks.shutdown(); } }
@Test public void testJMXRegistrationWithNetty() throws Exception { String originalServerCnxnFactory = System .getProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, NettyServerCnxnFactory.class.getName()); try { ClientBase.setupTestEnv(); File tmpDir_1 = ClientBase.createTmpDir(); ServerCnxnFactory server_1 = startServer(tmpDir_1); File tmpDir_2 = ClientBase.createTmpDir(); ServerCnxnFactory server_2 = startServer(tmpDir_2); server_1.shutdown(); server_2.shutdown(); deleteFile(tmpDir_1); deleteFile(tmpDir_2); } finally { // setting back if (originalServerCnxnFactory == null || originalServerCnxnFactory.isEmpty()) { System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); } else { System.setProperty( ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, originalServerCnxnFactory); } } }
/** * This test makes sure that duplicate state changes are not communicated * to the client watcher. For example we should not notify state as * "disconnected" if the watch has already been disconnected. In general * we don't consider a dup state notification if the event type is * not "None" (ie non-None communicates an event). */ @Test public void testSessionStateNoDupStateReporting() throws IOException, InterruptedException, KeeperException { final int TIMEOUT = 3000; DupWatcher watcher = new DupWatcher(); ZooKeeper zk = createClient(TIMEOUT, watcher); // shutdown the server serverFactory.shutdown(); try { Thread.sleep(10000); } catch (InterruptedException e) { // ignore } // verify that the size is just 2 - ie connect then disconnect // if the client attempts reconnect and we are not handling current // state correctly (ie eventing on duplicate disconnects) then we'll // see a disconnect for each Assert.failed connection attempt Assert.assertEquals(2, watcher.states.size()); zk.close(); }
@Test public void testJMXRegistrationWithNIO() throws Exception { ClientBase.setupTestEnv(); File tmpDir_1 = ClientBase.createTmpDir(); ServerCnxnFactory server_1 = startServer(tmpDir_1); File tmpDir_2 = ClientBase.createTmpDir(); ServerCnxnFactory server_2 = startServer(tmpDir_2); server_1.shutdown(); server_2.shutdown(); deleteFile(tmpDir_1); deleteFile(tmpDir_2); }
@After public void tearDown() throws Exception { serverFactory.shutdown(); zs.shutdown(); Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); }
/** */ private void shutdownServerInstance(ServerCnxnFactory factory) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) zkDb = zs.getZKDatabase(); } factory.shutdown(); try { if (zkDb != null) zkDb.close(); } catch (IOException ie) { // ignore } } }
@After public void teardown() throws Exception { // count down to avoid infinite blocking call due to this latch, if // any. startupDelayLatch.countDown(); if (servcnxnf != null) { servcnxnf.shutdown(); } if (zks != null) { zks.shutdown(); } if (zks.getZKDatabase() != null) { zks.getZKDatabase().close(); } ClientBase.recursiveDelete(tmpDir); }
zk.close(); f.shutdown(); zks.shutdown(); Assert.assertTrue("waiting for server down",
f.shutdown(); zks.shutdown(); Assert.assertTrue("waiting for server down",
@Test public void testGetSecureClientAddress() throws IOException { ZooKeeperServer zks = new ZooKeeperServer(); /** * case 1: When secure client is not configured getSecureClientAddress * should return empty string */ ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks); String result = serverBean.getSecureClientPort(); assertEquals("", result); /** * case 2: When secure client is configured getSecureClientAddress * should return configured SecureClientAddress */ ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); int secureClientPort = 8443; InetSocketAddress address = new InetSocketAddress(secureClientPort); cnxnFactory.configure(address, 5, true); zks.setSecureServerCnxnFactory(cnxnFactory); result = serverBean.getSecureClientAddress(); String ipv4 = "0.0.0.0:" + secureClientPort; String ipv6 = "0:0:0:0:0:0:0:0:" + secureClientPort; assertTrue(result.equals(ipv4) || result.equals(ipv6)); // cleanup cnxnFactory.shutdown(); }
@Test public void testGetSecureClientPort() throws IOException { ZooKeeperServer zks = new ZooKeeperServer(); /** * case 1: When secure client is not configured GetSecureClientPort * should return empty string */ ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks); String result = serverBean.getSecureClientPort(); assertEquals("", result); /** * case 2: When secure client is configured GetSecureClientPort should * return configured port */ ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); int secureClientPort = 8443; InetSocketAddress address = new InetSocketAddress(secureClientPort); cnxnFactory.configure(address, 5, true); zks.setSecureServerCnxnFactory(cnxnFactory); result = serverBean.getSecureClientPort(); assertEquals(Integer.toString(secureClientPort), result); // cleanup cnxnFactory.shutdown(); }
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) { zkDb = zs.getZKDatabase(); } } factory.shutdown(); try { if (zkDb != null) { zkDb.close(); } } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT, factory.isSecure())); } }
@Test public void testDisconnectedAddAuth() throws Exception { File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); SyncRequestProcessor.setSnapCount(1000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); try { LOG.info("starting up the zookeeper server .. waiting"); Assert.assertTrue("waiting for server being up", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); ZooKeeper zk = ClientBase.createZKClient(HOSTPORT); try { zk.addAuthInfo("digest", "pat:test".getBytes()); zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); } finally { zk.close(); } } finally { f.shutdown(); zks.shutdown(); Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT)); } }
ClientBase.waitForServerUp("127.0.0.1:" + PORT, QuorumTest.CONNECTION_TIMEOUT)); factory.shutdown(); zks.shutdown(); Assert.assertTrue("waiting for server down",
f.shutdown(); Assert.assertTrue("waiting for server being down ", ClientBase .waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));