Examples of CountdownWatcher


Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

     * Basic test of read-only client functionality. Tries to read and write
     * during read-only mode, then regains a quorum and tries to write again.
     */
    @Test(timeout = 90000)
    public void testReadOnlyClient() throws Exception {
        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
                watcher, true);
        watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected

        final String data = "Data to be read in RO mode";
        final String node = "/tnode";
        zk.create(node, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);

        watcher.reset();
        qu.shutdown(2);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        // read operation during r/o mode
        String remoteData = new String(zk.getData(node, false, null));
        Assert.assertEquals(data, remoteData);

        try {
            zk.setData(node, "no way".getBytes(), -1);
            Assert.fail("Write operation has succeeded during RO mode");
        } catch (NotReadOnlyException e) {
            // ok
        }

        watcher.reset();
        qu.start(2);
        Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
                "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
        watcher.waitForConnected(CONNECTION_TIMEOUT);
        zk.setData(node, "We're in the quorum now".getBytes(), -1);

        zk.close();
    }
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

     */
    @Test(timeout = 90000)
    public void testSessionEstablishment() throws Exception {
        qu.shutdown(2);

        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
                watcher, true);
        watcher.waitForConnected(CONNECTION_TIMEOUT);
        Assert.assertSame("should be in r/o mode", States.CONNECTEDREADONLY, zk
                .getState());
        long fakeId = zk.getSessionId();

        watcher.reset();
        qu.start(2);
        Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
                "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
        watcher.waitForConnected(CONNECTION_TIMEOUT);
        zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
        Assert.assertFalse("fake session and real session have same id", zk
                .getSessionId() == fakeId);

View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

        Logger zlogger = Logger.getLogger("org.apache.zookeeper");
        zlogger.addAppender(appender);

        try {
            qu.shutdown(2);
            CountdownWatcher watcher = new CountdownWatcher();
            ZooKeeper zk = new ZooKeeper(qu.getConnString(),
                    CONNECTION_TIMEOUT, watcher, true);
            watcher.waitForConnected(CONNECTION_TIMEOUT);

            // if we don't suspend a peer it will rejoin a quorum
            qu.getPeer(1).peer.suspend();

            // start two servers to form a quorum; client should detect this and
            // connect to one of them
            watcher.reset();
            qu.start(2);
            qu.start(3);
            ClientBase.waitForServerUp(qu.getConnString(), 2000);
            watcher.waitForConnected(CONNECTION_TIMEOUT);
            zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);

            // resume poor fellow
            qu.getPeer(1).peer.resume();
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

            super(name);
        }

        public void run() {
            try {
                CountdownWatcher watcher = new CountdownWatcher();
                zk = new TestableZooKeeper(qb.hostPort, CONNECTION_TIMEOUT,
                        watcher);
                watcher.waitForConnected(CONNECTION_TIMEOUT);
                while(bang) {
                    incOutstanding(); // before create otw race
                    zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE,
                            CreateMode.PERSISTENT_SEQUENTIAL, this, null);
                }
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

        Assert.assertFalse("No leader in quorum?", leaderIdx == -1);
        int followerIdx = (leaderIdx + 1) % 5;
        int testPeerIdx = testLeader ? leaderIdx : followerIdx;
        String hostPorts[] = qb.hostPort.split(",");

        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = qb.createClient(watcher, hostPorts[testPeerIdx],
                                       CONNECTION_TIMEOUT);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        long localSessionId = zk.getSessionId();

        // Try creating some data.
        for (int i = 0; i < 5; i++) {
            zk.create(nodePrefix + i, new byte[0],
                      ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }

        // Now, try an ephemeral node.  This should fail since we
        // cannot create ephemeral nodes on a local session.
        try {
            zk.create(nodePrefix + "ephemeral", new byte[0],
                      ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
            Assert.fail("Ephemeral node creation should fail.");
        } catch (KeeperException.EphemeralOnLocalSessionException e) {
        }

        // Close the session.
        zk.close();

        // Validate data on both follower and leader
        HashMap<String, Integer> peers = new HashMap<String, Integer>();
        peers.put("leader", leaderIdx);
        peers.put("follower", followerIdx);
        for (Entry<String, Integer> entry: peers.entrySet()) {
            watcher.reset();
            // Try reconnecting with a new session.
            // The data should be persisted, even though the session was not.
            zk = qb.createClient(watcher, hostPorts[entry.getValue()],
                                 CONNECTION_TIMEOUT);
            watcher.waitForConnected(CONNECTION_TIMEOUT);

            long newSessionId = zk.getSessionId();
            Assert.assertFalse(newSessionId == localSessionId);

            for (int i = 0; i < 5; i++) {
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

        ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
        f.startup(zks);
        Assert.assertTrue("waiting for server being up ", ClientBase
                .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));

        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        List<String> joiners = new ArrayList<String>();
        joiners.add("server.2=localhost:1234:1235;1236");
        // generate some transactions that will get logged
        try {
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

     * See ZOOKEEPER-790 for details
     * */
    @Test
    public void testFollowersStartAfterLeader() throws Exception {
        QuorumUtil qu = new QuorumUtil(1);
        CountdownWatcher watcher = new CountdownWatcher();
        qu.startQuorum();

        int index = 1;
        while(qu.getPeer(index).peer.leader == null)
            index++;

        // break the quorum
        qu.shutdown(index);
       
        // try to reestablish the quorum
        qu.start(index);
       
        // Connect the client after services are restarted (otherwise we would get
        // SessionExpiredException as the previous local session was not persisted).
        ZooKeeper zk = new ZooKeeper(
                "127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(),
                ClientBase.CONNECTION_TIMEOUT, watcher);

        try{
            watcher.waitForConnected(CONNECTION_TIMEOUT);     
        } catch(TimeoutException e) {
            Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds.");
        }

        zk.close();
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

     * Without the fix in ZOOKEEPER-1124, this fails with a ConnectionLoss KeeperException.
     */
    @Test
    public void testMultiToFollower() throws Exception {
        QuorumUtil qu = new QuorumUtil(1);
        CountdownWatcher watcher = new CountdownWatcher();
        qu.startQuorum();

        int index = 1;
        while(qu.getPeer(index).peer.leader == null)
            index++;

        ZooKeeper zk = new ZooKeeper(
                "127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(),
                ClientBase.CONNECTION_TIMEOUT, watcher);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        zk.multi(Arrays.asList(
                Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
                Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
                Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

     *
     * @throws Exception
     */
    @Test
    public void testLaggingFollowerResyncsUnderNewEpoch() throws Exception {
        CountdownWatcher watcher1 = new CountdownWatcher();
        CountdownWatcher watcher2 = new CountdownWatcher();
        CountdownWatcher watcher3 = new CountdownWatcher();

        QuorumUtil qu = new QuorumUtil(1);
        qu.shutdownAll();

        qu.start(1);
View Full Code Here

Examples of org.apache.zookeeper.test.ClientBase.CountdownWatcher

    {
        final Semaphore sem = new Semaphore(0);

        QuorumUtil qu = new QuorumUtil(1);
        qu.startAll();
        CountdownWatcher watcher1 = new CountdownWatcher();
        CountdownWatcher watcher2 = new CountdownWatcher();
        CountdownWatcher watcher3 = new CountdownWatcher();

        int index = 1;
        while(qu.getPeer(index).peer.leader == null) {
            index++;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.