static public ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns) throws IOException { return createFactory(new InetSocketAddress(clientPort), maxClientCnxns); }
static public ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns) throws IOException { return createFactory(new InetSocketAddress(clientPort), maxClientCnxns); }
/** * This constructor is only used by the existing unit test code. * It defaults to FileLogProvider persistence provider. */ public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit, QuorumVerifier quorumConfig) throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1), quorumConfig); }
static public ServerCnxnFactory createFactory(InetSocketAddress addr, int maxClientCnxns) throws IOException { ServerCnxnFactory factory = createFactory(); factory.configure(addr, maxClientCnxns); return factory; }
/** * This constructor is only used by the existing unit test code. * It defaults to FileLogProvider persistence provider. */ public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit, QuorumVerifier quorumConfig) throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1), quorumConfig); }
static public ServerCnxnFactory createFactory(InetSocketAddress addr, int maxClientCnxns) throws IOException { ServerCnxnFactory factory = createFactory(); factory.configure(addr, maxClientCnxns); return factory; }
/** * This constructor is only used by the existing unit test code. * It defaults to FileLogProvider persistence provider. */ public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit) throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, myid, tickTime, initLimit, syncLimit, false, ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1), new QuorumMaj(quorumPeers)); }
/** * This constructor is only used by the existing unit test code. * It defaults to FileLogProvider persistence provider. */ public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit) throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1), new QuorumMaj(countParticipants(quorumPeers))); }
public CustomQuorumPeer(Map<Long, QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit) throws IOException { super(quorumPeers, snapDir, logDir, electionAlg, myid, tickTime, initLimit, syncLimit, false, ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1), new QuorumMaj(quorumPeers)); }
/** */ private ServerCnxnFactory createNewServerInstance( ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException { final int port = getPort(hostPort); if (factory == null) factory = ServerCnxnFactory.createFactory(port, maxCnxns); return factory; }
/** * This method instantiates a new server. Starting of the server * instance has been moved to a separate method * {@link ClientBase#startServerInstance(File, ServerCnxnFactory, String, int)}. * Because any exception on starting the server would leave the server * running and the caller would not be able to shutdown the instance. This * may affect other test cases. * * @return newly created server instance * * @see <a * href="https://issues.apache.org/jira/browse/ZOOKEEPER-1852">ZOOKEEPER-1852</a> * for more information. */ public static ServerCnxnFactory createNewServerInstance( ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { final int port = getPort(hostPort); LOG.info("CREATING server instance 127.0.0.1:{}", port); if (factory == null) { factory = ServerCnxnFactory.createFactory(port, maxCnxns); } return factory; }
private void startSimpleZKServer(CountDownLatch startupDelayLatch) throws IOException { zks = new SimpleZooKeeperServer(tmpDir, tmpDir, 3000, startupDelayLatch); SyncRequestProcessor.setSnapCount(100); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); servcnxnf = ServerCnxnFactory.createFactory(PORT, -1); Thread startupThread = new Thread() { public void run() { try { servcnxnf.startup(zks); } catch (IOException e) { LOG.error("Unexcepted exception during server startup", e); // Ignoring exception. If there is an ioexception // then one of the following assertion will fail } catch (InterruptedException e) { LOG.error("Unexcepted exception during server startup", e); // Ignoring exception. If there is an interrupted exception // then one of the following assertion will fail } }; }; LOG.info("Starting zk server {}", HOSTPORT); startupThread.start(); }
@Before public void setUp() throws Exception { clientX509Util = new ClientX509Util(); String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data"); System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory"); System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty"); System.setProperty(ZKClientConfig.SECURE_CLIENT, "true"); System.setProperty(clientX509Util.getSslAuthProviderProperty(), "x509"); System.setProperty(clientX509Util.getSslKeystoreLocationProperty(), testDataPath + "/ssl/testKeyStore.jks"); System.setProperty(clientX509Util.getSslKeystorePasswdProperty(), "testpass"); System.setProperty(clientX509Util.getSslTruststoreLocationProperty(), testDataPath + "/ssl/testTrustStore.jks"); System.setProperty(clientX509Util.getSslTruststorePasswdProperty(), "testpass"); System.setProperty("javax.net.debug", "ssl"); System.setProperty("zookeeper.authProvider.x509", "org.apache.zookeeper.server.auth.X509AuthenticationProvider"); String host = "localhost"; int port = PortAssignment.unique(); hostPort = host + ":" + port; serverFactory = ServerCnxnFactory.createFactory(); serverFactory.configure(new InetSocketAddress(host, port), maxCnxns, true); super.setUp(); }
@Before public void setUp() throws Exception { if (tmpDir == null) { tmpDir = ClientBase.createTmpDir(); } ClientBase.setupTestEnv(); zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); serverFactory = ServerCnxnFactory.createFactory(PORT, -1); serverFactory.startup(zs); Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); }
@Before public void setup() throws Exception { File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); SyncRequestProcessor.setSnapCount(100); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); servcnxnf = ServerCnxnFactory.createFactory(PORT, -1); servcnxnf.startup(zks); Assert.assertTrue("waiting for server being up ", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); zks.sessionTracker = new MySessionTracker(); }
SyncRequestProcessor.setSnapCount(1000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); LOG.info("starting up the zookeeper server .. waiting");
private ServerCnxnFactory startServer(File tmpDir) throws IOException, InterruptedException { final int CLIENT_PORT = PortAssignment.unique(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1); f.startup(zks); Assert.assertNotNull("JMX initialization failed!", zks.jmxServerBean); Assert.assertTrue("waiting for server being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, CONNECTION_TIMEOUT)); return f; }
@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(); }
@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)); } }