Package org.apache.zookeeper.server

Examples of org.apache.zookeeper.server.ServerCnxnFactory


        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


    @Test
    public void testTruncate() throws IOException, InterruptedException, KeeperException {
        // Prime the server that is going to come in late with 50 txns
        String hostPort = "127.0.0.1:" + baseHostPort;
        ServerCnxnFactory factory = ClientBase.createNewServerInstance(dataDir1, null, hostPort, 100);
        ClientBase.shutdownServerInstance(factory, hostPort);

        // standalone starts with 0 epoch while quorum starts with 1
        File origfile = new File(new File(dataDir1, "version-2"), "snapshot.0");
        File newfile = new File(new File(dataDir1, "version-2"), "snapshot.100000000");
        origfile.renameTo(newfile);

        factory = ClientBase.createNewServerInstance(dataDir1, null, hostPort, 100);

        ZooKeeper zk = new ZooKeeper(hostPort, 15000, nullWatcher);
        for(int i = 0; i < 50; i++) {
            zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        zk.close();
       
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = ClientBase.getServer(factory);
   
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
View Full Code Here

    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]);
        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
        f.startup(zks);
        LOG.info("starting up the zookeeper server .. waiting");
        Assert.assertTrue("waiting for server being up",
                ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
        try {
            // we know this from the data files
            // this node is the last node in the snapshot

            Assert.assertTrue(zk.exists("/9/9/8", false) != null);
        } finally {
            zk.close();
        }
        f.shutdown();
        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown(HOSTPORT,
                           ClientBase.CONNECTION_TIMEOUT));

    }
View Full Code Here

        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

        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

        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

    @Test
    public void testTruncate() throws IOException, InterruptedException, KeeperException {
        // Prime the server that is going to come in late with 50 txns
        String hostPort = "127.0.0.1:" + baseHostPort;
        int maxCnxns = 100;
        ServerCnxnFactory factory = ClientBase.createNewServerInstance(null,
                hostPort, maxCnxns);
        ClientBase.startServerInstance(dataDir1, factory, hostPort);
        ClientBase.shutdownServerInstance(factory, hostPort);

        // standalone starts with 0 epoch while quorum starts with 1
        File origfile = new File(new File(dataDir1, "version-2"), "snapshot.0");
        File newfile = new File(new File(dataDir1, "version-2"), "snapshot.100000000");
        origfile.renameTo(newfile);

        factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns);
        ClientBase.startServerInstance(dataDir1, factory, hostPort);

        ZooKeeper zk = new ZooKeeper(hostPort, 15000, nullWatcher);
        for(int i = 0; i < 50; i++) {
            zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        zk.close();
       
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = ClientBase.getServer(factory);
   
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
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

    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

    {
        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();
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.