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


Java PortAssignment.unique方法代码示例

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


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

示例1: testObserverWithStandlone

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Ensure that observer only comes up when a proper ensemble is configured.
 * (and will not come up with standalone server).
 */
@Test
public void testObserverWithStandlone() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT_QP1 = PortAssignment.unique();        

    String quorumCfgSection =
        "server.1=127.0.0.1:" + (PortAssignment.unique())
        + ":" + (PortAssignment.unique()) + ":observer\n"
        + "server.2=127.0.0.1:" + (PortAssignment.unique())
        + ":" + (PortAssignment.unique()) + "\npeerType=observer\n";

    MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
    q1.start();
    q1.join(ClientBase.CONNECTION_TIMEOUT);
    Assert.assertFalse(q1.isAlive());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:21,代码来源:ObserverTest.java

示例2: testStandaloneQuorum

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Ensure that a single standalone server comes up when misconfigured
 * with a single server.# line in the configuration. This handles the
 * case of HBase, which configures zoo.cfg in this way. Maintain b/w
 * compatibility.
 * TODO remove in a future version (4.0.0 hopefully)
 */
@Test
public void testStandaloneQuorum() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT_QP1 = PortAssignment.unique();        
    
    String quorumCfgSection =
        "server.1=127.0.0.1:" + (PortAssignment.unique())
        + ":" + (PortAssignment.unique()) + "\n";
                
    MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
    q1.start();
    try {
        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        CONNECTION_TIMEOUT));
    } finally {
        q1.shutdown();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:27,代码来源:StandaloneTest.java

示例3: testLERestart

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

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", PortAssignment.unique(),
                                   PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }

    for(int i = 0; i < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:33,代码来源:FLERestartTest.java

示例4: testUnspecifiedClientAddress

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
@Test
public void testUnspecifiedClientAddress() throws Exception {
	int[] ports = new int[3];
	for (int port : ports) {
		port = PortAssignment.unique();
	}
	String server = "server.0=localhost:" + ports[0] + ":" + ports[1] + ";" + ports[2];
	QuorumServer qs = new QuorumServer(0, server);
	Assert.assertEquals(qs.clientAddr.getHostString(), "0.0.0.0");
	Assert.assertEquals(qs.clientAddr.getPort(), ports[2]);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:12,代码来源:ReconfigTest.java

示例5: testMinMaxSessionTimeOut

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Test verifies that the server is able to redefine the min/max session
 * timeouts
 */
@Test
public void testMinMaxSessionTimeOut() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();
    final int tickTime = 2000;
    final int minSessionTimeout = tickTime * 2 - 100;
    final int maxSessionTimeout = 20 * tickTime + 1000;
    final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n"
            + "minSessionTimeout=" + minSessionTimeout + "\n";
    MainThread main = new MainThread(CLIENT_PORT, true, configs);
    main.start();

    String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    // create session with min value
    verifySessionTimeOut(minSessionTimeout, minSessionTimeout, HOSTPORT);
    verifySessionTimeOut(minSessionTimeout - 2000, minSessionTimeout,
            HOSTPORT);
    // create session with max value
    verifySessionTimeOut(maxSessionTimeout, maxSessionTimeout, HOSTPORT);
    verifySessionTimeOut(maxSessionTimeout + 2000, maxSessionTimeout,
            HOSTPORT);
    main.shutdown();

    Assert.assertTrue("waiting for server down", ClientBase
            .waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:ZooKeeperServerMainTest.java

示例6: startServer

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
private ServerCnxnFactory startServer(File tmpDir) throws IOException,
        InterruptedException {
    final int CLIENT_PORT = PortAssignment.unique();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
    f.startup(zks);
    Assert.assertNotNull("JMX initialization failed!", zks.jmxServerBean);
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT));
    return f;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:13,代码来源:ZooKeeperServerMainTest.java

示例7: testSecureQuorumServer

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * This test checks that SSL works in cluster setup of ZK servers, which includes:
 * 1. setting "secureClientPort" in "zoo.cfg" file.
 * 2. setting jvm flags for serverCnxn, keystore, truststore.
 * Finally, a zookeeper client should be able to connect to the secure port and
 * communicate with server via secure connection.
 * <p/>
 * Note that in this test a ZK server has two ports -- clientPort and secureClientPort.
 */
@Test
public void testSecureQuorumServer() throws Exception {
    final int SERVER_COUNT = 3;
    final int clientPorts[] = new int[SERVER_COUNT];
    final Integer secureClientPorts[] = new Integer[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        secureClientPorts[i] = PortAssignment.unique();
        String server = String.format("server.%d=localhost:%d:%d:participant;localhost:%d",
                i, PortAssignment.unique(), PortAssignment.unique(), clientPorts[i]);
        sb.append(server + "\n");
    }
    String quorumCfg = sb.toString();


    MainThread[] mt = new MainThread[SERVER_COUNT];
    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, quorumCfg, secureClientPorts[i], true);
        mt[i].start();
    }

    // Servers have been set up. Now go test if secure connection is successful.
    for (int i = 0; i < SERVER_COUNT; i++) {
        Assert.assertTrue("waiting for server " + i + " being up",
                ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], TIMEOUT));

        ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + secureClientPorts[i], TIMEOUT);
        // Do a simple operation to make sure the connection is fine.
        zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.delete("/test", -1);
        zk.close();
    }

    for (int i = 0; i < mt.length; i++) {
        mt[i].shutdown();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:48,代码来源:SSLTest.java

示例8: testStandalone

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Verify the ability to start a standalone server instance.
 */
@Test
public void testStandalone() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();

    MainThread main = new MainThread(CLIENT_PORT, true);
    main.start();

    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT));


    ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
            ClientBase.CONNECTION_TIMEOUT, this);

    zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    Assert.assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
    zk.close();

    main.shutdown();
    main.join();
    main.deleteDirs();

    Assert.assertTrue("waiting for server down",
            ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
                    ClientBase.CONNECTION_TIMEOUT));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:ZooKeeperServerMainTest.java

示例9: testWithOnlyMinSessionTimeout

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Test verifies that the server is able to redefine if user configured only
 * minSessionTimeout limit
 */
@Test
public void testWithOnlyMinSessionTimeout() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();
    final int tickTime = 2000;
    final int minSessionTimeout = tickTime * 2 - 100;
    int maxSessionTimeout = 20 * tickTime;
    final String configs = "minSessionTimeout=" + minSessionTimeout + "\n";
    MainThread main = new MainThread(CLIENT_PORT, true, configs);
    main.start();

    String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    // create session with min value
    verifySessionTimeOut(minSessionTimeout, minSessionTimeout, HOSTPORT);
    verifySessionTimeOut(minSessionTimeout - 2000, minSessionTimeout,
            HOSTPORT);
    // create session with max value
    verifySessionTimeOut(maxSessionTimeout, maxSessionTimeout, HOSTPORT);
    verifySessionTimeOut(maxSessionTimeout + 2000, maxSessionTimeout,
            HOSTPORT);
    main.shutdown();
    Assert.assertTrue("waiting for server down", ClientBase
            .waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:32,代码来源:ZooKeeperServerMainTest.java

示例10: testReadOnlySnapshotDir

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Tests that the ZooKeeper server will fail to start if the
 * snapshot directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlySnapshotDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the snapshot directory read only
    File snapDir = new File(main.dataDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    snapDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    snapDir.setWritable(true);

    main.deleteDirs();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:40,代码来源:ZooKeeperServerMainTest.java

示例11: testMinMaxSessionTimeOut

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Test verifies that the server is able to redefine the min/max session
 * timeouts
 */
@Test
public void testMinMaxSessionTimeOut() throws Exception {
    ClientBase.setupTestEnv();

    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=127.0.0.1:" + PortAssignment.unique() + ":"
            + PortAssignment.unique();

    final int minSessionTimeOut = 10000;
    final int maxSessionTimeOut = 15000;
    final String configs = "maxSessionTimeout=" + maxSessionTimeOut + "\n"
            + "minSessionTimeout=" + minSessionTimeOut + "\n";

    MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection,
            configs);
    MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection,
            configs);
    q1.start();
    q2.start();

    Assert.assertTrue("waiting for server 1 being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                    CONNECTION_TIMEOUT));
    Assert.assertTrue("waiting for server 2 being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                    CONNECTION_TIMEOUT));

    QuorumPeer quorumPeer = q1.main.quorumPeer;

    Assert.assertEquals("minimumSessionTimeOut is not considered",
            minSessionTimeOut, quorumPeer.getMinSessionTimeout());
    Assert.assertEquals("maximumSessionTimeOut is not considered",
            maxSessionTimeOut, quorumPeer.getMaxSessionTimeout());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:43,代码来源:QuorumPeerMainTest.java

示例12: testObserverOnly

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * This test ensures that an Observer does not elect itself as a leader, or
 * indeed come up properly, if it is the lone member of an ensemble.
 * @throws Exception
 */
@Test
public void testObserverOnly() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT_QP1 = PortAssignment.unique();        
    
    String quorumCfgSection =
        "server.1=127.0.0.1:" + (PortAssignment.unique())
        + ":" + (PortAssignment.unique()) + ":observer\npeerType=observer\n";
                
    MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
    q1.start();
    q1.join(ClientBase.CONNECTION_TIMEOUT);
    Assert.assertFalse(q1.isAlive());
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:ObserverTest.java

示例13: testBadPeerAddressInQuorum

import org.apache.zookeeper.PortAssignment; //导入方法依赖的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

示例14: testValidIpv6AddressInQuorum

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
@Test
public void testValidIpv6AddressInQuorum() 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();
        final int CLIENT_PORT_QP2 = 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);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);

        q1.start();
        q2.start();

        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        Assert.assertTrue("waiting for server 2 being up",
                ClientBase.waitForServerUp("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        q1.shutdown();
        q2.shutdown();

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

        Assert.assertTrue("waiting for server 2 down",
                ClientBase.waitForServerDown("[0:0:0:0:0: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(".*Resolved hostname: 0:0:0:0:0:0:0:1.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("IPv6 address resolved", found);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:70,代码来源:QuorumPeerMainTest.java

示例15: runElection

import org.apache.zookeeper.PortAssignment; //导入方法依赖的package包/类
/**
 * Test leader election for a number of rounds. In all rounds but the last one
 * we kill the leader.
 * 
 * @param rounds
 * @throws Exception
 */
private void runElection(int rounds) throws Exception {
    ConcurrentHashMap<Long, HashSet<Integer> > quora = 
        new ConcurrentHashMap<Long, HashSet<Integer> >();

    LOG.info("TestLE: " + getTestName()+ ", " + count);

    /*
     * Creates list of peers.
     */
    for(int i = 0; i < count; i++) {
        port[i] = PortAssignment.unique();
        peers.put(Long.valueOf(i),
            new QuorumServer(i,
                new InetSocketAddress(
                    "127.0.0.1", PortAssignment.unique()),
                new InetSocketAddress(
                    "127.0.0.1", PortAssignment.unique()),
                new InetSocketAddress(
                    "127.0.0.1", port[i])));
        tmpdir[i] = ClientBase.createTmpDir();           
    }

    /*
     * Start one LEThread for each peer we want to run.
     */
    for(int i = 0; i < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i],
                port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        LEThread thread = new LEThread(this, peer, i, rounds, quora);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    int waitCounter = 0;
    synchronized(this){
        while(((successCount <= count/2) || (leader == -1))
            && (waitCounter < MAX_LOOP_COUNTER))
        {
            this.wait(200);
            waitCounter++;
        }
    }
    LOG.info("Success count: " + successCount);

    /*
    * Lists what threads haven't joined. A thread doesn't join if
    * it hasn't decided upon a leader yet. It can happen that a
    * peer is slow or disconnected, and it can take longer to
    * nominate and connect to the current leader.
    */
   for (int i = 0; i < threads.size(); i++) {
        if (threads.get(i).isAlive()) {
            LOG.info("Threads didn't join: " + i);
        }
    }

   /*
    * If we have a majority, then we are good to go.
    */
   if(successCount <= count/2){
       Assert.fail("Fewer than a a majority has joined");
   }

   /*
    * I'm done so joining.
    */
   if(!joinedThreads.contains(leader)){
       Assert.fail("Leader hasn't joined: " + leader);
   }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:80,代码来源:FLETest.java


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