Java 类org.apache.zookeeper.TestableZooKeeper 实例源码

项目:hadoop-oss    文件:ClientBaseWithFixes.java   
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;
}
项目:fuck_zookeeper    文件:ClientTest.java   
/** 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());
    }
}
项目:fuck_zookeeper    文件:ClientTest.java   
/**
 * 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();
    h.setType(888);  // This code does not exists
    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());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:fuck_zookeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
}
项目:fuck_zookeeper    文件:ClientBase.java   
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;
}
项目:fuck_zookeeper    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:https-github.com-apache-zookeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
    qu.shutdownAll();
}
项目:https-github.com-apache-zookeeper    文件:FourLetterWordsWhiteListTest.java   
@Test(timeout=30000)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
    stopServer();
    FourLetterCommands.resetWhiteList();
    System.setProperty("zookeeper.4lw.commands.whitelist", "stat");
    startServer();

    // Default white list for 3.5.x is empty, so all command should fail.
    verifyAllCommandsFail();

    TestableZooKeeper zk = createClient();

    verifyAllCommandsFail();

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

    verifyAllCommandsFail();

    zk.close();

    verifyFuzzyMatch("stat", "Outstanding");
    verifyAllCommandsFail();
}
项目:https-github.com-apache-zookeeper    文件:ClientBase.java   
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;
}
项目:https-github.com-apache-zookeeper    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:hadoop    文件:ClientBaseWithFixes.java   
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;
}
项目:ZooKeeper    文件:ClientTest.java   
/** 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());
    }
}
项目:ZooKeeper    文件:ClientTest.java   
/**
 * 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();
    h.setType(888);  // This code does not exists
    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());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:ZooKeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
}
项目:ZooKeeper    文件:FourLetterWordsWhiteListTest.java   
@Test(timeout=30000)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
    stopServer();
    ServerCnxn.resetWhiteList();
    System.setProperty("zookeeper.4lw.commands.whitelist", "stat");
    startServer();

    // Default white list for 3.5.x is empty, so all command should fail.
    verifyAllCommandsFail();

    TestableZooKeeper zk = createClient();

    verifyAllCommandsFail();

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

    verifyAllCommandsFail();

    zk.close();

    verifyFuzzyMatch("stat", "Outstanding");
    verifyAllCommandsFail();
}
项目:ZooKeeper    文件:ClientBase.java   
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;
}
项目:ZooKeeper    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:aliyun-oss-hadoop-fs    文件:ClientBaseWithFixes.java   
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;
}
项目:StreamProcessingInfrastructure    文件:ClientTest.java   
/** 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());
    }
}
项目:StreamProcessingInfrastructure    文件:ClientTest.java   
/**
 * 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();
    h.setType(888);  // This code does not exists
    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());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:SecureKeeper    文件:ClientBase.java   
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;
}
项目:StreamProcessingInfrastructure    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
}
项目:StreamProcessingInfrastructure    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:bigstreams    文件:ClientTest.java   
/** 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());
    }
}
项目:bigstreams    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
}
项目:bigstreams    文件:ClientTest.java   
/** 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());
    }
}
项目:big-c    文件:ClientBaseWithFixes.java   
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;
}
项目:zookeeper    文件:ClientTest.java   
/** 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());
    }
}
项目:zookeeper    文件:ClientTest.java   
/**
 * 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();
    h.setType(888);  // This code does not exists
    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());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:zookeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
}
项目:SecureKeeper    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:zookeeper    文件:ClientBase.java   
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;
}
项目:zookeeper    文件:SaslAuthFailDesignatedClientTest.java   
@Test
public void testAuth() throws Exception {
    // Cannot use createClient here because server may close session before 
    // JMXEnv.ensureAll is called which will fail the test case
    CountdownWatcher watcher = new CountdownWatcher();
    TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
    if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
    {
        Assert.fail("Unable to connect to server");
    }
    try {
        zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        Assert.fail("Should have gotten exception.");
    } catch (KeeperException e) {
        // ok, exception as expected.
        LOG.info("Got exception as expected: " + e);
    }
    finally {
        zk.close();
    }
}
项目:SecureKeeper    文件:ClientTest.java   
/** 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());
    }
}
项目:SecureKeeper    文件:ClientTest.java   
/**
 * 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();
    h.setType(888);  // This code does not exists
    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);
}
项目:SecureKeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerSendsLastZxid() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

    TestableZooKeeper zk =
            createTestableClient("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();
    qu.shutdownAll();
}
项目:SecureKeeper    文件:ClientBase.java   
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;
}
项目:fuck_zookeeper    文件:ClientTest.java   
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 Assert.failure
            zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
        }
    } catch (Throwable t) {
        LOG.error("test Assert.failed", t);
    }
}
项目:fuck_zookeeper    文件:FollowerResyncConcurrencyTest.java   
private static TestableZooKeeper createTestableClient(
    CountdownWatcher watcher, String hp)
    throws IOException, TimeoutException, InterruptedException
{
    TestableZooKeeper zk = new TestableZooKeeper(
            hp, ClientBase.CONNECTION_TIMEOUT, watcher);

    watcher.waitForConnected(CONNECTION_TIMEOUT);
    return zk;
}
项目:fuck_zookeeper    文件:FollowerResyncConcurrencyTest.java   
/**
 * Verify that the server is sending the proper zxid, and as a result
 * the watch doesn't fire. See ZOOKEEPER-1412.
 */
@Test
public void testFollowerWatcherResync() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

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

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

    MyWatcher watcher = new MyWatcher();
    TestableZooKeeper zk2 = createTestableClient(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();
}