Skip to content

Commit

Permalink
CURATOR-558 - uses CuratorTestBase so that retries occur and a short …
Browse files Browse the repository at this point in the history
…session timeout for faster execution
  • Loading branch information
randgalt committed Feb 12, 2020
1 parent 5a04ba4 commit 45a6665
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,9 +54,9 @@ private ClientAndLatch(CuratorFramework client, LeaderLatch latch, int index)
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
{
Expand All @@ -65,7 +65,7 @@ public void testInCluster() throws Exception
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));
Expand All @@ -78,7 +78,7 @@ public void testInCluster() throws Exception

cluster.killServer(instances.get(leader.index));

Thread.sleep(timing.multiple(2).session());
Thread.sleep(sessionLength * 2);

leader = waitForALeader(clients, timing);
Assert.assertNotNull(leader);
Expand All @@ -96,7 +96,13 @@ public void testInCluster() throws Exception
}
}

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 )
{
Expand Down

0 comments on commit 45a6665

Please sign in to comment.