This is an automated email from the ASF dual-hosted git repository. jxue pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/helix.git
commit 09649b34c4941adfab951defa52975683393bb80 Author: Marcos Rico Peng <55266861+marcosr...@users.noreply.github.com> AuthorDate: Wed Jun 7 17:36:51 2023 -0400 [helix/metaclient] ZkMetaClient Stress Tests (Part 2) (#2523) ZkMetaClient Stress Tests (Part 2) --------- Co-authored-by: mapeng <map...@linkedin.com> --- .../metaclient/impl/zk/TestStressZkClient.java | 96 +++++++++++++++++++--- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestStressZkClient.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestStressZkClient.java index 393a17f1b..8a3f9c115 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestStressZkClient.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestStressZkClient.java @@ -19,27 +19,18 @@ package org.apache.helix.metaclient.impl.zk; * under the License. */ -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.List; +import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.helix.metaclient.api.DataChangeListener; -import org.apache.helix.metaclient.api.DataUpdater; -import org.apache.helix.metaclient.api.MetaClientInterface; + +import org.apache.helix.metaclient.api.*; import org.apache.helix.metaclient.datamodel.DataRecord; import org.apache.helix.metaclient.exception.MetaClientException; import org.apache.helix.metaclient.impl.zk.factory.ZkMetaClientConfig; import org.apache.helix.metaclient.recipes.lock.DataRecordSerializer; -import org.apache.helix.zookeeper.datamodel.ZNRecord; -import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer; -import org.apache.helix.zookeeper.exception.ZkClientException; -import org.junit.Before; import org.testng.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -114,6 +105,29 @@ public class TestStressZkClient extends ZkMetaClientTestBase { Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); } + @Test + public void testCreateAndRenewTTL() { + final String zkParentKey = "/stressZk_testCreateAndRenewTTL"; + _zkMetaClient.create(zkParentKey, ENTRY_STRING_VALUE); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + _zkMetaClient.createWithTTL(zkParentKey + i, ENTRY_STRING_VALUE, 10000); + } + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + Assert.assertNotNull(_zkMetaClient.exists(zkParentKey)); + } + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + _zkMetaClient.renewTTLNode(zkParentKey + i); + } + MetaClientInterface.Stat stat; + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + stat = _zkMetaClient.exists(zkParentKey + i); + Assert.assertNotSame(stat.getCreationTime(), stat.getModifiedTime()); + } + // cleanup + _zkMetaClient.recursiveDelete(zkParentKey); + Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + } + @Test public void testGet() { final String zkParentKey = "/stressZk_testGet"; @@ -369,4 +383,60 @@ public class TestStressZkClient extends ZkMetaClientTestBase { _zkMetaClient.recursiveDelete(zkParentKey); Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); } + + @Test + public void testTransactionOps() { + String zkParentKey = "/stressZk_testTransactionOp"; + _zkMetaClient.create(zkParentKey, "parent_node"); + + // Transaction Create + List<Op> ops = new ArrayList<>(); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + ops.add(Op.create(zkParentKey + "/" + i, new byte[0], PERSISTENT)); + } + List<OpResult> opResults = _zkMetaClient.transactionOP(ops); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + Assert.assertTrue(opResults.get(i) instanceof OpResult.CreateResult); + } + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + Assert.assertNotNull(_zkMetaClient.exists(zkParentKey + "/" + i)); + } + + // Transaction Set + List<Op> ops_set = new ArrayList<>(); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + ops_set.add(Op.set(zkParentKey + "/" + i, new byte[0], -1)); + } + List<OpResult> opsResultSet = _zkMetaClient.transactionOP(ops_set); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + Assert.assertTrue(opsResultSet.get(i) instanceof OpResult.SetDataResult); + } + + // Transaction Delete + List<Op> ops_delete = new ArrayList<>(); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + ops_delete.add(Op.delete(zkParentKey + "/" + i, -1)); + } + List<OpResult> opsResultDelete = _zkMetaClient.transactionOP(ops_delete); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + Assert.assertTrue(opsResultDelete.get(i) instanceof OpResult.DeleteResult); + } + + // Transaction Create + List<Op> ops_error = new ArrayList<>(); + for (int i = 0; i < TEST_ITERATION_COUNT; i++) { + ops_error.add(Op.create("/_invalid/a/b/c" + "/" + i, new byte[0], PERSISTENT)); + } + try { + _zkMetaClient.transactionOP(ops_error); + Assert.fail("Should fail"); + } catch (Exception e) { + // OK + } + + + // cleanup + _zkMetaClient.recursiveDelete(zkParentKey); + Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + } } \ No newline at end of file