Package org.apache.zookeeper.server

Examples of org.apache.zookeeper.server.ServerCnxnFactory


    };
   
    @Test
    public void testTruncate() throws IOException, InterruptedException, KeeperException {
        // Prime the server that is going to come in late with 50 txns
        ServerCnxnFactory factory = ClientBase.createNewServerInstance(dataDir1, null, "127.0.0.1:" + baseHostPort, 100);
        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + baseHostPort, 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


    {
        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

    @Override
    public void blockUntilStarted() throws Exception
    {
        latch.await();

        ServerCnxnFactory cnxnFactory = getServerConnectionFactory();
        if ( cnxnFactory != null )
        {
            final ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory);
            if ( zkServer != null )
            {
View Full Code Here

    {
        shutdown();

        try
        {
            ServerCnxnFactory cnxnFactory = getServerConnectionFactory();
            if ( cnxnFactory != null )
            {
                ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory);
                if ( zkServer != null )
                {
View Full Code Here

    private ServerCnxnFactory getServerConnectionFactory() throws Exception
    {
        Field cnxnFactoryField = ZooKeeperServerMain.class.getDeclaredField("cnxnFactory");
        cnxnFactoryField.setAccessible(true);
        ServerCnxnFactory cnxnFactory;

        // Wait until the cnxnFactory field is non-null or up to 1s, whichever comes first.
        long startTime = System.currentTimeMillis();
        do
        {
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

        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);
        processor.pRequest(foo);
        testEnd.await(5, java.util.concurrent.TimeUnit.SECONDS);
        f.shutdown();
        zks.shutdown();
    }
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 = getConnectedZkClient();
    // 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 = getConnectedZkClient();
    // 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();
                zks.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.