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


Java ZKDatabase.truncateLog方法代码示例

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


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

示例1: testTruncationStreamReset

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.close();
    ClientBase.recursiveDelete(tmpdir);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:36,代码来源:TruncateTest.java

示例2: testTruncationNullLog

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
@Test
public void testTruncationNullLog() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }
    zkdb.close();
    File[] logs = snaplog.getDataDir().listFiles();
    for(int i = 0; i < logs.length; i++) {
        LOG.debug("Deleting: {}", logs[i].getName());
        Assert.assertTrue("Failed to delete log file: " + logs[i].getName(), logs[i].delete());
    }
    try {
        zkdb.truncateLog(1);
        Assert.assertTrue("Should not get here", false);
    }
    catch(IOException e) {
        Assert.assertTrue("Should have received an IOException", true);
    }
    catch(NullPointerException npe) {
        Assert.fail("This should not throw NPE!");
    }
 
    ClientBase.recursiveDelete(tmpdir);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:29,代码来源:TruncateTest.java

示例3: testTruncationStreamReset

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);
    // make sure to snapshot, so that we have something there when
    // truncateLog reloads the db
    snaplog.save(zkdb.getDataTree(), zkdb.getSessionWithTimeOuts(), false);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.close();
    ClientBase.recursiveDelete(tmpdir);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:39,代码来源:TruncateTest.java

示例4: testTruncationStreamReset

import org.apache.zookeeper.server.ZKDatabase; //导入方法依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:34,代码来源:TruncateTest.java


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