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


Java DataTree.getNode方法代码示例

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


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

示例1: testTxnFailure

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
/**
 * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
 * after create/delete failure during restore.
 */
@Test
public void testTxnFailure() throws Exception {
    long count = 1;
    File tmpDir = ClientBase.createTmpDir();
    FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir);
    DataTree dt = new DataTree();
    dt.createNode("/test", new byte[0], null, 0, -1, 1, 1);
    for (count = 1; count <= 3; count++) {
        dt.createNode("/test/" + count, new byte[0], null, 0, -1, count,
                System.currentTimeMillis());
    }
    DataNode zk = dt.getNode("/test");

    // Make create to fail, then verify cversion.
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk);

    // Make delete fo fail, then verify cversion.
    // this doesn't happen anymore, we only set the cversion on create
    // LOG.info("Attempting to delete " + "/test/" + (count + 1));
    // doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:LoadFromLogTest.java

示例2: recurseThroughDataTree

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
/**
 * recurse through the old datatree and construct the 
 * new data tree
 * @param dataTree the new datatree to be constructed
 * @param path the path to start with
 */
private void recurseThroughDataTree(DataTree dataTree, String path) {
    if (path == null)
        return;
    DataNodeV1 oldDataNode = oldDataTree.getNode(path);
    HashSet<String> children = oldDataNode.children;
    DataNode parent = null;
    if ("".equals(path)) {
        parent = null;
    }
    else {
        int lastSlash = path.lastIndexOf('/');
        String parentPath = path.substring(0, lastSlash);
        parent = dataTree.getNode(parentPath);
    }
    DataNode thisDatNode = convertDataNode(dataTree, parent,
                                oldDataNode);
    dataTree.addDataNode(path, thisDatNode);
    if (children == null || children.size() == 0) {
        return;
    }
    else {
        for (String child: children) {
            recurseThroughDataTree(dataTree, path + "/" +child);
        }
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:33,代码来源:UpgradeSnapShotV1.java

示例3: testTxnFailure

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
/**
 * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
 * after create/delete failure during restore.
 */
@Test
public void testTxnFailure() throws Exception {
    long count = 1;
    File tmpDir = ClientBase.createTmpDir();
    FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir);
    DataTree dt = new DataTree();
    dt.createNode("/test", new byte[0], null, 0, -1, 1, 1);
    for (count = 1; count <= 3; count++) {
        dt.createNode("/test/" + count, new byte[0], null, 0, -1, count,
                System.currentTimeMillis());
    }
    DataNode zk = dt.getNode("/test");

    // Make create to fail, then verify cversion.
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, -1);

    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk,
            zk.stat.getCversion() + 1);
    
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk,
            zk.stat.getCversion() + 1);
    
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk,
            -1);

    // Make delete fo fail, then verify cversion.
    // this doesn't happen anymore, we only set the cversion on create
    // LOG.info("Attempting to delete " + "/test/" + (count + 1));
    // doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:39,代码来源:LoadFromLogTest.java

示例4: testTxnFailure

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
/**
 * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
 * after create/delete failure during restore.
 */
@Test
public void testTxnFailure() throws Exception {
    long count = 1;
    File tmpDir = ClientBase.createTmpDir();
    FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir);
    DataTree dt = new DataTree();
    dt.createNode("/test", new byte[0], null, 0, -1, 1, 1);
    for (count = 1; count <= 3; count++) {
        dt.createNode("/test/" + count, new byte[0], null, 0, -1, count,
                Time.currentElapsedTime());
    }
    DataNode zk = dt.getNode("/test");

    // Make create to fail, then verify cversion.
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, -1);

    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk,
            zk.stat.getCversion() + 1);

    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk,
            zk.stat.getCversion() + 1);

    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk,
            -1);

    // Make delete fo fail, then verify cversion.
    // this doesn't happen anymore, we only set the cversion on create
    // LOG.info("Attempting to delete " + "/test/" + (count + 1));
    // doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:39,代码来源:LoadFromLogTest.java

示例5: testSerializeDoesntLockDataNodeWhileWriting

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSerializeDoesntLockDataNodeWhileWriting() throws Exception {
    DataTree tree = new DataTree();
    tree.createNode("/marker", new byte[] {42}, null, -1, 1, 1, 1);
    final DataNode markerNode = tree.getNode("/marker");
    final AtomicBoolean ranTestCase = new AtomicBoolean();
    DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream());
    BinaryOutputArchive oa = new BinaryOutputArchive(out) {
        @Override
        public void writeRecord(Record r, String tag) throws IOException {
            DataNode node = (DataNode) r;
            if (node.data.length == 1 && node.data[0] == 42) {
                final Semaphore semaphore = new Semaphore(0);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (markerNode) {
                            //When we lock markerNode, allow writeRecord to continue
                            semaphore.release();
                        }
                    }
                }).start();

                try {
                    boolean acquired = semaphore.tryAcquire(30, TimeUnit.SECONDS);
                    //This is the real assertion - could another thread lock
                    //the DataNode we're currently writing
                    Assert.assertTrue("Couldn't acquire a lock on the DataNode while we were calling tree.serialize", acquired);
                } catch (InterruptedException e1) {
                    throw new RuntimeException(e1);
                }
                ranTestCase.set(true);
            }
            super.writeRecord(r, tag);
        }
    };

    tree.serialize(oa, "test");

    //Let's make sure that we hit the code that ran the real assertion above
    Assert.assertTrue("Didn't find the expected node", ranTestCase.get());
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:43,代码来源:DataTreeTest.java


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