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


Java KeeperException.getResults方法代码示例

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


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

示例1: TestGetResults

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void TestGetResults() throws Exception {
    /* Delete of a node folowed by an update of the (now) deleted node */
    Iterable<Op> ops = Arrays.asList(
            Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
            Op.delete("/multi", 0),
            Op.setData("/multi", "Y".getBytes(), 0),
            Op.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
    );
    List<OpResult> results = null;
    if (useAsync) {
        final MultiResult res = new MultiResult();
        zk.multi(ops, new MultiCallback() {
            @Override
            public void processResult(int rc, String path, Object ctx,
                                      List<OpResult> opResults) {
                synchronized (res) {
                    res.rc = rc;
                    res.results = opResults;
                    res.finished = true;
                    res.notifyAll();
                }
            }
        }, null);
        synchronized (res) {
            while (!res.finished) {
                res.wait();
            }
        }
        Assert.assertFalse("/multi should have been deleted so setData should have failed",
                           KeeperException.Code.OK.intValue() == res.rc);
        Assert.assertNull(zk.exists("/multi", null));
        results = res.results;
    } else {
        try {
            zk.multi(ops);
            Assert.fail("/multi should have been deleted so setData should have failed");
        } catch (KeeperException e) {
            // '/multi' should never have been created as entire op should fail
            Assert.assertNull(zk.exists("/multi", null));
            results = e.getResults();
        }
    }

    Assert.assertNotNull(results);
    for (OpResult r : results) {
        LOG.info("RESULT==> " + r);
        if (r instanceof ErrorResult) {
            ErrorResult er = (ErrorResult) r;
            LOG.info("ERROR RESULT: " + er + " ERR=>" + KeeperException.Code.get(er.getErr()));
        }
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:54,代码来源:MultiTransactionTest.java

示例2: testGetResults

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testGetResults() throws Exception {
    /* Delete of a node folowed by an update of the (now) deleted node */
    Iterable<Op> ops = Arrays.asList(
            Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
            Op.delete("/multi", 0),
            Op.setData("/multi", "Y".getBytes(), 0),
            Op.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
    );
    List<OpResult> results = null;
    if (useAsync) {
        final MultiResult res = new MultiResult();
        zk.multi(ops, new MultiCallback() {
            @Override
            public void processResult(int rc, String path, Object ctx,
                                      List<OpResult> opResults) {
                synchronized (res) {
                    res.rc = rc;
                    res.results = opResults;
                    res.finished = true;
                    res.notifyAll();
                }
            }
        }, null);
        synchronized (res) {
            while (!res.finished) {
                res.wait();
            }
        }
        Assert.assertFalse("/multi should have been deleted so setData should have failed",
                           KeeperException.Code.OK.intValue() == res.rc);
        Assert.assertNull(zk.exists("/multi", null));
        results = res.results;
    } else {
        try {
            zk.multi(ops);
            Assert.fail("/multi should have been deleted so setData should have failed");
        } catch (KeeperException e) {
            // '/multi' should never have been created as entire op should fail
            Assert.assertNull(zk.exists("/multi", null));
            results = e.getResults();
        }
    }

    Assert.assertNotNull(results);
    for (OpResult r : results) {
        LOG.info("RESULT==> {}", r);
        if (r instanceof ErrorResult) {
            ErrorResult er = (ErrorResult) r;
            LOG.info("ERROR RESULT: {} ERR=>{}", er, KeeperException.Code.get(er.getErr()));
        }
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:54,代码来源:MultiTransactionTest.java


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