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


Java ClientBase.createZKClient方法代码示例

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


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

示例1: startServer

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Starts a single server in replicated mode,
 * initializes its client, and waits for it
 * to be connected.
 */
private void startServer(int id, String config) throws Exception {
    peers[id] = new MainThread(id, clientPorts[id], config);
    peers[id].start();
    Assert.assertTrue("Server " + id + " is not up",
                      ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT));
    Assert.assertTrue("Error- Server started in Standalone Mode!",
            peers[id].isQuorumPeerRunning());
    zkHandles[id] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[id]);
    zkAdminHandles[id] = new ZooKeeperAdmin("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT, this);
    zkAdminHandles[id].addAuthInfo("digest", "super:test".getBytes());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:StandaloneDisabledTest.java

示例2: testPurge

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:43,代码来源:PurgeTxnTest.java

示例3: testRestartZooKeeperServer

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2244
 *
 * @throws Exception
 */
@Test(timeout = 120000)
public void testRestartZooKeeperServer() throws Exception {
    final int clientPorts[] = new int[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    String server;

    for (int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        server = "server." + i + "=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique() + ":participant;127.0.0.1:"
                + clientPorts[i];
        sb.append(server + "\n");
    }
    String currentQuorumCfgSection = sb.toString();
    MainThread mt[] = new MainThread[SERVER_COUNT];

    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection,
                false);
        mt[i].start();
    }

    // ensure server started
    for (int i = 0; i < SERVER_COUNT; i++) {
        Assert.assertTrue("waiting for server " + i + " being up",
                ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                        CONNECTION_TIMEOUT));
    }

    ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);

    String zNodePath="/serverRestartTest";
    String data = "originalData";
    zk.create(zNodePath, data.getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk.close();

    /**
     * stop two servers out of three and again start them
     */
    mt[0].shutdown();
    mt[1].shutdown();
    mt[0].start();
    mt[1].start();
    // ensure server started
    for (int i = 0; i < SERVER_COUNT; i++) {
        Assert.assertTrue("waiting for server " + i + " being up",
                ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                        CONNECTION_TIMEOUT));
    }
    zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);

    byte[] dataBytes = zk.getData(zNodePath, null, null);
    String receivedData = new String(dataBytes);
    assertEquals(data, receivedData);

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

示例4: verifyQuorumConfig

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
private void verifyQuorumConfig(int sid, List<String> joiningServers, List<String> leavingServers) throws Exception {
    ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts.get(sid));
    ReconfigTest.testNormalOperation(zk, zk);
    ReconfigTest.testServerHasConfig(zk, joiningServers, leavingServers);
    zk.close();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:7,代码来源:ReconfigRollingRestartCompatibilityTest.java

示例5: testPurgeWhenLogRollingInProgress

import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
 * Tests purge when logs are rolling or a new snapshot is created, then
 * these newer files should alse be excluded in the current cycle.
 *
 * For frequent snapshotting, configured SnapCount to 30. There are three
 * threads which will create 1000 znodes each and simultaneously do purge
 * call
 */
@Test
public void testPurgeWhenLogRollingInProgress() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(30);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    final ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    final CountDownLatch doPurge = new CountDownLatch(1);
    final CountDownLatch purgeFinished = new CountDownLatch(1);
    final AtomicBoolean opFailed = new AtomicBoolean(false);
    new Thread() {
        public void run() {
            try {
                doPurge.await(OP_TIMEOUT_IN_MILLIS / 2,
                        TimeUnit.MILLISECONDS);
                PurgeTxnLog.purge(tmpDir, tmpDir, 3);
            } catch (IOException ioe) {
                LOG.error("Exception when purge", ioe);
                opFailed.set(true);
            } catch (InterruptedException ie) {
                LOG.error("Exception when purge", ie);
                opFailed.set(true);
            } finally {
                purgeFinished.countDown();
            }
        };
    }.start();
    final int thCount = 3;
    List<String> znodes = manyClientOps(zk, doPurge, thCount,
            "/invalidsnap");
    Assert.assertTrue("Purging is not finished!", purgeFinished.await(
            OP_TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS));
    Assert.assertFalse("Purging failed!", opFailed.get());
    for (String znode : znodes) {
        try {
            zk.getData(znode, false, null);
        } catch (Exception ke) {
            LOG.error("Unexpected exception when visiting znode!", ke);
            Assert.fail("Unexpected exception when visiting znode!");
        }
    }
    zk.close();
    f.shutdown();
    zks.shutdown();
    zks.getTxnLogFactory().close();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:60,代码来源:PurgeTxnTest.java


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