当前位置: 首页>>代码示例>>Java>>正文


Java CountdownWatcher.waitForConnected方法代码示例

本文整理汇总了Java中org.apache.zookeeper.test.ClientBase.CountdownWatcher.waitForConnected方法的典型用法代码示例。如果您正苦于以下问题:Java CountdownWatcher.waitForConnected方法的具体用法?Java CountdownWatcher.waitForConnected怎么用?Java CountdownWatcher.waitForConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.test.ClientBase.CountdownWatcher的用法示例。


在下文中一共展示了CountdownWatcher.waitForConnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValidCredentials

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test to verify that server is able to start with valid credentials
 */
@Test(timeout = 120000)
public void testValidCredentials() throws Exception {
    String serverPrincipal = hostServerPrincipal.substring(0, hostServerPrincipal.lastIndexOf("@"));
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
    authConfigs.put(QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL, serverPrincipal);
    String connectStr = startQuorum(3, authConfigs, 3, true);
    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    for (int i = 0; i < 10; i++) {
        zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    zk.close();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:21,代码来源:QuorumKerberosHostBasedAuthTest.java

示例2: testSaslNotRequiredWithInvalidCredentials

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test to verify that server is able to start with invalid credentials if
 * the configuration is set to quorum.auth.serverRequireSasl=false.
 * Quorum will talk each other even if the authentication is not succeeded
 */
@Test(timeout = 30000)
public void testSaslNotRequiredWithInvalidCredentials() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearnerInvalid");
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
    String connectStr = startQuorum(3, authConfigs, 3, false);
    CountdownWatcher watcher = new CountdownWatcher();
    zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    for (int i = 0; i < 10; i++) {
        zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:21,代码来源:QuorumDigestAuthTest.java

示例3: testSessionEstablishment

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Tests a situation when client firstly connects to a read-only server and
 * then connects to a majority server. Transition should be transparent for
 * the user.
 */
@Test
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);

    zk.close();
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:30,代码来源:ReadOnlyModeTest.java

示例4: testSessionEstablishment

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Tests a situation when client firstly connects to a read-only server and
 * then connects to a majority server. Transition should be transparent for
 * the user.
 */
@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);

    zk.close();
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:30,代码来源:ReadOnlyModeTest.java

示例5: testSessionEstablishment

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Tests a situation when client firstly connects to a read-only server and
 * then connects to a majority server. Transition should be transparent for
 * the user.
 */
@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();
    LOG.info("Connected as r/o mode with state {} and session id {}",
            zk.getState(), fakeId);

    watcher.reset();
    qu.start(2);
    Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
            "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
    LOG.info("Server 127.0.0.1:{} is up", qu.getPeer(2).clientPort);
    // ZOOKEEPER-2722: wait until we can connect to a read-write server after the quorum
    // is formed. Otherwise, it is possible that client first connects to a read-only server,
    // then drops the connection because of shutting down of the read-only server caused
    // by leader election / quorum forming between the read-only server and the newly started
    // server. If we happen to execute the zk.create after the read-only server is shutdown and
    // before the quorum is formed, we will get a ConnectLossException.
    watcher.waitForSyncConnected(CONNECTION_TIMEOUT);
    Assert.assertEquals("Should be in read-write mode", States.CONNECTED,
            zk.getState());
    LOG.info("Connected as rw mode with state {} and session id {}",
            zk.getState(), zk.getSessionId());
    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);
    zk.close();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:42,代码来源:ReadOnlyModeTest.java

示例6: testRelectionWithValidCredentials

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test to verify that server is able to reform quorum if the Leader goes
 * down.
 */
@Test(timeout = 30000)
public void testRelectionWithValidCredentials() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");

    String connectStr = startQuorum(3, authConfigs, 3, false);
    CountdownWatcher watcher = new CountdownWatcher();
    zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT_SEQUENTIAL);
    watcher.reset();

    // Shutdown Leader to trigger re-election
    QuorumPeer leaderQP = getLeaderQuorumPeer(mt);
    LOG.info("Shutdown Leader sid:{} to trigger quorum leader-election",
            leaderQP.getId());
    shutdownQP(leaderQP);

    // Wait for quorum formation
    QuorumPeer newLeaderQP = waitForLeader();
    assertNotNull("New leader must have been elected by now", newLeaderQP);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT_SEQUENTIAL);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:33,代码来源:QuorumDigestAuthTest.java

示例7: testReadOnlyClient

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:41,代码来源:ReadOnlyModeTest.java

示例8: testClientConnectionRequestDuringStartupWithNIOServerCnxn

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test case for
 * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-2383}.
 */
@Test(timeout = 30000)
public void testClientConnectionRequestDuringStartupWithNIOServerCnxn()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();

    startSimpleZKServer(startupDelayLatch);
    SimpleZooKeeperServer simplezks = (SimpleZooKeeperServer) zks;
    Assert.assertTrue(
            "Failed to invoke zks#startup() method during server startup",
            simplezks.waitForStartupInvocation(10));

    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zkClient = new ZooKeeper(HOSTPORT,
            ClientBase.CONNECTION_TIMEOUT, watcher);

    Assert.assertFalse(
            "Since server is not fully started, zks#createSession() shouldn't be invoked",
            simplezks.waitForSessionCreation(5));

    LOG.info(
            "Decrements the count of the latch, so that server will proceed with startup");
    startupDelayLatch.countDown();

    Assert.assertTrue("waiting for server being up ", ClientBase
            .waitForServerUp(HOSTPORT, ClientBase.CONNECTION_TIMEOUT));

    Assert.assertTrue(
            "Failed to invoke zks#createSession() method during client session creation",
            simplezks.waitForSessionCreation(5));
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zkClient.close();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:38,代码来源:ZooKeeperServerStartupTest.java

示例9: testFollowersStartAfterLeader

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/** 
 * 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++;
    }
    
    ZooKeeper zk = new ZooKeeper(
            "127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(),
            ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(CONNECTION_TIMEOUT);
    
    // break the quorum
    qu.shutdown(index);

    // Wait until we disconnect to proceed
    watcher.waitForDisconnected(CONNECTION_TIMEOUT);
    
    // try to reestablish the quorum
    qu.start(index);

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

    zk.close();

    qu.tearDown();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:39,代码来源:FollowerTest.java

示例10: testAuthLearnerAgainstNoAuthRequiredServer

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test to verify that servers are able to form quorum.
 * peer0 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
 * peer1 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
 */
@Test(timeout = 30000)
public void testAuthLearnerAgainstNoAuthRequiredServer() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");

    String connectStr = startQuorum(2, authConfigs, 2, false);
    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT,
            watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk.close();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:QuorumAuthUpgradeTest.java

示例11: testFollowersStartAfterLeader

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/** 
 * See ZOOKEEPER-790 for details 
 * */
@Test
public void testFollowersStartAfterLeader() throws Exception {
    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();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:QuorumTest.java

示例12: testMultiToFollower

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Tests if a multiop submitted to a non-leader propagates to the leader properly
 * (see ZOOKEEPER-1124).
 * 
 * The test works as follows. It has a client connect to a follower and submit a multiop
 * to the follower. It then verifies that the multiop successfully gets committed by the leader.
 *
 * Without the fix in ZOOKEEPER-1124, this fails with a ConnectionLoss KeeperException.
 */
@Test
public void testMultiToFollower() throws Exception {
    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)
            ));
    zk.getData("/multi0", false, null);
    zk.getData("/multi1", false, null);
    zk.getData("/multi2", false, null);

    zk.close();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:36,代码来源:QuorumTest.java

示例13: createTestableClient

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
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;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:11,代码来源:FollowerResyncConcurrencyTest.java

示例14: testLocalSessionUpgrade

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
private void testLocalSessionUpgrade(boolean testLeader) throws Exception {

        int leaderIdx = qb.getLeaderIndex();
        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);

        final String firstPath = "/first";
        final String secondPath = "/ephemeral";

        // Just create some node so that we know the current zxid
        zk.create(firstPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);

        // Now, try an ephemeral node. This will trigger session upgrade
        // so there will be createSession request inject into the pipeline
        // prior to this request
        zk.create(secondPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.EPHEMERAL);

        Stat firstStat = zk.exists(firstPath, null);
        Assert.assertNotNull(firstStat);

        Stat secondStat = zk.exists(secondPath, null);
        Assert.assertNotNull(secondStat);

        long zxidDiff = secondStat.getCzxid() - firstStat.getCzxid();

        // If there is only one createSession request in between, zxid diff
        // will be exactly 2. The alternative way of checking is to actually
        // read txnlog but this should be sufficient
        Assert.assertEquals(2L, zxidDiff);

    }
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:41,代码来源:DuplicateLocalSessionUpgradeTest.java

示例15: testNullAuthLearnerServer

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入方法依赖的package包/类
/**
 * Test to verify that servers are able to start without any authentication.
 * peer0 -> quorum.auth.enableSasl=false
 * peer1 -> quorum.auth.enableSasl=false
 */
@Test(timeout = 30000)
public void testNullAuthLearnerServer() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");

    String connectStr = startQuorum(2, authConfigs, 0, false);
    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT,
            watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk.close();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:QuorumAuthUpgradeTest.java


注:本文中的org.apache.zookeeper.test.ClientBase.CountdownWatcher.waitForConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。