Search in sources :

Example 1 with TestableZooKeeper

use of org.apache.zookeeper.TestableZooKeeper in project hadoop by apache.

the class ClientBaseWithFixes method createClient.

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)) {
        Assert.fail("Unable to connect to server");
    }
    synchronized (this) {
        if (!allClientsSetup) {
            LOG.error("allClients never setup");
            Assert.fail("allClients never setup");
        }
        if (allClients != null) {
            allClients.add(zk);
        } else {
            // test done - close the zk, not needed
            zk.close();
        }
    }
    watcher.initializeWatchedClient(zk);
    return zk;
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper)

Example 2 with TestableZooKeeper

use of org.apache.zookeeper.TestableZooKeeper in project zookeeper by apache.

the class ClientBase method createClient.

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)) {
        Assert.fail("Unable to connect to server");
    }
    synchronized (this) {
        if (!allClientsSetup) {
            LOG.error("allClients never setup");
            Assert.fail("allClients never setup");
        }
        if (allClients != null) {
            allClients.add(zk);
            JMXEnv.ensureAll(getHexSessionId(zk.getSessionId()));
        } else {
            // test done - close the zk, not needed
            zk.close();
        }
    }
    return zk;
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper)

Example 3 with TestableZooKeeper

use of org.apache.zookeeper.TestableZooKeeper in project zookeeper by apache.

the class FourLetterWordsQuorumTest method testFourLetterWords.

/** Test the various four letter words */
@Test
public void testFourLetterWords() throws Exception {
    String[] servers = hostPort.split(",");
    for (String hp : servers) {
        verify(hp, "ruok", "imok");
        verify(hp, "envi", "java.version");
        verify(hp, "conf", "clientPort");
        verify(hp, "stat", "Outstanding");
        verify(hp, "srvr", "Outstanding");
        verify(hp, "cons", "queued");
        verify(hp, "dump", "Session");
        verify(hp, "wchs", "watches");
        verify(hp, "wchp", "");
        verify(hp, "wchc", "");
        verify(hp, "srst", "reset");
        verify(hp, "crst", "reset");
        verify(hp, "stat", "Outstanding");
        verify(hp, "srvr", "Outstanding");
        verify(hp, "cons", "queued");
        TestableZooKeeper zk = createClient(hp);
        String sid = getHexSessionId(zk.getSessionId());
        verify(hp, "stat", "queued");
        verify(hp, "srvr", "Outstanding");
        verify(hp, "cons", sid);
        verify(hp, "dump", sid);
        verify(hp, "dirs", "size");
        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);
        verify(hp, "dirs", "size");
        zk.close();
        verify(hp, "ruok", "imok");
        verify(hp, "envi", "java.version");
        verify(hp, "conf", "clientPort");
        verify(hp, "stat", "Outstanding");
        verify(hp, "srvr", "Outstanding");
        verify(hp, "cons", "queued");
        verify(hp, "dump", "Session");
        verify(hp, "wchs", "watch");
        verify(hp, "wchp", "");
        verify(hp, "wchc", "");
        verify(hp, "dirs", "size");
        verify(hp, "srst", "reset");
        verify(hp, "crst", "reset");
        verify(hp, "stat", "Outstanding");
        verify(hp, "srvr", "Outstanding");
        verify(hp, "cons", "queued");
        verify(hp, "mntr", "zk_version\t");
    }
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) Test(org.junit.Test)

Example 4 with TestableZooKeeper

use of org.apache.zookeeper.TestableZooKeeper in project zookeeper by apache.

the class FourLetterWordsTest method testFourLetterWords.

/** Test the various four letter words */
@Test
public void testFourLetterWords() throws Exception {
    verify("ruok", "imok");
    verify("envi", "java.version");
    verify("conf", "clientPort");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("dump", "Session");
    verify("wchs", "watches");
    verify("wchp", "");
    verify("wchc", "");
    verify("srst", "reset");
    verify("crst", "reset");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("gtmk", "306");
    verify("isro", "rw");
    TestableZooKeeper zk = createClient();
    String sid = getHexSessionId(zk.getSessionId());
    verify("stat", "queued");
    verify("srvr", "Outstanding");
    verify("cons", sid);
    verify("dump", sid);
    verify("dirs", "size");
    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);
    verify("dirs", "size");
    zk.close();
    verify("ruok", "imok");
    verify("envi", "java.version");
    verify("conf", "clientPort");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("dump", "Session");
    verify("wchs", "watch");
    verify("wchp", "");
    verify("wchc", "");
    verify("srst", "reset");
    verify("crst", "reset");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("mntr", "zk_server_state\tstandalone");
    verify("mntr", "num_alive_connections");
    verify("stat", "Connections");
    verify("srvr", "Connections");
    verify("dirs", "size");
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) Test(org.junit.Test)

Example 5 with TestableZooKeeper

use of org.apache.zookeeper.TestableZooKeeper in project zookeeper by apache.

the class ClientTest method testNonExistingOpCode.

/**
     * We create a perfectly valid 'exists' request, except that the opcode is wrong.
     * @return
     * @throws Exception
     */
@Test
public void testNonExistingOpCode() throws Exception {
    TestableZooKeeper zk = createClient();
    final String path = "/m1";
    RequestHeader h = new RequestHeader();
    // This code does not exists
    h.setType(888);
    ExistsRequest request = new ExistsRequest();
    request.setPath(path);
    request.setWatch(false);
    ExistsResponse response = new ExistsResponse();
    ReplyHeader r = zk.submitRequest(h, request, response, null);
    Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());
    zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
}
Also used : ExistsRequest(org.apache.zookeeper.proto.ExistsRequest) ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) RequestHeader(org.apache.zookeeper.proto.RequestHeader) ExistsResponse(org.apache.zookeeper.proto.ExistsResponse) Test(org.junit.Test)

Aggregations

TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)13 Test (org.junit.Test)9 KeeperException (org.apache.zookeeper.KeeperException)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)1 ExistsResponse (org.apache.zookeeper.proto.ExistsResponse)1 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)1 RequestHeader (org.apache.zookeeper.proto.RequestHeader)1