From d976c750443b803ecccfc5f9df812dd96e69cdc6 Mon Sep 17 00:00:00 2001 From: xyuanlu Date: Fri, 2 Aug 2024 23:10:37 -0700 Subject: [PATCH] refactor and fix puppy --- .../CreatePuppy.java | 5 +- .../DeletePuppy.java | 7 +- .../TestMultiThreadStressTest/GetPuppy.java | 4 +- .../TestMultiThreadStressTest/SetPuppy.java | 4 +- .../TestMultiThreadStressZKClient.java | 183 ++++++++++-------- .../UpdatePuppy.java | 5 +- .../helix/metaclient/impl/zk/TestUtil.java | 8 + .../helix/metaclient/puppy/AbstractPuppy.java | 4 +- .../leaderelection/LeaderElectionPuppy.java | 7 +- 9 files changed, 127 insertions(+), 100 deletions(-) diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/CreatePuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/CreatePuppy.java index 3940f79ab4..3f5c92f0f0 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/CreatePuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/CreatePuppy.java @@ -29,10 +29,9 @@ public class CreatePuppy extends AbstractPuppy { private final Random _random; - private final String _parentPath = "/test"; - public CreatePuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); + public CreatePuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { + super(metaclient, puppySpec, parentPath); _random = new Random(); } diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/DeletePuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/DeletePuppy.java index 1aa9d4d729..cc066d3a29 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/DeletePuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/DeletePuppy.java @@ -28,11 +28,12 @@ public class DeletePuppy extends AbstractPuppy { private final Random _random; - private final String _parentPath = "/test"; + private final String _parentPath; - public DeletePuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); + public DeletePuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { + super(metaclient, puppySpec, parentPath); _random = new Random(); + _parentPath = parentPath; } @Override diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/GetPuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/GetPuppy.java index 4af1c4df32..0bd8ef25f7 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/GetPuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/GetPuppy.java @@ -31,8 +31,8 @@ public class GetPuppy extends AbstractPuppy { private final Random _random; private final String _parentPath = "/test"; - public GetPuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); + public GetPuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { + super(metaclient, puppySpec, parentPath); _random = new Random(); } diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/SetPuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/SetPuppy.java index 3385b8673b..97301bed4a 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/SetPuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/SetPuppy.java @@ -31,8 +31,8 @@ public class SetPuppy extends AbstractPuppy { private final Random _random; private final String _parentPath = "/test"; - public SetPuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); + public SetPuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { + super(metaclient, puppySpec, parentPath); _random = new Random(); } diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/TestMultiThreadStressZKClient.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/TestMultiThreadStressZKClient.java index 6a01fffa79..90f4905787 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/TestMultiThreadStressZKClient.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/TestMultiThreadStressZKClient.java @@ -35,6 +35,9 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.helix.metaclient.impl.zk.TestUtil.*; + + public class TestMultiThreadStressZKClient extends ZkMetaClientTestBase { private ZkMetaClient _zkMetaClient; @@ -50,12 +53,13 @@ private void setUp() { @Test public void testCreatePuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - CreatePuppy createPuppy2 = new CreatePuppy(_zkMetaClient, puppySpec); - CreatePuppy createPuppy3 = new CreatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + CreatePuppy createPuppy2 = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + CreatePuppy createPuppy3 = new CreatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -67,17 +71,18 @@ public void testCreatePuppy() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testCreatePuppy") public void testDeletePuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -88,17 +93,18 @@ public void testDeletePuppy() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testDeletePuppy") public void testGetPuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -109,17 +115,18 @@ public void testGetPuppy() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testGetPuppy") public void testSetPuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -130,17 +137,18 @@ public void testSetPuppy() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testSetPuppy") public void testUpdatePuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -151,20 +159,21 @@ public void testUpdatePuppy() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testUpdatePuppy") public void testCrudPuppies() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec); - DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec); - SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec); - UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec, testPath); + DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec, testPath); + SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec, testPath); + UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -178,24 +187,25 @@ public void testCrudPuppies() { assertNoExceptions(puppyManager, null); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - - @Test + @Test(dependsOnMethods = "testCrudPuppies") public void testBasicParentListenerPuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); AtomicInteger globalChildChangeCounter = new AtomicInteger(); ChildChangeListener childChangeListener = (changedPath, changeType) -> { globalChildChangeCounter.addAndGet(1); - System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + ". Number of total changes: " + globalChildChangeCounter.get()); + System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + + ". Number of total changes: " + globalChildChangeCounter.get()); }; - _zkMetaClient.subscribeChildChanges(zkParentKey, childChangeListener, false); + _zkMetaClient.subscribeChildChanges(testPath, childChangeListener, false); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -205,28 +215,31 @@ public void testBasicParentListenerPuppy() { assertNoExceptions(puppyManager, globalChildChangeCounter); // cleanup - _zkMetaClient.unsubscribeChildChanges(zkParentKey, childChangeListener); - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.unsubscribeChildChanges(testPath, childChangeListener); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } - @Test + @Test(dependsOnMethods = "testBasicParentListenerPuppy") public void testComplexParentListenerPuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); // Global counter for all child changes AtomicInteger globalChildChangeCounter = new AtomicInteger(); ChildChangeListener childChangeListener = (changedPath, changeType) -> { globalChildChangeCounter.addAndGet(1); - System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + globalChildChangeCounter.get()); + System.out.println( + "-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + + globalChildChangeCounter.get()); }; - _zkMetaClient.subscribeChildChanges(zkParentKey, childChangeListener, false); + _zkMetaClient.subscribeChildChanges(testPath, childChangeListener, false); PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 5); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec); - DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec); - SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec); - UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec, testPath); + DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec, testPath); + SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec, testPath); + UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -240,23 +253,23 @@ public void testComplexParentListenerPuppy() { assertNoExceptions(puppyManager, globalChildChangeCounter); // cleanup - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); - _zkMetaClient.unsubscribeChildChanges(zkParentKey, childChangeListener); - _zkMetaClient.delete(zkParentKey); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); + _zkMetaClient.unsubscribeChildChanges(testPath, childChangeListener); + _zkMetaClient.delete(testPath); } - - @Test + @Test(dependsOnMethods = "testComplexParentListenerPuppy") public void testChildListenerPuppy() { - _zkMetaClient.create(zkParentKey, "test"); + String testPath = zkParentKey + getTestMethodName(); + _zkMetaClient.create(testPath, "test"); // Setting num diff paths to 3 until we find a better way of scaling listeners. PuppySpec puppySpec = new PuppySpec(PuppyMode.REPEAT, 0.2f, new ExecDelay(5000, 0.1f), 3); - CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec); - GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec); - DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec); - SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec); - UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec); + CreatePuppy createPuppy = new CreatePuppy(_zkMetaClient, puppySpec, testPath); + GetPuppy getPuppy = new GetPuppy(_zkMetaClient, puppySpec, testPath); + DeletePuppy deletePuppy = new DeletePuppy(_zkMetaClient, puppySpec, testPath); + SetPuppy setPuppy = new SetPuppy(_zkMetaClient, puppySpec, testPath); + UpdatePuppy updatePuppy = new UpdatePuppy(_zkMetaClient, puppySpec, testPath); PuppyManager puppyManager = new PuppyManager(); puppyManager.addPuppy(createPuppy); @@ -265,28 +278,38 @@ public void testChildListenerPuppy() { puppyManager.addPuppy(setPuppy); puppyManager.addPuppy(updatePuppy); + String childTestPath0 = testPath + "/0"; + String childTestPath1 = testPath + "/1"; + String childTestPath2 = testPath + "/2"; + // Create a child listener for each child defined in number diff paths in puppyspec. // TODO: Make this a parameter for a loop. AtomicInteger childChangeCounter0 = new AtomicInteger(); ChildChangeListener childChangeListener0 = (changedPath, changeType) -> { childChangeCounter0.addAndGet(1); - System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + childChangeCounter0.get()); + System.out.println( + "-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + + childChangeCounter0.get()); }; - _zkMetaClient.subscribeChildChanges("/test/0", childChangeListener0, false); + _zkMetaClient.subscribeChildChanges(childTestPath0, childChangeListener0, false); AtomicInteger childChangeCounter1 = new AtomicInteger(); ChildChangeListener childChangeListener1 = (changedPath, changeType) -> { childChangeCounter1.addAndGet(1); - System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + childChangeCounter1.get()); + System.out.println( + "-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + + childChangeCounter1.get()); }; - _zkMetaClient.subscribeChildChanges("/test/1", childChangeListener1, false); + _zkMetaClient.subscribeChildChanges(childTestPath1, childChangeListener1, false); AtomicInteger childChangeCounter2 = new AtomicInteger(); ChildChangeListener childChangeListener2 = (changedPath, changeType) -> { childChangeCounter2.addAndGet(1); - System.out.println("-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + childChangeCounter2.get()); + System.out.println( + "-------------- Child change detected: " + changeType + " at path: " + changedPath + " number of changes: " + + childChangeCounter2.get()); }; - _zkMetaClient.subscribeChildChanges("/test/2", childChangeListener2, false); + _zkMetaClient.subscribeChildChanges(childTestPath2, childChangeListener2, false); puppyManager.start(TIMEOUT); @@ -314,11 +337,11 @@ public void testChildListenerPuppy() { Assert.assertEquals(childChangeCounter2.get(), mergedEventChangeCounterMap.getOrDefault("2", 0).intValue()); // cleanup - _zkMetaClient.unsubscribeChildChanges("/test/0", childChangeListener0); - _zkMetaClient.unsubscribeChildChanges("/test/1", childChangeListener1); - _zkMetaClient.unsubscribeChildChanges("/test/2", childChangeListener2); - _zkMetaClient.recursiveDelete(zkParentKey); - Assert.assertEquals(_zkMetaClient.countDirectChildren(zkParentKey), 0); + _zkMetaClient.unsubscribeChildChanges(childTestPath0, childChangeListener0); + _zkMetaClient.unsubscribeChildChanges(childTestPath1, childChangeListener1); + _zkMetaClient.unsubscribeChildChanges(childTestPath2, childChangeListener2); + _zkMetaClient.recursiveDelete(testPath); + Assert.assertEquals(_zkMetaClient.countDirectChildren(testPath), 0); } private void assertNoExceptions(PuppyManager puppyManager, AtomicInteger globalChangeCounter) { diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/UpdatePuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/UpdatePuppy.java index 5af055f741..c302567fa5 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/UpdatePuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestMultiThreadStressTest/UpdatePuppy.java @@ -29,10 +29,9 @@ public class UpdatePuppy extends AbstractPuppy { private final Random _random; - private final String _parentPath = "/test"; - public UpdatePuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); + public UpdatePuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { + super(metaclient, puppySpec, parentPath); _random = new Random(); } diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestUtil.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestUtil.java index 92c0182b35..a0aca15e89 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestUtil.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestUtil.java @@ -203,4 +203,12 @@ public static void simulateZkStateClosedAndReconnect(ZkMetaClient client) throws zkClient.process(event); } + /** + * return the name of the calling test method + */ + public static String getTestMethodName() { + StackTraceElement[] calls = Thread.currentThread().getStackTrace(); + return calls[2].getMethodName(); + } + } \ No newline at end of file diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/puppy/AbstractPuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/puppy/AbstractPuppy.java index b16f786156..80189d124d 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/puppy/AbstractPuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/puppy/AbstractPuppy.java @@ -32,11 +32,13 @@ public abstract class AbstractPuppy implements Runnable { protected PuppySpec _puppySpec; public final HashMap _eventChangeCounterMap; public int _unhandledErrorCounter; + protected final String _parentPath ; - public AbstractPuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { + public AbstractPuppy(MetaClientInterface metaclient, PuppySpec puppySpec, String parentPath) { _metaclient = metaclient; _puppySpec = puppySpec; _eventChangeCounterMap = new HashMap<>(); + _parentPath = parentPath; } /** diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/leaderelection/LeaderElectionPuppy.java b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/leaderelection/LeaderElectionPuppy.java index 3f123d3ac8..0b7b6616c0 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/leaderelection/LeaderElectionPuppy.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/leaderelection/LeaderElectionPuppy.java @@ -35,14 +35,9 @@ public class LeaderElectionPuppy extends AbstractPuppy { private final Random _random; LeaderElectionClient _leaderElectionClient; - public LeaderElectionPuppy(MetaClientInterface metaclient, PuppySpec puppySpec) { - super(metaclient, puppySpec); - _random = new Random(); - } - public LeaderElectionPuppy(LeaderElectionClient leaderElectionClient, PuppySpec puppySpec, String leaderGroup, String participant) { - super(leaderElectionClient.getMetaClient(), puppySpec); + super(leaderElectionClient.getMetaClient(), puppySpec, leaderGroup); _leaderElectionClient = leaderElectionClient; _leaderGroup = leaderGroup; _random = new Random();