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


Java FileTxnSnapLog.getDataDir方法代碼示例

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


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


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