本文整理汇总了Java中org.apache.zookeeper.Transaction.setData方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.setData方法的具体用法?Java Transaction.setData怎么用?Java Transaction.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.Transaction
的用法示例。
在下文中一共展示了Transaction.setData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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));
}
示例3: 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));
}