xyuanlu commented on code in PR #2328:
URL: https://github.com/apache/helix/pull/2328#discussion_r1063835557
##########
zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/RealmAwareZkClientTestBase.java:
##########
@@ -67,4 +76,132 @@ public void afterClass() {
_msdsServer.stopServer();
}
}
-}
+ /**
+ * Initialize requirement for testing multi support.
+ */
+ @Test
+ public void testMultiSetup() throws InvalidRoutingDataException {
+ // Create a connection config with a valid sharding key
+ RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder builder =
+ new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder();
+ RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig =
+ builder.setZkRealmShardingKey(ZK_SHARDING_KEY_PREFIX).build();
+
+ _realmAwareZkClient = new FederatedZkClient(connectionConfig,
+ new RealmAwareZkClient.RealmAwareZkClientConfig());
+ }
+
+ /**
+ * Test that zk multi works for create.
+ */
+ @Test(dependsOnMethods = "testMultiSetup")
+ public void testMultiCreate() {
+ String test_name = "/test_multi_create";
+
+ //Create Nodes
+ List<Op> ops = Arrays.asList(
+ Op.create(PARENT_PATH, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
+ Op.create(PARENT_PATH + test_name, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
+
+ //Execute transactional support on operations and verify they were run
+ List<OpResult> opResults = _realmAwareZkClient.multi(ops);
+ Assert.assertTrue(opResults.get(0) instanceof OpResult.CreateResult);
+ Assert.assertTrue(opResults.get(1) instanceof OpResult.CreateResult);
+
+ //Verify that the znodes were created
+ Assert.assertTrue(_realmAwareZkClient.exists(PARENT_PATH), "Path has not
been created.");
+ Assert.assertTrue(_realmAwareZkClient.exists(PARENT_PATH + test_name),
"Path has not been created.");
+
+ cleanup();
+ }
+
+ /**
+ * Multi should be an all or nothing transaction. Creating correct
+ * paths and a singular bad one should all fail.
+ */
+ @Test(dependsOnMethods = "testMultiCreate")
+ public void testMultiFail() {
+ String test_name = "/test_multi_fail";
+ //Create Nodes
+ List<Op> ops = Arrays.asList(
+ Op.create(PARENT_PATH, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
+ Op.create(PARENT_PATH + test_name, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
+ Op.create(TEST_INVALID_PATH, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
+ try {
+ _realmAwareZkClient.multi(ops);
+ Assert.fail("Should have thrown an exception. Cannot run multi on
incorrect path.");
+ } catch (Exception e) {
+ boolean pathExists = _realmAwareZkClient.exists(PARENT_PATH);
+ Assert.assertFalse(pathExists, "Path should not have been created.");
+
+ cleanup();
+ }
+ }
+
+ /**
+ * Test that zk multi works for delete.
+ */
+ @Test(dependsOnMethods = "testMultiFail")
+ public void testMultiDelete() {
+ String test_name = "/test_multi_delete";
+ //Create Nodes
+ List<Op> ops = Arrays.asList(
+ Op.create(PARENT_PATH, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
+ Op.create(PARENT_PATH + test_name, new byte[0],
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
+ Op.delete(PARENT_PATH + test_name, -1));
+
+ List<OpResult> opResults = _realmAwareZkClient.multi(ops);
+ Assert.assertTrue(opResults.get(0) instanceof OpResult.CreateResult);
+ Assert.assertTrue(opResults.get(1) instanceof OpResult.CreateResult);
+ Assert.assertTrue(opResults.get(2) instanceof OpResult.DeleteResult);
+
+ Assert.assertTrue(_realmAwareZkClient.exists(PARENT_PATH), "Path has not
been created.");
+ Assert.assertFalse(_realmAwareZkClient.exists(PARENT_PATH + test_name),
"Path should have been removed.");
Review Comment:
I guess the message should be the opposite?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]