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


Java ClientBase.waitForServerUp方法代码示例

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


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

示例1: testSaslRequiredInvalidCredentials

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Test to verify that server shouldn't start with invalid credentials
 * if the configuration is set to quorum.auth.serverRequireSasl=true,
 * quorum.auth.learnerRequireSasl=true
 */
@Test(timeout = 30000)
public void testSaslRequiredInvalidCredentials() 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, "true");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
    int serverCount = 2;
    final int[] clientPorts = startQuorum(serverCount, 0,
            new StringBuilder(), authConfigs, serverCount, false);
    for (int i = 0; i < serverCount; i++) {
        boolean waitForServerUp = ClientBase.waitForServerUp(
                "127.0.0.1:" + clientPorts[i], QuorumPeerTestBase.TIMEOUT);
        Assert.assertFalse("Shouldn't start server with invalid credentials",
                waitForServerUp);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:QuorumDigestAuthTest.java

示例2: testBadPeerAddressInQuorum

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Verify handling of bad quorum address
 */
@Test
public void testBadPeerAddressInQuorum() throws Exception {
    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
        Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setThreshold(Level.WARN);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
            "server.1=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique()
            + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique()
            + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
            ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                    30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
        Pattern.compile(".*Cannot open channel to .* at election address .*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about host", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例3: testInvalidIpv6AddressInQuorum

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Test
public void testInvalidIpv6AddressInQuorum() throws Exception {
    assumeIPv6Available();

    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();

        String quorumCfgSection =
                "server.1=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique()
                + "\nserver.2=[0:0:0:0:0:0:0:1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*QuorumPeerConfig\\$ConfigException.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about configuration", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例4: testBadPeerAddressInQuorum

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Verify handling of bad quorum address
 */
@Test
public void testBadPeerAddressInQuorum() throws Exception {
    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setThreshold(Level.WARN);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
            "server.1=127.0.0.1:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1
            + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique()
            + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*Cannot open channel to .* at election address .*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about host", found);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:59,代码来源:QuorumPeerMainTest.java

示例5: testNonAuthEnabledObserverJoiningAuthEnabledQuorum

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Test to verify that non-auth enabled Observer server should be rejected
 * by the auth enabled quorum servers.
 */
@Test(timeout = 30000)
public void testNonAuthEnabledObserverJoiningAuthEnabledQuorum()
        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 3-node cluster.
    int totalServerCount = 3;
    String connectStr = startQuorum(totalServerCount, authConfigs,
            totalServerCount, false);

    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_SEQUENTIAL);

    // Adding a non-auth enabled Observer to the 3-node auth cluster.
    String quorumCfgSection = mt.get(0).getQuorumCfgSection();
    int observerMyid = totalServerCount + 1;
    StringBuilder newObsCfgSection = new StringBuilder(quorumCfgSection);
    newObsCfgSection.append("\n");
    newObsCfgSection.append(String.format(
            "server.%d=localhost:%d:%d:observer", observerMyid,
            PortAssignment.unique(), PortAssignment.unique()));
    newObsCfgSection.append("\npeerType=observer");
    newObsCfgSection.append("\n");
    int clientPort = PortAssignment.unique();
    newObsCfgSection.append("127.0.0.1:" + clientPort);
    MainThread mthread = new MainThread(observerMyid, clientPort,
            newObsCfgSection.toString());
    mt.add(mthread);
    mthread.start();

    boolean waitForServerUp = ClientBase.waitForServerUp(
            "127.0.0.1:" + clientPort, QuorumPeerTestBase.TIMEOUT);
    Assert.assertFalse(
            "Non-auth enabled Observer shouldn't be able join auth-enabled quorum",
            waitForServerUp);

    // quorum shouldn't be disturbed due to rejection.
    zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT_SEQUENTIAL);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:52,代码来源:QuorumDigestAuthTest.java


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