You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2020/02/20 03:31:33 UTC

[curator] 02/03: CURATOR-558 - uses CuratorTestBase so that retries occur and a short session timeout for faster execution

This is an automated email from the ASF dual-hosted git repository.

randgalt pushed a commit to branch CURATOR-558-pt1-remove-zk40-etc
in repository https://gitbox.apache.org/repos/asf/curator.git

commit 9990dbfb326af8d24fe4dd97795706fd6bbbe9f1
Author: randgalt <ra...@apache.org>
AuthorDate: Sun Feb 2 15:31:15 2020 -0500

    CURATOR-558 - uses CuratorTestBase so that retries occur and a short session timeout for faster execution
---
 .../recipes/leader/TestLeaderLatchCluster.java     | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatchCluster.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatchCluster.java
index 8744bd2..0d08199 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatchCluster.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatchCluster.java
@@ -19,20 +19,20 @@
 package org.apache.curator.framework.recipes.leader;
 
 import com.google.common.collect.Lists;
-import org.apache.curator.utils.CloseableUtils;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;
-import org.apache.curator.test.Timing;
+import org.apache.curator.test.compatibility.CuratorTestBase;
+import org.apache.curator.test.compatibility.Timing2;
+import org.apache.curator.utils.CloseableUtils;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 import java.util.Collection;
 import java.util.List;
 
-public class TestLeaderLatchCluster
+public class TestLeaderLatchCluster extends CuratorTestBase
 {
     private static final int MAX_LOOPS = 5;
 
@@ -54,9 +54,9 @@ public class TestLeaderLatchCluster
     public void testInCluster() throws Exception
     {
         final int PARTICIPANT_QTY = 3;
+        final int sessionLength = timing.session() / 4;
 
         List<ClientAndLatch>    clients = Lists.newArrayList();
-        Timing                  timing = new Timing();
         TestingCluster          cluster = new TestingCluster(PARTICIPANT_QTY);
         try
         {
@@ -65,7 +65,7 @@ public class TestLeaderLatchCluster
             List<InstanceSpec>      instances = Lists.newArrayList(cluster.getInstances());
             for ( int i = 0; i < PARTICIPANT_QTY; ++i )
             {
-                CuratorFramework        client = CuratorFrameworkFactory.newClient(instances.get(i).getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
+                CuratorFramework        client = CuratorFrameworkFactory.newClient(instances.get(i).getConnectString(), sessionLength, sessionLength, new ExponentialBackoffRetry(100, 3));
                 LeaderLatch             latch = new LeaderLatch(client, "/latch");
 
                 clients.add(new ClientAndLatch(client, latch, i));
@@ -78,7 +78,7 @@ public class TestLeaderLatchCluster
 
             cluster.killServer(instances.get(leader.index));
 
-            Thread.sleep(timing.multiple(2).session());
+            Thread.sleep(sessionLength * 2);
 
             leader = waitForALeader(clients, timing);
             Assert.assertNotNull(leader);
@@ -96,7 +96,13 @@ public class TestLeaderLatchCluster
         }
     }
 
-    private ClientAndLatch waitForALeader(List<ClientAndLatch> latches, Timing timing) throws InterruptedException
+    @Override
+    protected void createServer()
+    {
+        // NOP
+    }
+
+    private ClientAndLatch waitForALeader(List<ClientAndLatch> latches, Timing2 timing) throws InterruptedException
     {
         for ( int i = 0; i < MAX_LOOPS; ++i )
         {