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


Java CountdownWatcher类代码示例

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


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

示例1: setUp

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    LOG.info("STARTING " + getName());

    // set the snap count to something low so that we force log rollover
    // and verify that is working as part of the epoch rollover.
    SyncRequestProcessor.setSnapCount(7);

    qu = new QuorumUtil(1);
    startAll();

    for (int i = 0; i < zkClients.length; i++) {
        zkClientWatchers[i] = new CountdownWatcher();
        PeerStruct peer = qu.getPeer(i + 1);
        zkClients[i] = new ZooKeeper(
                "127.0.0.1:" + peer.clientPort,
                ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
    }
    waitForClientsConnected();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:21,代码来源:ZxidRolloverTest.java

示例2: 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:maoling,项目名称:fuck_zookeeper,代码行数:30,代码来源:ReadOnlyModeTest.java

示例3: setUp

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    System.setProperty("zookeeper.admin.enableServer", "false");

    // set the snap count to something low so that we force log rollover
    // and verify that is working as part of the epoch rollover.
    SyncRequestProcessor.setSnapCount(7);

    qu = new QuorumUtil(1);
    startAll();

    for (int i = 0; i < zkClients.length; i++) {
        zkClientWatchers[i] = new CountdownWatcher();
        PeerStruct peer = qu.getPeer(i + 1);
        zkClients[i] = new ZooKeeper(
                "127.0.0.1:" + peer.clientPort,
                ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
    }
    waitForClientsConnected();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:21,代码来源:ZxidRolloverTest.java

示例4: testAuthLearnerServer

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=true, quorum.auth.serverRequireSasl=true
 * peer1 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
 */
@Test(timeout = 30000)
public void testAuthLearnerServer() 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(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,代码行数:22,代码来源:QuorumAuthUpgradeTest.java

示例5: testValidCredentials

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
 * Test to verify that server is able to start with valid credentials
 */
@Test(timeout = 30000)
public void testValidCredentials() 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);
    for (int i = 0; i < 10; i++) {
        zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:QuorumDigestAuthTest.java

示例6: 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

示例7: testObserverWithValidCredentials

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
 * Test to verify that Observer server is able to join quorum.
 */
@Test(timeout = 30000)
public void testObserverWithValidCredentials() 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");

    // Starting auth enabled 5-node cluster. 3-Participants and 2-Observers.
    int totalServerCount = 5;
    int observerCount = 2;
    String connectStr = startQuorum(totalServerCount, observerCount,
            authConfigs, totalServerCount);
    CountdownWatcher watcher = new CountdownWatcher();
    zk = new ZooKeeper(connectStr.toString(), ClientBase.CONNECTION_TIMEOUT,
            watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:QuorumDigestAuthTest.java

示例8: 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

示例9: 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 = KerberosTestUtils.getServerPrincipal();
    serverPrincipal = serverPrincipal.substring(0, serverPrincipal.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,代码行数:22,代码来源:QuorumKerberosAuthTest.java

示例10: 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

示例11: setUp

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    LOG.info("STARTING " + getName());

    // set the snap count to something low so that we force log rollover
    // and verify that is working as part of the epoch rollover.
    SyncRequestProcessor.setSnapCount(7);

    qu = new QuorumUtil(1);
    startAll();

    for (int i = 0; i < zkClients.length; i++) {
        zkClientWatchers[i] = new CountdownWatcher();
        int followerPort = qu.getPeer(i+1).peer.getClientPort();
        zkClients[i] = new ZooKeeper(
                "127.0.0.1:" + followerPort,
                ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
    }
    waitForClients();
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:21,代码来源:ZxidRolloverTest.java

示例12: createClient

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
private static DisconnectableZooKeeper createClient(int port,
        CountdownWatcher watcher)
    throws IOException, TimeoutException, InterruptedException
{
    DisconnectableZooKeeper zk = new DisconnectableZooKeeper(
            "127.0.0.1:" + port, ClientBase.CONNECTION_TIMEOUT, watcher);

    watcher.waitForConnected(CONNECTION_TIMEOUT);
    return zk;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:11,代码来源:FollowerResyncConcurrencyTest.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:maoling,项目名称:fuck_zookeeper,代码行数:11,代码来源:FollowerResyncConcurrencyTest.java

示例14: testMultiTransaction

import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
 * Test write operations using multi request.
 */
@Test(timeout = 90000)
public void testMultiTransaction() 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 node1 = "/tnode1";
    final String node2 = "/tnode2";
    zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    watcher.reset();
    qu.shutdown(2);
    watcher.waitForConnected(CONNECTION_TIMEOUT);
    Assert.assertEquals("Should be in r-o mode", States.CONNECTEDREADONLY,
            zk.getState());

    // read operation during r/o mode
    String remoteData = new String(zk.getData(node1, false, null));
    Assert.assertEquals("Failed to read data in r-o mode", data, remoteData);

    try {
        Transaction transaction = zk.transaction();
        transaction.setData(node1, "no way".getBytes(), -1);
        transaction.create(node2, data.getBytes(),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        transaction.commit();
        Assert.fail("Write operation using multi-transaction"
                + " api has succeeded during RO mode");
    } catch (NotReadOnlyException e) {
        // ok
    }

    Assert.assertNull("Should have created the znode:" + node2,
            zk.exists(node2, false));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:42,代码来源:ReadOnlyModeTest.java

示例15: 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:maoling,项目名称:fuck_zookeeper,代码行数:41,代码来源:ReadOnlyModeTest.java


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