Package org.apache.zookeeper.server

Examples of org.apache.zookeeper.server.ServerCnxnFactory


        File tmpDir = ClientBase.createTmpDir();

        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

        ServerCnxnFactory f = ServerCnxnFactory.createFactory(
                new InetSocketAddress(bindAddress, PORT), -1);
        f.startup(zks);
        LOG.info("starting up the the server, waiting");

        Assert.assertTrue("waiting for server up",
                   ClientBase.waitForServerUp(HOSTPORT,
                                   CONNECTION_TIMEOUT));

        startSignal = new CountDownLatch(1);
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
        try {
            startSignal.await(CONNECTION_TIMEOUT,
                    TimeUnit.MILLISECONDS);
            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
            zk.close();
        } finally {
            f.shutdown();

            Assert.assertTrue("waiting for server down",
                       ClientBase.waitForServerDown(HOSTPORT,
                                                    CONNECTION_TIMEOUT));
        }
View Full Code Here


        }
        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

        final int PORT = PortAssignment.unique();
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server up",
                   ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                              CONNECTION_TIMEOUT));

        System.err.println("OOM Stage 0");
        utestPrep(PORT);
        System.out.println("Free = " + Runtime.getRuntime().freeMemory()
                + " total = " + Runtime.getRuntime().totalMemory() + " max = "
                + Runtime.getRuntime().maxMemory());
        System.err.println("OOM Stage 1");
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
            utestExists(PORT);
        }
        System.out.println("Free = " + Runtime.getRuntime().freeMemory()
                + " total = " + Runtime.getRuntime().totalMemory() + " max = "
                + Runtime.getRuntime().maxMemory());
        System.err.println("OOM Stage 2");
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
            utestGet(PORT);
        }
        System.out.println("Free = " + Runtime.getRuntime().freeMemory()
                + " total = " + Runtime.getRuntime().totalMemory() + " max = "
                + Runtime.getRuntime().maxMemory());
        System.err.println("OOM Stage 3");
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
            utestChildren(PORT);
        }
        System.out.println("Free = " + Runtime.getRuntime().freeMemory()
                + " total = " + Runtime.getRuntime().totalMemory() + " max = "
                + Runtime.getRuntime().maxMemory());
        hog.get(0)[0] = (byte) 1;

        f.shutdown();
        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
View Full Code Here

        File tmpDir = ClientBase.createTmpDir();
        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
        SyncRequestProcessor.setSnapCount(100);
        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ",
                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
        try {
            for (int i = 0; i< 2000; i++) {
                zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                        CreateMode.PERSISTENT);
            }
        } finally {
            zk.close();
        }
        f.shutdown();
        Assert.assertTrue("waiting for server to shutdown",
                ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));

        // start server again
        zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
View Full Code Here

        qb.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]);
        ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1);

        factory.startup(zks);
        System.out.println("Comment: starting factory");
        Assert.assertTrue("waiting for server up",
                   ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                           QuorumTest.CONNECTION_TIMEOUT));
        factory.shutdown();
        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                QuorumTest.CONNECTION_TIMEOUT));
        System.out.println("Comment: shutting down standalone");
    }
View Full Code Here

        this.tickTime = tickTime;
    }

    /** Maximum number of connections allowed from particular host (ip) */
    public int getMaxClientCnxnsPerHost() {
        ServerCnxnFactory fac = getCnxnFactory();
        if (fac == null) {
            return -1;
        }
        return fac.getMaxClientCnxnsPerHost();
    }
View Full Code Here

        File tmpDir = ClientBase.createTmpDir();
        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
        SyncRequestProcessor.setSnapCount(100);
        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ",
                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
        zks.sessionTracker = new MySessionTracker();
        PrepRequestProcessor processor = new PrepRequestProcessor(zks, new MyRequestProcessor());
        Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null);
View Full Code Here

        File tmpDir = ClientBase.createTmpDir();
        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
        SyncRequestProcessor.setSnapCount(100);
        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ",
                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);

        // generate some transactions that will get logged
        try {
            for (int i = 0; i< NUM_MESSAGES; i++) {
                zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                        CreateMode.PERSISTENT);
            }
        } finally {
            zk.close();
        }
        f.shutdown();
        Assert.assertTrue("waiting for server to shutdown",
                ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));

        // now verify that the FileTxnLog reads every transaction only once
        File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
View Full Code Here

        int oldSnapCount = SyncRequestProcessor.getSnapCount();
        SyncRequestProcessor.setSnapCount(1000);
        try {
            final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
            ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
            f.startup(zks);
            LOG.info("starting up the the server, waiting");

            Assert.assertTrue("waiting for server up",
                       ClientBase.waitForServerUp(HOSTPORT,
                                       CONNECTION_TIMEOUT));

            startSignal = new CountDownLatch(1);
            ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
            startSignal.await(CONNECTION_TIMEOUT,
                    TimeUnit.MILLISECONDS);
            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
            String path;
            LOG.info("starting creating nodes");
            for (int i = 0; i < 10; i++) {
                path = "/" + i;
                zk.create(path,
                          (path + "!").getBytes(),
                          Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                for (int j = 0; j < 10; j++) {
                    String subpath = path + "/" + j;
                    zk.create(subpath, (subpath + "!").getBytes(),
                            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                    for (int k = 0; k < 20; k++) {
                        String subsubpath = subpath + "/" + k;
                        zk.create(subsubpath, (subsubpath + "!").getBytes(),
                                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                    }
                }
            }

            f.shutdown();
            Assert.assertTrue("waiting for server down",
                       ClientBase.waitForServerDown(HOSTPORT,
                                          CONNECTION_TIMEOUT));

            zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
            f = ServerCnxnFactory.createFactory(PORT, -1);

            startSignal = new CountDownLatch(1);

            f.startup(zks);

            Assert.assertTrue("waiting for server up",
                       ClientBase.waitForServerUp(HOSTPORT,
                                           CONNECTION_TIMEOUT));

            startSignal.await(CONNECTION_TIMEOUT,
                    TimeUnit.MILLISECONDS);
            Assert.assertTrue("count == 0", startSignal.getCount() == 0);

            Stat stat = new Stat();
            for (int i = 0; i < 10; i++) {
                path = "/" + i;
                LOG.info("Checking " + path);
                Assert.assertEquals(new String(zk.getData(path, false, stat)), path
                        + "!");
                for (int j = 0; j < 10; j++) {
                    String subpath = path + "/" + j;
                    Assert.assertEquals(new String(zk.getData(subpath, false, stat)),
                            subpath + "!");
                    for (int k = 0; k < 20; k++) {
                        String subsubpath = subpath + "/" + k;
                        Assert.assertEquals(new String(zk.getData(subsubpath, false,
                                stat)), subsubpath + "!");
                    }
                }
            }
            f.shutdown();

            Assert.assertTrue("waiting for server down",
                       ClientBase.waitForServerDown(HOSTPORT,
                                          ClientBase.CONNECTION_TIMEOUT));

            zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
            f = ServerCnxnFactory.createFactory(PORT, -1);

            startSignal = new CountDownLatch(1);

            f.startup(zks);

            Assert.assertTrue("waiting for server up",
                       ClientBase.waitForServerUp(HOSTPORT,
                               CONNECTION_TIMEOUT));

            startSignal.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
            Assert.assertTrue("count == 0", startSignal.getCount() == 0);

            stat = new Stat();
            LOG.info("Check 2");
            for (int i = 0; i < 10; i++) {
                path = "/" + i;
                Assert.assertEquals(new String(zk.getData(path, false, stat)),
                             path + "!");
                for (int j = 0; j < 10; j++) {
                    String subpath = path + "/" + j;
                    Assert.assertEquals(new String(zk.getData(subpath, false, stat)),
                            subpath + "!");
                    for (int k = 0; k < 20; k++) {
                        String subsubpath = subpath + "/" + k;
                        Assert.assertEquals(new String(zk.getData(subsubpath, false,
                                stat)), subsubpath + "!");
                    }
                }
            }
            zk.close();

            f.shutdown();

            Assert.assertTrue("waiting for server down",
                       ClientBase.waitForServerDown(HOSTPORT,
                                                    CONNECTION_TIMEOUT));
        } finally {
View Full Code Here

    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(10000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ", ClientBase
        .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);

    long start = System.currentTimeMillis();
    while (!connected) {
      long end = System.currentTimeMillis();
      if (end - start > 5000) {
        Assert.assertTrue("Could not connect with server in 5 seconds",
            false);
      }
      try {
        Thread.sleep(200);
      } catch (Exception e) {
        LOG.warn("Intrrupted");
      }

    }
    // generate some transactions
    String lastPath = null;
    try {
      zk.create("/invalidsnap", new byte[0], Ids.OPEN_ACL_UNSAFE,
          CreateMode.PERSISTENT);
      for (int i = 0; i < NUM_MESSAGES; i++) {
        lastPath = zk.create("/invalidsnap/test-", new byte[0],
            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
      }
    } finally {
      zk.close();
    }
    String[] tokens = lastPath.split("-");
    String expectedPath = "/invalidsnap/test-"
        + String.format("%010d",
            (new Integer(tokens[1])).intValue() + 1);
    long eZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid();
    // force the zxid to be behind the content
    zks.getZKDatabase().setlastProcessedZxid(
        zks.getZKDatabase().getDataTreeLastProcessedZxid() - 10);
    LOG.info("Set lastProcessedZxid to "
        + zks.getZKDatabase().getDataTreeLastProcessedZxid());
    // Force snapshot and restore
    zks.takeSnapshot();
    zks.shutdown();
    f.shutdown();

    zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(10000);
    f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ", ClientBase
        .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    connected = false;
    long fZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid();

    // Verify lastProcessedZxid is set correctly
    Assert.assertTrue("Restore failed expected zxid=" + eZxid + " found="
        + fZxid, fZxid == eZxid);
    zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    start = System.currentTimeMillis();
    while (!connected) {
      long end = System.currentTimeMillis();
      if (end - start > 5000) {
        Assert.assertTrue("Could not connect with server in 5 seconds",
            false);
      }
      try {
        Thread.sleep(200);
      } catch (Exception e) {
        LOG.warn("Intrrupted");
      }

    }
    // Verify correctness of data and whether sequential znode creation
    // proceeds correctly after this point
    String[] children;
    String path;
    try {
      children = zk.getChildren("/invalidsnap", false).toArray(
          new String[0]);
      path = zk.create("/invalidsnap/test-", new byte[0],
          Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
    } finally {
      zk.close();
    }
    LOG.info("Expected " + expectedPath + " found " + path);
    Assert.assertTrue("Error in sequential znode creation expected "
        + expectedPath + " found " + path, path.equals(expectedPath));
    Assert.assertTrue("Unexpected number of children " + children.length
        + " expected " + NUM_MESSAGES,
        (children.length == NUM_MESSAGES));
    f.shutdown();
  }
View Full Code Here

        File tmpDir = ClientBase.createTmpDir();
        ClientBase.setupTestEnv();
        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
        SyncRequestProcessor.setSnapCount(10000);
        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ", ClientBase
                .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);

        long start = System.currentTimeMillis();
        while (!connected) {
            long end = System.currentTimeMillis();
            if (end - start > 5000) {
                Assert.assertTrue("Could not connect with server in 5 seconds",
                        false);
            }
            try {
                Thread.sleep(200);
            } catch (Exception e) {
                LOG.warn("Intrrupted");
            }

        }
        // generate some transactions
        try {
            for (int i = 0; i < NUM_MESSAGES; i++) {
                try {
                    zk.create("/invaliddir/test-", new byte[0],
                            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
                } catch(NoNodeException e) {
                    //Expected
                }
            }
        } finally {
            zk.close();
        }

        // force the zxid to be behind the content
        zks.getZKDatabase().setlastProcessedZxid(
                zks.getZKDatabase().getDataTreeLastProcessedZxid() - 10);
        LOG.info("Set lastProcessedZxid to "
                + zks.getZKDatabase().getDataTreeLastProcessedZxid());
       
        // Force snapshot and restore
        zks.takeSnapshot();
        zks.shutdown();
        f.shutdown();

        zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
        SyncRequestProcessor.setSnapCount(10000);
        f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ", ClientBase
                .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
       
        f.shutdown();
    }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.server.ServerCnxnFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.