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


Java ClientBase类代码示例

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


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

示例1: waitForAll

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
private void waitForAll(ZooKeeper[] zks, States state) throws InterruptedException {
	int iterations = 10;
	boolean someoneNotConnected = true;
       while(someoneNotConnected) {
       	if (iterations-- == 0) {
       		ClientBase.logAllStackTraces();
		throw new RuntimeException("Waiting too long");
       	}
       	
       	someoneNotConnected = false;
       	for(ZooKeeper zk: zks) {
       		if (zk.getState() != state) {
       			someoneNotConnected = true;
       		}
       	}
       	Thread.sleep(1000);
       }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:QuorumPeerMainTest.java

示例2: LaunchServers

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * This is a helper function for launching a set of servers
 *  
 * @param numServers
 * @return
 * @throws IOException
 * @throws InterruptedException
 */
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
    int SERVER_COUNT = numServers;
    Servers svrs = new Servers();
    final int clientPorts[] = new int[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
    }
    String quorumCfgSection = sb.toString();
  
    MainThread mt[] = new MainThread[SERVER_COUNT];
    ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
    for(int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
        mt[i].start();
        zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
    }
  
    waitForAll(zk, States.CONNECTED);
  
    svrs.mt = mt;
    svrs.zk = zk;
    return svrs;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:QuorumPeerMainTest.java

示例3: internalTestSnapFilesEqualsToRetain

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
public void internalTestSnapFilesEqualsToRetain(boolean testWithPrecedingLogFile) throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, testWithPrecedingLogFile, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:18,代码来源:PurgeTxnTest.java

示例4: setUp

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

    this.count = 3;
    this.peers = new HashMap<Long,QuorumServer>(count); 
    peerTmpdir = new File[count];
    peerQuorumPort = new int[count];
    peerClientPort = new int[count];
    
    for(int i = 0; i < count; i++) {
        peerQuorumPort[i] = PortAssignment.unique();
        peerClientPort[i] = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0",
                                   peerQuorumPort[i],
                                   PortAssignment.unique(), null));
        peerTmpdir[i] = ClientBase.createTmpDir();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:CnxManagerTest.java

示例5: teardown

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
@After
public void teardown() throws Exception {
    // count down to avoid infinite blocking call due to this latch, if
    // any.
    startupDelayLatch.countDown();

    if (servcnxnf != null) {
        servcnxnf.shutdown();
    }
    if (zks != null) {
        zks.shutdown();
    }
    if (zks.getZKDatabase() != null) {
        zks.getZKDatabase().close();
    }
    if (tmpDir != null) {
        ClientBase.recursiveDelete(tmpDir);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:ZooKeeperServerStartupTest.java

示例6: shutdown

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
private void shutdown(int idx) throws Exception {
    qu.shutdown(idx);

    // leader will shutdown, remaining followers will elect a new leader
    PeerStruct peer = qu.getPeer(idx);
    Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown(
            "127.0.0.1:" + peer.clientPort, ClientBase.CONNECTION_TIMEOUT));

    // if idx is the the leader then everyone will get disconnected,
    // otherwise if idx is a follower then just that client will get
    // disconnected
    if (idx == idxLeader) {
        checkClientDisconnected(idx);
        try {
            checkClientsDisconnected();
        } catch (AssertionFailedError e) {
            // the clients may or may not have already reconnected
            // to the recovered cluster, force a check, but ignore
        }
    } else {
        checkClientDisconnected(idx);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:24,代码来源:ZxidRolloverTest.java

示例7: testSnapFilesEqualsToRetain

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:PurgeTxnTest.java

示例8: testSnapFilesLessThanToRetain

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:30,代码来源:PurgeTxnTest.java

示例9: testZooKeeperWithCustomHostProvider

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
@Test
public void testZooKeeperWithCustomHostProvider() throws IOException,
        InterruptedException {
    final int CLIENT_PORT = PortAssignment.unique();
    final HostProvider specialHostProvider = new SpecialHostProvider();
    int expectedCounter = 3;
    counter.set(expectedCounter);

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

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

    Assert.assertTrue(counter.get() == expectedCounter);
    zkDefaults.updateServerList("127.0.0.1:" + PortAssignment.unique());
    Assert.assertTrue(counter.get() == expectedCounter);

    zkSpecial.updateServerList("127.0.0.1:" + PortAssignment.unique());
    expectedCounter--;
    Assert.assertTrue(counter.get() == expectedCounter);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:23,代码来源:CustomHostProviderTest.java

示例10: LaunchServers

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * This is a helper function for launching a set of servers
 *
 * @param numServers
 * @return
 * @throws IOException
 * @throws InterruptedException
 */
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
    int SERVER_COUNT = numServers;
    Servers svrs = new Servers();
    final int clientPorts[] = new int[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+";"+clientPorts[i]+"\n");
    }
    String quorumCfgSection = sb.toString();

    MainThread mt[] = new MainThread[SERVER_COUNT];
    ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
        mt[i].start();
        zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
    }

    waitForAll(zk, States.CONNECTED);

    svrs.mt = mt;
    svrs.zk = zk;
    return svrs;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:QuorumPeerMainTest.java

示例11: testLearnerHandlerAuthFailed

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * Test verifies that the LearnerHandler should authenticate the connecting
 * quorumpeer. Here its simulating authentication failure and it should throw
 * SaslException
 */
@Test(timeout = 30000)
public void testLearnerHandlerAuthFailed() throws Exception {
    File testData = ClientBase.createTmpDir();
    Socket leaderSocket = getSocketPair();
    File tmpDir = File.createTempFile("test", ".dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    Leader leader = null;
    QuorumPeer peer = createQuorumPeer(tmpDir, true, false, true,
            "QuorumLearner", "QuorumServer",
            QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
    leader = createLeader(tmpDir, peer);
    peer.leader = leader;

    // authentication failed as qpserver didn't get auth packet from qpclient.
    try {
        new LearnerHandler(leaderSocket,
                new BufferedInputStream(leaderSocket.getInputStream()), leader);
        Assert.fail("Must throw exception as there is an authentication failure");
    } catch (SaslException e){
        Assert.assertEquals("Mistakely added to learners", 0,
                leader.getLearners().size());
    }
    ClientBase.recursiveDelete(testData);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:31,代码来源:QuorumCnxManagerTest.java

示例12: setUp

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
public void setUp(int numCommitThreads, int numClientThreads, int writePercent)
        throws Exception {
    stopped = false;
    System.setProperty(
        CommitProcessor.ZOOKEEPER_COMMIT_PROC_NUM_WORKER_THREADS,
        Integer.toString(numCommitThreads));
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    zks = new TestZooKeeperServer(tmpDir, tmpDir, 4000);
    zks.startup();
    for(int i=0; i<numClientThreads; ++i) {
        TestClientThread client = new TestClientThread(writePercent);
        testClients.add(client);
        client.start();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:CommitProcessorTest.java

示例13: testAuthLearnerServer

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

示例14: testStandalone

import org.apache.zookeeper.test.ClientBase; //导入依赖的package包/类
/**
 * Starts a standalone server and tests that we can query its AdminServer.
 */
@Test
public void testStandalone() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();

    ZooKeeperServerMainTest.MainThread main = new ZooKeeperServerMainTest.MainThread(CLIENT_PORT, false, null);
    main.start();

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

    queryAdminServer(jettyAdminPort);

    main.shutdown();

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

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


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