• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Transaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Transaction类属于org.apache.zookeeper包,在下文中一共展示了Transaction类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testInvalidTransactionOperation

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
@Test
public void testInvalidTransactionOperation() throws Exception {
  zkClient.create("/transaction", "transaction".getBytes(), OPEN_ACL, CreateMode.PERSISTENT) ;
  Transaction transaction = zkClient.transaction();
  transaction.create("/transaction/good", new byte[0], OPEN_ACL, CreateMode.PERSISTENT);
  transaction.create("/transaction/bad/nested", new byte[0], OPEN_ACL, CreateMode.PERSISTENT);
  KeeperException expectError = null;
  try {
    transaction.commit();
  } catch(KeeperException ex) {
    expectError = ex ;
  }
  Assert.assertNotNull(expectError);
  Assert.assertTrue(expectError instanceof KeeperException.NoNodeException);
  Assert.assertNull(zkClient.exists("/transaction/good", false));
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:17,代码来源:ZookeeperTransactionUnitTest.java


示例2: testMultiTransaction

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
/**
 * Test write operations using multi request.
 */
@Test(timeout = 90000)
public void testMultiTransaction() throws Exception {
    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            watcher, true);
    watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected

    final String data = "Data to be read in RO mode";
    final String node1 = "/tnode1";
    final String node2 = "/tnode2";
    zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    watcher.reset();
    qu.shutdown(2);
    watcher.waitForConnected(CONNECTION_TIMEOUT);
    Assert.assertEquals("Should be in r-o mode", States.CONNECTEDREADONLY,
            zk.getState());

    // read operation during r/o mode
    String remoteData = new String(zk.getData(node1, false, null));
    Assert.assertEquals("Failed to read data in r-o mode", data, remoteData);

    try {
        Transaction transaction = zk.transaction();
        transaction.setData(node1, "no way".getBytes(), -1);
        transaction.create(node2, data.getBytes(),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        transaction.commit();
        Assert.fail("Write operation using multi-transaction"
                + " api has succeeded during RO mode");
    } catch (NotReadOnlyException e) {
        // ok
    }

    Assert.assertNull("Should have created the znode:" + node2,
            zk.exists(node2, false));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:42,代码来源:ReadOnlyModeTest.java


示例3: commit

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
private List<OpResult> commit(Transaction txn)
throws KeeperException, InterruptedException {
    if (useAsync) {
        final MultiResult res = new MultiResult();
        txn.commit(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();
            }
        }
        if (KeeperException.Code.OK.intValue() != res.rc) {
            KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc));
            throw ke;
        }
        return res.results;
    } else {
        return txn.commit();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:MultiTransactionTest.java


示例4: testChRootTransaction

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
@Test
public void testChRootTransaction() throws Exception {
    // creating the subtree for chRoot clients.
    String chRoot = createNameSpace();
    // checking the child version using chRoot client.
    zk_chroot = createClient(this.hostPort + chRoot);
    String childPath = "/myid";
    Transaction transaction = zk_chroot.transaction();
    transaction.create(childPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    transaction.check(childPath, 0);
    transaction.setData(childPath, childPath.getBytes(), 0);
    commit(transaction);

    Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk
            .exists(chRoot + childPath, false));
    Assert.assertNotNull("zNode is not created under chroot:" + chRoot,
            zk_chroot.exists(childPath, false));
    Assert.assertNull("zNode is created directly under '/', ignored configured chroot",
                    zk.exists(childPath, false));
    Assert.assertArrayEquals("zNode data not matching", childPath
            .getBytes(), zk_chroot.getData(childPath, false, null));

    transaction = zk_chroot.transaction();
    // Deleting child using chRoot client.
    transaction.delete(childPath, 1);
    commit(transaction);

    Assert.assertNull("chroot:" + chRoot + " exists after delete", zk
            .exists(chRoot + "/myid", false));
    Assert.assertNull("chroot:" + chRoot + " exists after delete",
            zk_chroot.exists("/myid", false));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:MultiTransactionTest.java


示例5: testChRootTransaction

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
@Test
public void testChRootTransaction() throws Exception {
    // creating the subtree for chRoot clients.
    String chRoot = createNameSpace();
    // checking the child version using chRoot client.
    zk_chroot = createClient(this.hostPort + chRoot);
    String childPath = "/myid";
    Transaction transaction = zk_chroot.transaction();
    transaction.create(childPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    transaction.check(childPath, 0);
    transaction.setData(childPath, childPath.getBytes(), 0);
    transaction.commit();

    Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk
            .exists(chRoot + childPath, false));
    Assert.assertNotNull("zNode is not created under chroot:" + chRoot,
            zk_chroot.exists(childPath, false));
    Assert.assertNull("zNode is created directly under '/', ignored configured chroot",
                    zk.exists(childPath, false));
    Assert.assertArrayEquals("zNode data not matching", childPath
            .getBytes(), zk_chroot.getData(childPath, false, null));

    transaction = zk_chroot.transaction();
    // Deleting child using chRoot client.
    transaction.delete(childPath, 1);
    transaction.commit();

    Assert.assertNull("chroot:" + chRoot + " exists after delete", zk
            .exists(chRoot + "/myid", false));
    Assert.assertNull("chroot:" + chRoot + " exists after delete",
            zk_chroot.exists("/myid", false));
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:34,代码来源:MultiTransactionTest.java


示例6: createLog

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
private static void createLog(ZooKeeperClient zk, URI uri, String logName, String logIdentifier)
        throws Exception {
    final String logRootPath = getLogRootPath(uri, logName, logIdentifier);
    final String logSegmentsPath = logRootPath + LOGSEGMENTS_PATH;
    final String maxTxIdPath = logRootPath + MAX_TXID_PATH;
    final String lockPath = logRootPath + LOCK_PATH;
    final String readLockPath = logRootPath + READ_LOCK_PATH;
    final String versionPath = logRootPath + VERSION_PATH;
    final String allocationPath = logRootPath + ALLOCATION_PATH;

    Utils.zkCreateFullPathOptimistic(zk, logRootPath, new byte[0],
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    Transaction txn = zk.get().transaction();
    txn.create(logSegmentsPath, DLUtils.serializeLogSegmentSequenceNumber(
                    DistributedLogConstants.UNASSIGNED_LOGSEGMENT_SEQNO),
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.create(maxTxIdPath, DLUtils.serializeTransactionId(0L),
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.create(lockPath, DistributedLogConstants.EMPTY_BYTES,
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.create(readLockPath, DistributedLogConstants.EMPTY_BYTES,
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.create(versionPath, ZKLogMetadataForWriter.intToBytes(LAYOUT_VERSION),
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.create(allocationPath, DistributedLogConstants.EMPTY_BYTES,
            zk.getDefaultACL(), CreateMode.PERSISTENT);
    txn.commit();
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:29,代码来源:TestZKLogMetadataForWriter.java


示例7: testTransaction

import org.apache.zookeeper.Transaction; //导入依赖的package包/类
@Test
public void testTransaction() throws Exception {
  zkClient.create("/transaction", "transaction".getBytes(), OPEN_ACL, CreateMode.PERSISTENT) ;
  Transaction transaction = zkClient.transaction();
  transaction.create("/transaction/test", new byte[0], OPEN_ACL, CreateMode.PERSISTENT);
  transaction.create("/transaction/test/nested", new byte[0], OPEN_ACL, CreateMode.PERSISTENT);
  transaction.create("/transaction/test/delete", new byte[0], OPEN_ACL, CreateMode.PERSISTENT);
  transaction.delete("/transaction/test/delete", 0);
  Assert.assertNull(zkClient.exists("/transaction/test", false));
  Assert.assertNull(zkClient.exists("/transaction/test/nested", false));
  transaction.commit();
  Assert.assertNotNull(zkClient.exists("/transaction/test", false));
  Assert.assertNotNull(zkClient.exists("/transaction/test/nested", false));
  Assert.assertNull(zkClient.exists("/transaction/test/delete", false));
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:16,代码来源:ZookeeperTransactionUnitTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Schema类代码示例发布时间:2022-05-22
下一篇:
Java SwitchPayload类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap