Package org.apache.zookeeper

Examples of org.apache.zookeeper.TestableZooKeeper


    protected TestableZooKeeper createClient(CountdownWatcher watcher,
            String hp, int timeout)
        throws IOException, InterruptedException
    {
        watcher.reset();
        TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
        if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS))
        {
            fail("Unable to connect to server");
        }
        synchronized(this) {
            if (!allClientsSetup) {
                LOG.error("allClients never setup");
                fail("allClients never setup");
            }
            if (allClients != null) {
                allClients.add(zk);
            } else {
                // test done - close the zk, not needed
                zk.close();
            }
        }

        JMXEnv.ensureAll("0x" + Long.toHexString(zk.getSessionId()));

        return zk;
    }
View Full Code Here


        verify("stat", "Outstanding");
        verify("srvr", "Outstanding");
        verify("cons", "queued");

        TestableZooKeeper zk = createClient();
        String sid = "0x" + Long.toHexString(zk.getSessionId());

        verify("stat", "queued");
        verify("srvr", "Outstanding");
        verify("cons", sid);
        verify("dump", sid);

        zk.getData("/", true, null);

        verify("stat", "queued");
        verify("srvr", "Outstanding");
        verify("cons", sid);
        verify("dump", sid);

        verify("wchs", "watching 1");
        verify("wchp", sid);
        verify("wchc", sid);
        zk.close();

        verify("ruok", "imok");
        verify("envi", "java.version");
        verify("conf", "clientPort");
        verify("stat", "Outstanding");
View Full Code Here

        while(qu.getPeer(index).peer.follower == null) {
            index++;
        }
        LOG.info("Connecting to follower:" + index);

        TestableZooKeeper zk =
                createClient("localhost:" + qu.getPeer(index).peer.getClientPort());

        assertEquals(0L, zk.testableLastZxid());
        zk.exists("/", false);
        long lzxid = zk.testableLastZxid();
        assertTrue("lzxid:" + lzxid + " > 0", lzxid > 0);
        zk.close();
    }
View Full Code Here

        while(qu.getPeer(index).peer.follower == null) {
            index++;
        }
        LOG.info("Connecting to follower:" + index);

        TestableZooKeeper zk1 = createClient(
                "localhost:" + qu.getPeer(index).peer.getClientPort());
        zk1.create("/foo", "foo".getBytes(), Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);

        MyWatcher watcher = new MyWatcher();
        TestableZooKeeper zk2 = createClient(watcher,
                "localhost:" + qu.getPeer(index).peer.getClientPort());

        zk2.exists("/foo", true);

        watcher.reset();
        zk2.testableConnloss();
        if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
        {
            fail("Unable to connect to server");
        }
        assertArrayEquals("foo".getBytes(), zk2.getData("/foo", false, null));

        assertNull(watcher.events.poll(5, TimeUnit.SECONDS));

        zk1.close();
        zk2.close();
    }
View Full Code Here

            verify(hp, "stat", "Outstanding");
            verify(hp, "srvr", "Outstanding");
            verify(hp, "cons", "queued");

            TestableZooKeeper zk = createClient(hp);
            String sid = "0x" + Long.toHexString(zk.getSessionId());

            verify(hp, "stat", "queued");
            verify(hp, "srvr", "Outstanding");
            verify(hp, "cons", sid);
            verify(hp, "dump", sid);

            zk.getData("/", true, null);

            verify(hp, "stat", "queued");
            verify(hp, "srvr", "Outstanding");
            verify(hp, "cons", sid);
            verify(hp, "dump", sid);
            verify(hp, "wchs", "watching 1");
            verify(hp, "wchp", sid);
            verify(hp, "wchc", sid);

            zk.close();

            verify(hp, "ruok", "imok");
            verify(hp, "envi", "java.version");
            verify(hp, "conf", "clientPort");
            verify(hp, "stat", "Outstanding");
View Full Code Here

    public void testWatchAutoResetWithPending() throws Exception {
       MyWatcher watches[] = new MyWatcher[COUNT];
       MyStatCallback cbs[] = new MyStatCallback[COUNT];
       MyWatcher watcher = new MyWatcher();
       int count[] = new int[1];
       TestableZooKeeper zk = createClient(watcher, hostPort);
       ZooKeeper zk2 = createClient(watcher, hostPort);
       zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
       for(int i = 0; i < COUNT/2; i++) {
           watches[i] = new MyWatcher();
           cbs[i] = new MyStatCallback();
           zk.exists("/test", watches[i], cbs[i], count);
       }
       zk.exists("/test", false);
       zk.pauseCnxn(4000);
       Thread.sleep(50);
       zk2.close();
       stopServer();
       watches[0].waitForDisconnected(3000);
       for(int i = COUNT/2; i < COUNT; i++) {
           watches[i] = new MyWatcher();
           cbs[i] = new MyStatCallback();
           zk.exists("/test", watches[i], cbs[i], count);
       }
       startServer();
       watches[49].waitForConnected(4000);
       assertEquals(null, zk.exists("/test", false));
       Thread.sleep(10);
       for(int i = 0; i < COUNT/2; i++) {
           assertEquals("For " + i, 1, watches[i].events.size());
       }
       for(int i = COUNT/2; i < COUNT; i++) {
           if (cbs[i].rc == 0) {
               assertEquals("For " +i, 1, watches[i].events.size());
           } else {
               assertEquals("For " +i, 0, watches[i].events.size());
           }
       }
       assertEquals(COUNT, count[0]);
       zk.close();
    }
View Full Code Here

    }

    protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
        throws IOException, InterruptedException
    {
        TestableZooKeeper zk = new TestableZooKeeper(hp, 9000, watcher);
        if (!watcher.clientConnected.await(CONNECTION_TIMEOUT,
                TimeUnit.MILLISECONDS))
        {
            fail("Unable to connect to server");
        }
View Full Code Here

    }

    /** Exercise the testable functions, verify tostring, etc... */
    @Test
    public void testTestability() throws Exception {
        TestableZooKeeper zk = createClient();
        try {
            LOG.info(zk.testableLocalSocketAddress());
            LOG.info(zk.testableRemoteSocketAddress());
            LOG.info(zk.toString());
        } finally {
            zk.close();
            zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
            LOG.info(zk.testableLocalSocketAddress());
            LOG.info(zk.testableRemoteSocketAddress());
            LOG.info(zk.toString());
        }
    }
View Full Code Here

        }

        public void run() {
            try {
                for (; current < count; current++) {
                    TestableZooKeeper zk = createClient();
                    zk.close();
                    // we've asked to close, wait for it to finish closing
                    // all the sub-threads otw the selector may not be
                    // closed when we check (false positive on test failure
                    zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
                }
            } catch (Throwable t) {
                LOG.error("test failed", t);
            }
        }
View Full Code Here

    protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
        throws IOException, InterruptedException
    {
        watcher.reset();
        TestableZooKeeper zk =
            new TestableZooKeeper(hp, CONNECTION_TIMEOUT, watcher);
        if (!watcher.clientConnected.await(CONNECTION_TIMEOUT,
                TimeUnit.MILLISECONDS))
        {
            fail("Unable to connect to server");
        }
        JMXEnv.ensureAll("0x" + Long.toHexString(zk.getSessionId()));

        return zk;
    }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.TestableZooKeeper

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.