Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.4.x] ISPN-10080 Test cache managers created in other threads cannot join the cluster with UDP #6795

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,46 @@
package org.infinispan.statetransfer;

import static java.util.concurrent.TimeUnit.SECONDS;

import java.util.concurrent.Future;

import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.fwk.CleanupAfterMethod;
import org.infinispan.test.fwk.TestResourceTracker;
import org.testng.annotations.Test;

/**
* Test that a node started in a different thread can join the cluster.
*
* @author Dan Berindei
* @since 10.0
*/
@Test(testName = "statetransfer.JoinInNewThreadTest", groups = "functional")
@CleanupAfterMethod
public class JoinInNewThreadTest extends MultipleCacheManagersTest {
@Override
protected void createCacheManagers() throws Throwable {
// Do nothing here
}

public void testJoinInNewThread() throws Exception {
TestResourceTracker.setThreadTestName(JoinInNewThreadTest.class.getName());

ConfigurationBuilder replCfg = new ConfigurationBuilder();
replCfg.clustering().cacheMode(CacheMode.REPL_SYNC).stateTransfer().timeout(30, SECONDS);

// Connect 2 channels
addClusterEnabledCacheManager(replCfg);
addClusterEnabledCacheManager(replCfg);
waitForClusterToForm();

Future<Void> future = fork(() -> {
TestResourceTracker.testThreadStarted(this);
addClusterEnabledCacheManager(replCfg);
waitForClusterToForm();
});
future.get(30, SECONDS);
}
}
Expand Up @@ -17,6 +17,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.infinispan.commons.util.LegacyKeySupportSystemProperties;
Expand Down Expand Up @@ -52,27 +54,17 @@ protected Integer initialValue() {
/**
* Holds unique mcast_addr for each thread used for JGroups channel construction.
*/
private static final ThreadLocal<String> threadMcastIP = new ThreadLocal<String>() {
private final AtomicInteger uniqueAddr = new AtomicInteger(11);

@Override
protected String initialValue() {
return "228.10.10." + uniqueAddr.getAndIncrement();
}
};

/**
* Holds unique mcast_port for each thread used for JGroups channel construction.
*/
private static final ThreadLocal<Integer> threadMcastPort = new ThreadLocal<Integer>() {
private final AtomicInteger uniquePort = new AtomicInteger(45589);
private static final ThreadLocal<Integer> threadUdpIndex = new ThreadLocal<Integer>() {
private final AtomicInteger counter = new AtomicInteger(0);

@Override
protected Integer initialValue() {
return uniquePort.getAndIncrement();
return counter.getAndIncrement();
}
};

private static final ConcurrentMap<String, Integer> testUdpIndex = new ConcurrentHashMap<>();

static {
JGROUPS_STACK = LegacyKeySupportSystemProperties.getProperty("infinispan.test.jgroups.protocol", "protocol.stack", "udp");
System.out.println("Transport protocol stack used = " + JGROUPS_STACK);
Expand Down Expand Up @@ -100,7 +92,7 @@ public static String getJGroupsConfig(String fullTestName, TransportFlags flags)

configureTestPing(fullTestName, jgroupsCfg);
replaceTcpStartPort(jgroupsCfg, flags);
replaceMCastAddressAndPort(jgroupsCfg);
replaceMCastAddressAndPort(jgroupsCfg, fullTestName);
return jgroupsCfg.toString();
}

Expand Down Expand Up @@ -141,13 +133,15 @@ private static void configureTestPing(String fullTestName, JGroupsProtocolCfg jg
replaceProperties(jgroupsCfg, props, TEST_PING);
}

private static void replaceMCastAddressAndPort(JGroupsProtocolCfg jgroupsCfg) {
private static void replaceMCastAddressAndPort(JGroupsProtocolCfg jgroupsCfg, String fullTestName) {
ProtocolConfiguration udp = jgroupsCfg.getProtocol(UDP);
if (udp == null) return;

Integer udpIndex = testUdpIndex.computeIfAbsent(fullTestName, k -> threadUdpIndex.get());

Map<String, String> props = udp.getProperties();
props.put("mcast_addr", threadMcastIP.get());
props.put("mcast_port", threadMcastPort.get().toString());
props.put("mcast_addr", "228.10.10." + udpIndex);
props.put("mcast_port", String.valueOf(46000 + udpIndex));
replaceProperties(jgroupsCfg, props, UDP);
}

Expand Down