當前位置: 首頁>>代碼示例>>Java>>正文


Java FileTxnSnapLog.getSnapDir方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.server.persistence.FileTxnSnapLog.getSnapDir方法的典型用法代碼示例。如果您正苦於以下問題:Java FileTxnSnapLog.getSnapDir方法的具體用法?Java FileTxnSnapLog.getSnapDir怎麽用?Java FileTxnSnapLog.getSnapDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.server.persistence.FileTxnSnapLog的用法示例。


在下文中一共展示了FileTxnSnapLog.getSnapDir方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNonRecoverableError

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2247.
 * Test to verify that even after non recoverable error (error while
 * writing transaction log) on ZooKeeper service will be available
 */
@Test(timeout = 30000)
public void testNonRecoverableError() 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("/foo1", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    Assert.assertEquals(new String(zk.getData("/foo1", null, null)), "foobar");

    // inject problem in server
    ZooKeeperServer zooKeeperServer = main.getCnxnFactory()
            .getZooKeeperServer();
    FileTxnSnapLog snapLog = zooKeeperServer.getTxnLogFactory();
    FileTxnSnapLog fileTxnSnapLogWithError = new FileTxnSnapLog(
            snapLog.getDataDir(), snapLog.getSnapDir()) {
        @Override
        public void commit() throws IOException {
            throw new IOException("Input/output error");
        }
    };
    ZKDatabase newDB = new ZKDatabase(fileTxnSnapLogWithError);
    zooKeeperServer.setZKDatabase(newDB);

    try {
        // do create operation, so that injected IOException is thrown
        zk.create("/foo2", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
        fail("IOException is expected as error is injected in transaction log commit funtionality");
    } catch (Exception e) {
        // do nothing
    }
    zk.close();
    Assert.assertTrue("waiting for server down",
            ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
                    ClientBase.CONNECTION_TIMEOUT));
    fileTxnSnapLogWithError.close();
    main.shutdown();
    main.deleteDirs();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:57,代碼來源:ZooKeeperServerMainTest.java

示例2: testCorruption

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
@Test
public void testCorruption() throws Exception {
    ClientBase.waitForServerUp(qb.hostPort, 10000);
    ClientBase.waitForServerUp(qb.hostPort, 10000);
    ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
        public void process(WatchedEvent event) {
        }});
    SyncRequestProcessor.setSnapCount(100);
    for (int i = 0; i < 2000; i++) {
        zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                  CreateMode.PERSISTENT, new NoopStringCallback(), null);
    }
    zk.close();

    long leaderSid = 1;
    QuorumPeer leader = null;
    //find out who is the leader and kill it
    for (QuorumPeer quorumPeer : Arrays.asList(qb.s1, qb.s2, qb.s3, qb.s4, qb.s5)) {
        if (quorumPeer.getPeerState() == ServerState.LEADING) {
            leader = quorumPeer;
            break;
        }
        ++leaderSid;
    }

    Assert.assertNotNull("Cannot find the leader.", leader);
    leader.shutdown();

    // now corrupt the leader's database
    FileTxnSnapLog snapLog = leader.getTxnFactory();
    File snapDir= snapLog.getSnapDir();
    //corrupt all the snapshot in the snapshot directory
    corruptAllSnapshots(snapDir);
    qb.shutdownServers();
    qb.setupServers();

    if (leaderSid != 1)qb.s1.start(); else leader = qb.s1;
    if (leaderSid != 2)qb.s2.start(); else leader = qb.s2;
    if (leaderSid != 3)qb.s3.start(); else leader = qb.s3;
    if (leaderSid != 4)qb.s4.start(); else leader = qb.s4;
    if (leaderSid != 5)qb.s5.start(); else leader = qb.s5;

    try {
        leader.start();
        Assert.assertTrue(false);
    } catch(RuntimeException re) {
        LOG.info("Got an error: expected", re);
    }
    //wait for servers to be up
    String[] list = qb.hostPort.split(",");
    for (int i = 0; i < 5; i++) {
        if(leaderSid != (i + 1)) {
            String hp = list[i];
            Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(hp,
                            CONNECTION_TIMEOUT));
            LOG.info("{} is accepting client connections", hp);
        } else {
            LOG.info("Skipping the leader");
        }
    }

    zk = qb.createClient();
    SyncRequestProcessor.setSnapCount(100);
    for (int i = 2000; i < 4000; i++) {
        zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                  CreateMode.PERSISTENT, new NoopStringCallback(), null);
    }
    zk.close();

    if (leaderSid != 1)QuorumBase.shutdown(qb.s1);
    if (leaderSid != 2)QuorumBase.shutdown(qb.s2);
    if (leaderSid != 3)QuorumBase.shutdown(qb.s3);
    if (leaderSid != 4)QuorumBase.shutdown(qb.s4);
    if (leaderSid != 5)QuorumBase.shutdown(qb.s5);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:77,代碼來源:ZkDatabaseCorruptionTest.java

示例3: testNonRecoverableError

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2247.
 * Test to verify that even after non recoverable error (error while
 * writing transaction log), ZooKeeper is still available.
 */
@Test(timeout = 30000)
public void testNonRecoverableError() throws Exception {
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = PortAssignment.unique();

    MainThread main = new MainThread(CLIENT_PORT, true, null);
    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("/foo1", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    Assert.assertEquals(new String(zk.getData("/foo1", null, null)), "foobar");

    // inject problem in server
    ZooKeeperServer zooKeeperServer = main.getCnxnFactory()
            .getZooKeeperServer();
    FileTxnSnapLog snapLog = zooKeeperServer.getTxnLogFactory();
    FileTxnSnapLog fileTxnSnapLogWithError = new FileTxnSnapLog(
            snapLog.getDataDir(), snapLog.getSnapDir()) {
        @Override
        public void commit() throws IOException {
            throw new IOException("Input/output error");
        }
    };
    ZKDatabase newDB = new ZKDatabase(fileTxnSnapLogWithError);
    zooKeeperServer.setZKDatabase(newDB);

    try {
        // do create operation, so that injected IOException is thrown
        zk.create("/foo2", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
        fail("IOException is expected as error is injected in transaction log commit funtionality");
    } catch (Exception e) {
        // do nothing
    }
    zk.close();
    Assert.assertTrue("waiting for server down",
            ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
                    ClientBase.CONNECTION_TIMEOUT));
    fileTxnSnapLogWithError.close();
    main.shutdown();
    main.deleteDirs();
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:57,代碼來源:ZooKeeperServerMainTest.java

示例4: testCorruption

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
@Test
public void testCorruption() throws Exception {
    ClientBase.waitForServerUp(qb.hostPort, 10000);
    ClientBase.waitForServerUp(qb.hostPort, 10000);
    ZooKeeper zk = ClientBase.createZKClient(qb.hostPort, 10000);
    SyncRequestProcessor.setSnapCount(100);
    for (int i = 0; i < 2000; i++) {
        zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                  CreateMode.PERSISTENT, new NoopStringCallback(), null);
    }
    zk.close();

    long leaderSid = 1;
    QuorumPeer leader = null;
    //find out who is the leader and kill it
    for (QuorumPeer quorumPeer : Arrays.asList(qb.s1, qb.s2, qb.s3, qb.s4, qb.s5)) {
        if (quorumPeer.getPeerState() == ServerState.LEADING) {
            leader = quorumPeer;
            break;
        }
        ++leaderSid;
    }

    Assert.assertNotNull("Cannot find the leader.", leader);
    leader.shutdown();

    // now corrupt the leader's database
    FileTxnSnapLog snapLog = leader.getTxnFactory();
    File snapDir= snapLog.getSnapDir();
    //corrupt all the snapshot in the snapshot directory
    corruptAllSnapshots(snapDir);
    qb.shutdownServers();
    qb.setupServers();

    if (leaderSid != 1)qb.s1.start(); else leader = qb.s1;
    if (leaderSid != 2)qb.s2.start(); else leader = qb.s2;
    if (leaderSid != 3)qb.s3.start(); else leader = qb.s3;
    if (leaderSid != 4)qb.s4.start(); else leader = qb.s4;
    if (leaderSid != 5)qb.s5.start(); else leader = qb.s5;

    try {
        leader.start();
        Assert.assertTrue(false);
    } catch(RuntimeException re) {
        LOG.info("Got an error: expected", re);
    }
    //wait for servers to be up
    String[] list = qb.hostPort.split(",");
    for (int i = 0; i < 5; i++) {
        if(leaderSid != (i + 1)) {
            String hp = list[i];
            Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(hp,
                            CONNECTION_TIMEOUT));
            LOG.info("{} is accepting client connections", hp);
        } else {
            LOG.info("Skipping the leader");
        }
    }

    zk = qb.createClient();
    SyncRequestProcessor.setSnapCount(100);
    for (int i = 2000; i < 4000; i++) {
        zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                  CreateMode.PERSISTENT, new NoopStringCallback(), null);
    }
    zk.close();

    if (leaderSid != 1)QuorumBase.shutdown(qb.s1);
    if (leaderSid != 2)QuorumBase.shutdown(qb.s2);
    if (leaderSid != 3)QuorumBase.shutdown(qb.s3);
    if (leaderSid != 4)QuorumBase.shutdown(qb.s4);
    if (leaderSid != 5)QuorumBase.shutdown(qb.s5);
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:75,代碼來源:ZkDatabaseCorruptionTest.java


注:本文中的org.apache.zookeeper.server.persistence.FileTxnSnapLog.getSnapDir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。