public static Factory mkInprocessZookeeper(String localDir, int port) throws IOException, InterruptedException { LOG.info("Starting in-process zookeeper at port " + port + " and dir " + localDir); File localFile = new File(localDir); ZooKeeperServer zk = new ZooKeeperServer(localFile, localFile, 2000); Factory factory = new Factory(new InetSocketAddress(port), 0); factory.startup(zk); return factory; }
public ServerCnxnFactory mkInprocessZookeeper(String localdir, int port) throws IOException, InterruptedException { LOG.info("Starting inprocess zookeeper at port " + port + " and dir " + localdir); File localfile = new File(localdir); ZooKeeperServer zk = new ZooKeeperServer(localfile, localfile, 2000); ServerCnxnFactory factory =NIOServerCnxnFactory.createFactory( new InetSocketAddress(port),60); factory.startup(zk); return factory; }
/** */ private void startServerInstance(File dataDir, ServerCnxnFactory factory) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); factory.startup(zks); }
public EmbeddedZookeeper(int port) throws IOException { this.port = port; zkDataDir = Files.createTempDir(); zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(zkDataDir, zkDataDir); zkServer.setTxnLogFactory(ftxn); cnxnFactory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(port), 0); }
@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)); }
public void startServer() throws Exception { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.debug("Running ZK server"); // ServerStats.registerAsConcrete(); ClientBase.setupTestEnv(); ZkTmpDir = File.createTempFile("zookeeper", "test"); ZkTmpDir.delete(); ZkTmpDir.mkdir(); zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(zkaddr, 100); serverFactory.startup(zks); boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT); LOG.debug("Server up: " + b); // create a zookeeper client LOG.debug("Instantiate ZK Client"); zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build(); // initialize the zk client with values zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); }
/** * Starting the given server instance */ public static void startServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int serverId) throws IOException, InterruptedException { final int port = getPort(hostPort); LOG.info("STARTING server instance 127.0.0.1:{}", port); ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); zks.setCreateSessionTrackerServerId(serverId); factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp( "127.0.0.1:" + port, CONNECTION_TIMEOUT, factory.isSecure())); }
@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(); }
public void testSnapshot() throws Exception { File snapDir = new File(testData, "invalidsnap"); ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000); SyncRequestProcessor.setSnapCount(1000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
private ZooKeeperServer setupSessionTracker() throws IOException { File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); zks.setupRequestProcessors(); firstProcessor = new FirstProcessor(zks, null); zks.firstProcessor = firstProcessor; // setup session tracker zks.createSessionTracker(); zks.startSessionTracker(); return zks; }
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(); }
File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); SyncRequestProcessor.setSnapCount(100); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); zks.startdata(); List<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
@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)); } }
@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(); }
QuorumBase.shutdown(qb.s5); String hp = qb.hostPort.split(",")[0]; ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(), qb.s1.getTxnFactory().getDataDir(), 3000); final int PORT = Integer.parseInt(hp.split(":")[1]);
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
stopServer(); zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); startServer();
@Test public void testTxnLogElapsedSyncTime() throws IOException { File tmpDir = ClientBase.createEmptyTestDir(); FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"), new File(tmpDir, "data_txnlog")); ZooKeeperServer zks = new ZooKeeperServer(); zks.setTxnLogFactory(fileTxnSnapLog); ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks); long elapsedTime = serverBean.getTxnLogElapsedSyncTime(); assertEquals(-1, elapsedTime); TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData); Record txn = new SetDataTxn("/foo", new byte[0], 1); Request req = new Request(0, 0, 0, hdr, txn, 0); try { zks.getTxnLogFactory().append(req); zks.getTxnLogFactory().commit(); elapsedTime = serverBean.getTxnLogElapsedSyncTime(); assertNotEquals(-1, elapsedTime); assertEquals(elapsedTime, serverBean.getTxnLogElapsedSyncTime()); } finally { fileTxnSnapLog.close(); } }