Activate infinispan remote testing using docker image

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
olivier lamy 2020-05-11 11:41:42 +10:00 committed by Olivier Lamy
parent a0b9cb3fa4
commit abec84596f
2 changed files with 40 additions and 18 deletions

View File

@ -13,7 +13,10 @@
<bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name> <bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name>
<!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users --> <!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users -->
<!-- 10.1.7.Final --> <!-- 10.1.7.Final -->
<infinispan.docker.version>9.4.11.Final</infinispan.docker.version> <!--could be ${infinispan.version} but maybe we want to test different version of server vs client -->
<infinispan.docker.image.version>9.4.8.Final</infinispan.docker.image.version>
<!-- from 10.xx it has changed to jboss/infinispan -->
<infinispan.docker.image.name>jboss/infinispan-server</infinispan.docker.image.name>
</properties> </properties>
<build> <build>
<plugins> <plugins>
@ -160,7 +163,8 @@
<include>**/*.java</include> <include>**/*.java</include>
</includes> </includes>
<systemPropertyVariables> <systemPropertyVariables>
<infinispan.docker.version>${infinispan.docker.version}</infinispan.docker.version> <infinispan.docker.image.version>${infinispan.docker.image.version}</infinispan.docker.image.version>
<infinispan.docker.image.name>${infinispan.docker.image.name}</infinispan.docker.image.name>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -31,18 +31,19 @@ import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping; import org.hibernate.search.cfg.SearchMapping;
import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller; import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller;
import org.infinispan.protostream.FileDescriptorSource; import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.SerializationContext; import org.infinispan.protostream.SerializationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.output.Slf4jLogConsumer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/** /**
* RemoteInfinispanTestSupport * RemoteInfinispanTestSupport
@ -57,18 +58,28 @@ public class RemoteInfinispanTestSupport
private static final Logger INFINISPAN_LOG = private static final Logger INFINISPAN_LOG =
LoggerFactory.getLogger("org.eclipse.jetty.server.session.remote.infinispanLogs"); LoggerFactory.getLogger("org.eclipse.jetty.server.session.remote.infinispanLogs");
static GenericContainer infinispan = static GenericContainer infinispan;
new GenericContainer("jboss/infinispan-server:" +
System.getProperty("infinispan.docker.version", "9.4.11.Final"))
.withEnv("APP_USER","theuser")
.withEnv("APP_PASS","foobar")
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
static static
{ {
try try
{ {
Testcontainers.exposeHostPorts(11222);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
String infinispanVersion = System.getProperty("infinispan.docker.image.version", "9.4.8.Final");
infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
":" + infinispanVersion)
.withEnv("APP_USER","theuser")
.withEnv("APP_PASS","foobar")
.withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin")
.withExposedPorts(11222)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
if (infinispanVersion.startsWith("9.4"))
{
infinispan = infinispan.withCommand("standalone");
}
infinispan.start(); infinispan.start();
String host = infinispan.getContainerIpAddress(); String host = infinispan.getContainerIpAddress();
System.setProperty("hotrod.host", host); System.setProperty("hotrod.host", host);
@ -83,15 +94,22 @@ public class RemoteInfinispanTestSupport
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping); properties.put(Environment.MODEL_MAPPING, mapping);
ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().withProperties(properties)
clientBuilder.withProperties(properties).addServer().host(host).port(port) .addServer().host(host).port(port)
.security().authentication().enable().realm("default")
.serverName("infinispan")
.saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar")
.marshaller(new ProtoStreamMarshaller()); .marshaller(new ProtoStreamMarshaller());
_manager = new RemoteCacheManager(clientBuilder.build()); if (infinispanVersion.startsWith("1"))
{
configurationBuilder.security().authentication()
.realm("default")
.serverName("infinispan")
.saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar");
}
Configuration configuration = configurationBuilder.build();
_manager = new RemoteCacheManager(configuration);
FileDescriptorSource fds = new FileDescriptorSource(); FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFiles("/session.proto"); fds.addProtoFiles("/session.proto");
@ -111,7 +129,7 @@ public class RemoteInfinispanTestSupport
} }
String content = baos.toString("UTF-8"); String content = baos.toString("UTF-8");
_manager.getCache("___protobuf_metadata").put("session.proto", content); _manager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content);
} }
catch (Exception e) catch (Exception e)
{ {
@ -140,7 +158,7 @@ public class RemoteInfinispanTestSupport
public void setup() throws Exception public void setup() throws Exception
{ {
_cache = _manager.getCache(_name); _cache = _manager.administration().getOrCreateCache(_name,(String)null);
} }
public void teardown() throws Exception public void teardown() throws Exception