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


Java ZooKeeperServer.shutdown方法代码示例

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


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

示例1: testPurge

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的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 = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    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:maoling,项目名称:fuck_zookeeper,代码行数:43,代码来源:PurgeTxnTest.java

示例2: testSnapshot

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * test the snapshot
 * @throws Exception an exception could be expected
 */
@Test
public void testSnapshot() throws Exception {
    File snapDir = new File(testData, "invalidsnap");
    ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    LOG.info("starting up the zookeeper server .. waiting");
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
    try {
        // we know this from the data files
        // this node is the last node in the snapshot

        Assert.assertTrue(zk.exists("/9/9/8", false) != null);
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:32,代码来源:InvalidSnapshotTest.java

示例3: testDisconnectedAddAuth

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
@Test
public void testDisconnectedAddAuth() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    try {
        LOG.info("starting up the zookeeper server .. waiting");
        Assert.assertTrue("waiting for server being up",
                ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
        try {
            zk.addAuthInfo("digest", "pat:test".getBytes());
            zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
        } finally {
            zk.close();
        }
    } finally {
        f.shutdown();
        zks.shutdown();
        Assert.assertTrue("waiting for server down",
                ClientBase.waitForServerDown(HOSTPORT,
                        ClientBase.CONNECTION_TIMEOUT));
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:29,代码来源:ACLTest.java

示例4: testFail

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/** bring up 5 quorum peers and then shut them down
 * and then bring one of the nodes as server
 *
 * @throws Exception might be thrown here
 */
@Test
public void testFail() throws Exception {
    QuorumBase qb = new QuorumBase();
    qb.setUp();

    System.out.println("Comment: the servers are at " + qb.hostPort);
    ZooKeeper zk = qb.createClient();
    zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
    qb.shutdown(qb.s1);
    qb.shutdown(qb.s2);
    qb.shutdown(qb.s3);
    qb.shutdown(qb.s4);
    qb.shutdown(qb.s5);
    String hp = qb.hostPort.split(",")[0];
    ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(),
            qb.s1.getTxnFactory().getDataDir(), 3000);
    final int PORT = Integer.parseInt(hp.split(":")[1]);
    ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1);

    factory.startup(zks);
    System.out.println("Comment: starting factory");
    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                       QuorumTest.CONNECTION_TIMEOUT));
    factory.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                            QuorumTest.CONNECTION_TIMEOUT));
    System.out.println("Comment: shutting down standalone");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:38,代码来源:RepeatStartupTest.java

示例5: testSnapshot

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * test the snapshot
 * @throws Exception an exception could be expected
 */
@Test
public void testSnapshot() throws Exception {
    File snapDir = new File(testData, "invalidsnap");
    ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    LOG.info("starting up the zookeeper server .. waiting");
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        // we know this from the data files
        // this node is the last node in the snapshot

        Assert.assertTrue(zk.exists("/9/9/8", false) != null);
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:32,代码来源:InvalidSnapshotTest.java

示例6: testDisconnectedAddAuth

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
@Test
public void testDisconnectedAddAuth() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    try {
        LOG.info("starting up the zookeeper server .. waiting");
        Assert.assertTrue("waiting for server being up",
                ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
        try {
            zk.addAuthInfo("digest", "pat:test".getBytes());
            zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
        } finally {
            zk.close();
        }
    } finally {
        f.shutdown();
        zks.shutdown();
        Assert.assertTrue("waiting for server down",
                ClientBase.waitForServerDown(HOSTPORT,
                        ClientBase.CONNECTION_TIMEOUT));
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:29,代码来源:ACLTest.java

示例7: testFail

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/** bring up 5 quorum peers and then shut them down
 * and then bring one of the nodes as server
 *
 * @throws Exception might be thrown here
 */
@Test
public void testFail() throws Exception {
    QuorumBase qb = new QuorumBase();
    qb.setUp();

    System.out.println("Comment: the servers are at " + qb.hostPort);
    ZooKeeper zk = qb.createClient();
    zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
    QuorumBase.shutdown(qb.s1);
    QuorumBase.shutdown(qb.s2);
    QuorumBase.shutdown(qb.s3);
    QuorumBase.shutdown(qb.s4);
    QuorumBase.shutdown(qb.s5);
    String hp = qb.hostPort.split(",")[0];
    ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(),
            qb.s1.getTxnFactory().getDataDir(), 3000);
    final int PORT = Integer.parseInt(hp.split(":")[1]);
    ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1);

    factory.startup(zks);
    System.out.println("Comment: starting factory");
    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                       QuorumTest.CONNECTION_TIMEOUT));
    factory.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                            QuorumTest.CONNECTION_TIMEOUT));
    System.out.println("Comment: shutting down standalone");
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:38,代码来源:RepeatStartupTest.java

示例8: testStandaloneReconfigFails

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * Verify that reconfiguration in standalone mode fails with
 * KeeperException.UnimplementedException.
 */
@Test
public void testStandaloneReconfigFails() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();
    final String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;

    File tmpDir = ClientBase.createTmpDir();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

    ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ", ClientBase
            .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));

    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher);
    ZooKeeperAdmin zkAdmin = new ZooKeeperAdmin(HOSTPORT, CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(CONNECTION_TIMEOUT);

    List<String> joiners = new ArrayList<String>();
    joiners.add("server.2=localhost:1234:1235;1236");
    // generate some transactions that will get logged
    try {
        zkAdmin.addAuthInfo("digest", "super:test".getBytes());
        zkAdmin.reconfigure(joiners, null, null, -1, new Stat());
        Assert.fail("Reconfiguration in standalone should trigger " +
                    "UnimplementedException");
    } catch (KeeperException.UnimplementedException ex) {
        // expected
    }
    zk.close();

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

示例9: testPurgeWhenLogRollingInProgress

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的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 = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    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:maoling,项目名称:fuck_zookeeper,代码行数:60,代码来源:PurgeTxnTest.java

示例10: testLoad

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * test that all transactions from the Log are loaded, and only once
 * @throws Exception an exception might be thrown here
 */
@Test
public void testLoad() throws Exception {
    // setup a single server cluster
    File 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 = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);

    // generate some transactions that will get logged
    try {
        for (int i = 0; i< NUM_MESSAGES; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));

    // now verify that the FileTxnLog reads every transaction only once
    File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    FileTxnLog txnLog = new FileTxnLog(logDir);

    TxnIterator itr = txnLog.read(0);
    long expectedZxid = 0;
    long lastZxid = 0;
    TxnHeader hdr;
    do {
        hdr = itr.getHeader();
        expectedZxid++;
        Assert.assertTrue("not the same transaction. lastZxid=" + lastZxid + ", zxid=" + hdr.getZxid(), lastZxid != hdr.getZxid());
        Assert.assertTrue("excepting next transaction. expected=" + expectedZxid + ", retreived=" + hdr.getZxid(), (hdr.getZxid() == expectedZxid));
        lastZxid = hdr.getZxid();
    }while(itr.next());
	
    Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS));
    zks.shutdown();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:51,代码来源:LoadFromLogTest.java

示例11: testBindByAddress

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * Verify that the server binds to the specified address
 */
@Test
public void testBindByAddress() throws Exception {
    String bindAddress = null;
    Enumeration<NetworkInterface> intfs =
        NetworkInterface.getNetworkInterfaces();
    // if we have a loopback and it has an address use it
    while(intfs.hasMoreElements()) {
        NetworkInterface i = intfs.nextElement();
        try {
            if (i.isLoopback()) {
              Enumeration<InetAddress> addrs = i.getInetAddresses();
              while (addrs.hasMoreElements()) {
                InetAddress a = addrs.nextElement();
                if(a.isLoopbackAddress()) {
                  bindAddress = a.getHostAddress();
                  break;
                }
              }
            }
        } catch (SocketException se) {
            LOG.warn("Couldn't find  loopback interface: " + se.getMessage());
        }
    }
    if (bindAddress == null) {
        LOG.warn("Unable to determine loop back address, skipping test");
        return;
    }
    final int PORT = PortAssignment.unique();

    LOG.info("Using " + bindAddress + " as the bind address");
    final String HOSTPORT = bindAddress + ":" + PORT;
    LOG.info("Using " + HOSTPORT + " as the host/port");


    File tmpDir = ClientBase.createTmpDir();

    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

    ServerCnxnFactory f = ServerCnxnFactory.createFactory(
            new InetSocketAddress(bindAddress, PORT), -1);
    f.startup(zks);
    LOG.info("starting up the the server, waiting");

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                               CONNECTION_TIMEOUT));

    startSignal = new CountDownLatch(1);
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        startSignal.await(CONNECTION_TIMEOUT,
                TimeUnit.MILLISECONDS);
        Assert.assertTrue("count == 0", startSignal.getCount() == 0);
        zk.close();
    } finally {
        f.shutdown();
        zks.shutdown();

        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown(HOSTPORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:68,代码来源:ClientPortBindTest.java

示例12: testBindByAddress

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * Verify that the server binds to the specified address
 */
@Test
public void testBindByAddress() throws Exception {
    String bindAddress = null;
    Enumeration<NetworkInterface> intfs =
        NetworkInterface.getNetworkInterfaces();
    // if we have a loopback and it has an address use it
    while(intfs.hasMoreElements()) {
        NetworkInterface i = intfs.nextElement();
        if (i.isLoopback()) {
            Enumeration<InetAddress> addrs = i.getInetAddresses();
            while (addrs.hasMoreElements()) {
                InetAddress a = addrs.nextElement();
                if(a.isLoopbackAddress()) {
                    bindAddress = a.getHostAddress();
                    break;
                }
            }
        }
    }
    if (bindAddress == null) {
        LOG.warn("Unable to determine loop back address, skipping test");
        return;
    }
    final int PORT = PortAssignment.unique();

    LOG.info("Using " + bindAddress + " as the bind address");
    final String HOSTPORT = bindAddress + ":" + PORT;
    LOG.info("Using " + HOSTPORT + " as the host/port");


    File tmpDir = ClientBase.createTmpDir();

    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

    ServerCnxnFactory f = ServerCnxnFactory.createFactory(
            new InetSocketAddress(bindAddress, PORT), -1);
    f.startup(zks);
    LOG.info("starting up the the server, waiting");

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                               CONNECTION_TIMEOUT));

    startSignal = new CountDownLatch(1);
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        startSignal.await(CONNECTION_TIMEOUT,
                TimeUnit.MILLISECONDS);
        Assert.assertTrue("count == 0", startSignal.getCount() == 0);
        zk.close();
    } finally {
        f.shutdown();
        zks.shutdown();

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

示例13: testPurgeWhenLogRollingInProgress

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

示例14: testOOM

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
@Test
public void testOOM() throws IOException, InterruptedException, KeeperException {
    // This test takes too long tos run!
    if (true)
        return;
    File tmpDir = ClientBase.createTmpDir();
    // Grab some memory so that it is easier to cause an
    // OOM condition;
    List<byte[]> hog = new ArrayList<byte[]>();
    while (true) {
        try {
            hog.add(new byte[1024 * 1024 * 2]);
        } catch (OutOfMemoryError e) {
            hog.remove(0);
            break;
        }
    }
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

    final int PORT = PortAssignment.unique();
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    System.err.println("OOM Stage 0");
    utestPrep(PORT);
    System.out.println("Free = " + Runtime.getRuntime().freeMemory()
            + " total = " + Runtime.getRuntime().totalMemory() + " max = "
            + Runtime.getRuntime().maxMemory());
    System.err.println("OOM Stage 1");
    for (int i = 0; i < 1000; i++) {
        System.out.println(i);
        utestExists(PORT);
    }
    System.out.println("Free = " + Runtime.getRuntime().freeMemory()
            + " total = " + Runtime.getRuntime().totalMemory() + " max = "
            + Runtime.getRuntime().maxMemory());
    System.err.println("OOM Stage 2");
    for (int i = 0; i < 1000; i++) {
        System.out.println(i);
        utestGet(PORT);
    }
    System.out.println("Free = " + Runtime.getRuntime().freeMemory()
            + " total = " + Runtime.getRuntime().totalMemory() + " max = "
            + Runtime.getRuntime().maxMemory());
    System.err.println("OOM Stage 3");
    for (int i = 0; i < 1000; i++) {
        System.out.println(i);
        utestChildren(PORT);
    }
    System.out.println("Free = " + Runtime.getRuntime().freeMemory()
            + " total = " + Runtime.getRuntime().totalMemory() + " max = "
            + Runtime.getRuntime().maxMemory());
    hog.get(0)[0] = (byte) 1;

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

示例15: testBindByAddress

import org.apache.zookeeper.server.ZooKeeperServer; //导入方法依赖的package包/类
/**
 * Verify that the server binds to the specified address
 */
@Test
public void testBindByAddress() throws Exception {
    String bindAddress = null;
    Enumeration<NetworkInterface> intfs =
        NetworkInterface.getNetworkInterfaces();
    // if we have a loopback and it has an address use it
    while(intfs.hasMoreElements()) {
        NetworkInterface i = intfs.nextElement();
        try {
            if (i.isLoopback()) {
              Enumeration<InetAddress> addrs = i.getInetAddresses();
              while (addrs.hasMoreElements()) {
                InetAddress a = addrs.nextElement();
                if(a.isLoopbackAddress()) {
                  bindAddress = a.getHostAddress();
                  break;
                }
              }
            }
        } catch (SocketException se) {
            LOG.warn("Couldn't find  loopback interface: " + se.getMessage());
        }
    }
    if (bindAddress == null) {
        LOG.warn("Unable to determine loop back address, skipping test");
        return;
    }
    final int PORT = PortAssignment.unique();

    LOG.info("Using " + bindAddress + " as the bind address");
    final String HOSTPORT = bindAddress + ":" + PORT;
    LOG.info("Using " + HOSTPORT + " as the host/port");


    File tmpDir = ClientBase.createTmpDir();

    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

    ServerCnxnFactory f = ServerCnxnFactory.createFactory(
            new InetSocketAddress(bindAddress, PORT), -1);
    f.startup(zks);
    LOG.info("starting up the the server, waiting");

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                               CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        zk.close();
    } finally {
        f.shutdown();
        zks.shutdown();

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


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