當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。