Skip to content

Commit

Permalink
Add server integration test for IRAC
Browse files Browse the repository at this point in the history
  • Loading branch information
pruivo committed May 6, 2020
1 parent 8554956 commit fd84748
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected void start(String name, File rootDir, String configurationFile) {
properties.setProperty(Server.INFINISPAN_CLUSTER_NAME, name);
properties.setProperty(TEST_HOST_ADDRESS, testHostAddress.getHostName());
configuration.properties().forEach((k, v) -> args.add("-D" + k + "=" + StringPropertyReplacer.replaceProperties((String) v, properties)));
configureSite(args);
boolean preserveImageAfterTest = Boolean.parseBoolean(configuration.properties().getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_PRESERVE_IMAGE, "false"));
Path tmp = Paths.get(CommonsTestingUtil.tmpDirectory(this.getClass()));

Expand Down Expand Up @@ -207,7 +208,7 @@ protected void start(String name, File rootDir, String configurationFile) {

if (configuration.isParallelStartup()) {
latch = new CountdownLatchLoggingConsumer(configuration.numServers(), STARTUP_MESSAGE_REGEX);
IntStream.range(0, configuration.numServers()).forEach(i -> createContainer(i));
IntStream.range(0, configuration.numServers()).forEach(this::createContainer);
Exceptions.unchecked(() -> latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
} else {
for (int i = 0; i < configuration.numServers(); i++) {
Expand All @@ -218,6 +219,14 @@ protected void start(String name, File rootDir, String configurationFile) {
}
}

private void configureSite(List<String> args) {
if (configuration.site() == null) {
return;
}
args.add("-Drelay.site_name=" + configuration.site());
args.add("-Djgroups.cluster.mcast_port=" + configuration.siteDiscoveryPort());
}

private GenericContainer createContainer(int i) {

if (this.volumes[i] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.test.Exceptions;
import org.infinispan.commons.util.StringPropertyReplacer;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.server.DefaultExitHandler;
import org.infinispan.server.ExitStatus;
import org.infinispan.server.Server;
import org.infinispan.commons.test.Exceptions;
import org.infinispan.test.TestingUtil;

/**
Expand All @@ -40,7 +40,7 @@ protected EmbeddedInfinispanServerDriver(InfinispanServerTestConfiguration confi
}

protected int clusterPortOffset() {
return 0;
return configuration.site() == null ? 0 : configuration.sitePortOffset();
}

@Override
Expand All @@ -55,6 +55,7 @@ protected void start(String name, File rootDir, String configurationFile) {
properties.setProperty(Server.INFINISPAN_PORT_OFFSET, Integer.toString(clusterPortOffset() + i * OFFSET_FACTOR));
properties.setProperty(Server.INFINISPAN_CLUSTER_NAME, name);
properties.setProperty(TEST_HOST_ADDRESS, testHostAddress.getHostName());
configureSite(properties);
configuration.properties().forEach((k, v) -> properties.put(k, StringPropertyReplacer.replaceProperties((String) v, properties)));
Server server = new Server(serverRoot, new File(configurationFile), properties);
server.setExitHandler(new DefaultExitHandler());
Expand Down Expand Up @@ -148,4 +149,14 @@ public RemoteCacheManager createRemoteCacheManager(ConfigurationBuilder builder)
public int getTimeout() {
return TIMEOUT_SECONDS;
}

private void configureSite(Properties properties) {
if (configuration.site() == null) {
return; //nothing to configure
}
//we need to replace the properties in xsite-stacks.xml
properties.setProperty("relay.site_name", configuration.site());
properties.setProperty("jgroups.cluster.mcast_port", Integer.toString(configuration.siteDiscoveryPort()));

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.infinispan.server.test.core;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -10,6 +13,22 @@
**/
public class InfinispanServerTestConfiguration {

//site names must match the same names defined in xsite-stacks.xml
public static final String LON = "LON";
public static final String NYC = "NYC";

//each site needs a different discovery port otherwise they will be merged
private static final Map<String, Integer> SITE_DISCOVER_PORTS_OFFSET;
private static final int DEFAULT_DISCOVER_PORT = 46655;

static {
Map<String, Integer> ports = new HashMap<>();
//46655 is the default! don't use it!
ports.put(LON, 1000);
ports.put(NYC, 2000);
SITE_DISCOVER_PORTS_OFFSET = Collections.unmodifiableMap(ports);
}

private final String configurationFile;
private final int numServers;
private final ServerRunMode runMode;
Expand All @@ -18,10 +37,11 @@ public class InfinispanServerTestConfiguration {
private final JavaArchive[] archives;
private final boolean jmx;
private final boolean parallelStartup;
private final String site;

public InfinispanServerTestConfiguration(String configurationFile, int numServers, ServerRunMode runMode,
Properties properties, String[] mavenArtifacts, JavaArchive[] archives,
boolean jmx, boolean parallelStartup) {
Properties properties, String[] mavenArtifacts, JavaArchive[] archives,
boolean jmx, boolean parallelStartup, String site) {
this.configurationFile = configurationFile;
this.numServers = numServers;
this.runMode = runMode;
Expand All @@ -30,6 +50,7 @@ public InfinispanServerTestConfiguration(String configurationFile, int numServer
this.archives = archives;
this.jmx = jmx;
this.parallelStartup = parallelStartup;
this.site = site;
}

public String configurationFile() {
Expand Down Expand Up @@ -63,4 +84,17 @@ public String[] mavenArtifacts() {
public boolean isParallelStartup() {
return parallelStartup;
}

public String site() {
return site;
}

public int siteDiscoveryPort() {
return DEFAULT_DISCOVER_PORT + sitePortOffset();
}

public int sitePortOffset() {
return SITE_DISCOVER_PORTS_OFFSET.get(site);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
**/
public class InfinispanServerRule implements TestRule {
private InfinispanServerDriver serverDriver;
private InfinispanServerTestConfiguration configuration;
private final InfinispanServerTestConfiguration configuration;
protected final List<Consumer<File>> configurationEnhancers = new ArrayList<>();

public InfinispanServerRule(InfinispanServerTestConfiguration configuration) {
Expand Down Expand Up @@ -68,7 +68,8 @@ public void evaluate() throws Throwable {
String testName = description.getTestClass().getName();
RunWith runWith = description.getTestClass().getAnnotation(RunWith.class);
boolean inSuite = runWith != null && runWith.value() == Suite.class;
if (!inSuite) {
boolean hasXsite = configuration.site() != null;
if (!inSuite && !hasXsite) {
TestResourceTracker.testStarted(testName);
}
// Don't manage the server when a test is using the same InfinispanServerRule instance as the parent suite
Expand All @@ -90,7 +91,7 @@ public void evaluate() throws Throwable {
if (manageServer && serverDriver != null) {
serverDriver.stop(testName);
}
if (!inSuite) {
if (!inSuite && !hasXsite) {
TestResourceTracker.testFinished(testName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class InfinispanServerRuleBuilder {
private JavaArchive[] archives;
private boolean jmx;
private boolean parallelStartup = true;
private String site;

public static InfinispanServerRuleBuilder config(String configurationFile) {
return new InfinispanServerRuleBuilder(configurationFile);
Expand Down Expand Up @@ -78,10 +79,18 @@ public InfinispanServerRuleBuilder parallelStartup(boolean parallel) {
return this;
}

/**
* Sets the current site name
*/
public InfinispanServerRuleBuilder site(String site) {
this.site = site;
return this;
}

public InfinispanServerRule build() {
InfinispanServerTestConfiguration configuration =
new InfinispanServerTestConfiguration(configurationFile, numServers, runMode, this.properties, mavenArtifacts,
archives, jmx, parallelStartup);
archives, jmx, parallelStartup, site);
return new InfinispanServerRule(configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void createSourceClusterCache(RestClient client) {
private static class ClusterConfiguration extends InfinispanServerTestConfiguration {
public ClusterConfiguration(String configurationFile, int numServers) {
super(configurationFile, numServers, ServerRunMode.EMBEDDED, new Properties(), null, null,
false, false);
false, false, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.infinispan.server.functional;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.commons.test.Eventually;
import org.infinispan.server.test.junit4.InfinispanServerRule;
import org.infinispan.server.test.junit4.InfinispanServerTestMethodRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

/**
* @author Pedro Ruivo
* @since 11.0
**/
public class XSiteHotRodCacheOperations {

@ClassRule
public static final InfinispanServerRule LON_SERVERS = XSiteIT.LON_SERVERS;
@ClassRule
public static final InfinispanServerRule NYC_SERVERS = XSiteIT.NYC_SERVERS;

private static final String LON_CACHE_XML_CONFIG =
"<infinispan><cache-container>" +
" <distributed-cache-configuration name=\"%s\">" +
" <backups>" +
" <backup site=\"NYC\" strategy=\"ASYNC\"/>" +
" </backups>" +
" </distributed-cache-configuration>" +
"</cache-container></infinispan>";
@Rule
public InfinispanServerTestMethodRule LON_SERVER_TEST = new InfinispanServerTestMethodRule(XSiteIT.LON_SERVERS);

@Rule
public InfinispanServerTestMethodRule NYC_SERVER_TEST = new InfinispanServerTestMethodRule(XSiteIT.NYC_SERVERS);

@Test
public void testHotRodOperations() {
String lonXML = String.format(LON_CACHE_XML_CONFIG, LON_SERVER_TEST.getMethodName());

RemoteCache<String, String> lonCache = LON_SERVER_TEST.hotrod()
.withServerConfiguration(new XMLStringConfiguration(lonXML)).create();
RemoteCache<String, String> nycCache = NYC_SERVER_TEST.hotrod().create(); //must have the same name as LON cache

lonCache.put("k1", "v1");
nycCache.put("k2", "v2"); //nyc cache don't backup to lon

Eventually.eventuallyEquals("v1", () -> lonCache.get("k1"));
Eventually.eventuallyEquals("v1", () -> nycCache.get("k1"));

Eventually.eventuallyEquals(null, () -> lonCache.get("k2"));
Eventually.eventuallyEquals("v2", () -> nycCache.get("k2"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.infinispan.server.functional;

import org.infinispan.server.test.core.InfinispanServerTestConfiguration;
import org.infinispan.server.test.junit4.InfinispanServerRule;
import org.infinispan.server.test.junit4.InfinispanServerRuleBuilder;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
* Cross-Site suite
*
* @author Pedro Ruivo
* @since 11.0
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
XSiteHotRodCacheOperations.class
})
public class XSiteIT {
@ClassRule
public static final InfinispanServerRule LON_SERVERS =
InfinispanServerRuleBuilder.config("configuration/XSiteServerTest.xml")
.numServers(3)
.site(InfinispanServerTestConfiguration.LON)
.build();
@ClassRule
public static final InfinispanServerRule NYC_SERVERS =
InfinispanServerRuleBuilder.config("configuration/XSiteServerTest.xml")
.numServers(3)
.site(InfinispanServerTestConfiguration.NYC)
.build();
}
23 changes: 23 additions & 0 deletions server/tests/src/test/resources/configuration/XSiteServerTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="urn:infinispan:config:11.0 https://infinispan.org/schemas/infinispan-config-11.0.xsd
urn:infinispan:server:11.0 https://infinispan.org/schemas/infinispan-server-11.0.xsd"
xmlns="urn:infinispan:config:11.0"
xmlns:server="urn:infinispan:server:11.0">

<xi:include href="jgroups/xsite-stacks.xml"/>

<xi:include href="cache-container/clustered.xml"/>

<server xmlns="urn:infinispan:server:11.0">

<xi:include href="interfaces/default.xml"/>

<xi:include href="socket-bindings/default.xml"/>

<xi:include href="security/none.xml"/>

<xi:include href="endpoints/default.xml"/>
</server>
</infinispan>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<jgroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:11.0 https://infinispan.org/schemas/infinispan-config-fragment-11.0.xsd
urn:org:jgroups http://www.jgroups.org/schema/jgroups-4.0.xsd"
xmlns="urn:infinispan:config:11.0"
xmlns:ispn="urn:infinispan:config:11.0">
<stack name="test-tcp" extends="tcp">
<MPING bind_addr="${jgroups.bind.address,jgroups.tcp.address:127.0.0.1}"
mcast_addr="${jgroups.mcast_addr:228.6.7.8}"
mcast_port="${jgroups.cluster.mcast_port}"
num_discovery_runs="3"
ip_ttl="${jgroups.udp.ip_ttl:2}"
ispn:stack.combine="REPLACE"
/>
<MERGE3 min_interval="1000" max_interval="5000" ispn:stack.combine="REPLACE"/>
<FD_SOCK sock_conn_timeout="3000"/>
<FD_ALL3 timeout="3000"
interval="1000"
ispn:stack.combine="REPLACE" ispn:stack.position="FD_ALL"/>
<relay.RELAY2 site="${relay.site_name}" max_site_masters="3" xmlns="urn:org:jgroups"/>
<remote-sites default-stack="tcp">
<remote-site name="LON"/>
<remote-site name="NYC"/>
</remote-sites>
</stack>
<stack name="test-udp" extends="udp">
<UDP bind_addr="${jgroups.bind.address,jgroups.udp.address:SITE_LOCAL}"
bind_port="${jgroups.bind.port,jgroups.udp.port:0}"
mcast_addr="${jgroups.mcast_addr:228.6.7.8}"
mcast_port="${jgroups.cluster.mcast_port}"
tos="0"
ucast_send_buf_size="1m"
mcast_send_buf_size="1m"
ucast_recv_buf_size="20m"
mcast_recv_buf_size="25m"
ip_ttl="${jgroups.ip_ttl:2}"
thread_naming_pattern="pl"
enable_diagnostics="false"
bundler_type="no-bundler"
max_bundle_size="8500"

thread_pool.min_threads="${jgroups.thread_pool.min_threads:0}"
thread_pool.max_threads="${jgroups.thread_pool.max_threads:200}"
thread_pool.keep_alive_time="60000"
ispn:stack.combine="REPLACE"
/>
<MERGE3 min_interval="1000" max_interval="5000" ispn:stack.combine="REPLACE"/>
<FD_SOCK sock_conn_timeout="3000"/>
<FD_ALL3 timeout="3000"
interval="1000"
ispn:stack.combine="REPLACE" ispn:stack.position="FD_ALL"/>
<relay.RELAY2 site="${relay.site_name}" max_site_masters="3" xmlns="urn:org:jgroups"/>
<remote-sites default-stack="tcp">
<remote-site name="LON"/>
<remote-site name="NYC"/>
</remote-sites>
</stack>
</jgroups>

0 comments on commit fd84748

Please sign in to comment.