Jetty 10.0.x correctly shutdown infinispan between tests (#7066)

* correctly shutdown infinispan after each test class

Signed-off-by: Olivier Lamy <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2021-11-09 15:34:47 +10:00 committed by GitHub
parent d571436d00
commit 0ad49fd1fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 146 additions and 94 deletions

View File

@ -54,7 +54,6 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
private GenericContainer<?> hazelcast = new GenericContainer<>("hazelcast/hazelcast:" + System.getProperty("hazelcast.version", "4.2.2"))
.withExposedPorts(5701)
.waitingFor(Wait.forLogMessage(".*is STARTED.*", 1))
//.waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(120L)))
.withLogConsumer(new Slf4jLogConsumer(HAZELCAST_LOG));
private Path hazelcastJettyPath;

View File

@ -22,7 +22,6 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
/**
*

View File

@ -20,10 +20,8 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;
/**

View File

@ -45,6 +45,7 @@ public class RemoteClusteredInvalidationSessionTest extends AbstractClusteredInv
public static void teardown() throws Exception
{
__testSupport.teardown();
__testSupport.shutdown();
}
@Override

View File

@ -45,6 +45,7 @@ public class RemoteClusteredSessionScavengingTest extends AbstractClusteredSessi
public static void teardown() throws Exception
{
__testSupport.teardown();
__testSupport.shutdown();
}
@Override

View File

@ -30,7 +30,9 @@ import org.infinispan.client.hotrod.Search;
import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory;
import org.infinispan.query.dsl.QueryResult;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
@ -55,11 +57,16 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
{
super();
}
@BeforeAll
public static void initRemoteSupport() throws Exception
{
__testSupport = new RemoteInfinispanTestSupport("remote-session-test");
}
@BeforeEach
public void setup() throws Exception
{
__testSupport = new RemoteInfinispanTestSupport("remote-session-test");
__testSupport.setup();
}
@ -69,6 +76,12 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
__testSupport.teardown();
}
@AfterAll
public static void shutdown() throws Exception
{
__testSupport.shutdown();
}
@Override
public SessionDataStoreFactory createSessionDataStoreFactory()
{

View File

@ -16,6 +16,7 @@ package org.eclipse.jetty.server.session.remote;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.annotation.ElementType;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.eclipse.jetty.server.session.SessionData;
@ -35,7 +36,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.containers.wait.strategy.Wait;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -49,58 +49,82 @@ public class RemoteInfinispanTestSupport
private static final Logger LOG = LoggerFactory.getLogger(RemoteInfinispanTestSupport.class);
public static final String DEFAULT_CACHE_NAME = "session_test_cache";
public RemoteCache<String, InfinispanSessionData> _cache;
private String _name;
public static RemoteCacheManager _manager;
private final String _name;
public RemoteCacheManager _manager;
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;
private static final String IMAGE_NAME = System.getProperty("infinispan.docker.image.name", "infinispan/server") +
":" + System.getProperty("infinispan.docker.image.version", "11.0.9.Final");
static
private static final GenericContainer INFINISPAN = new GenericContainer(IMAGE_NAME)
.withEnv("USER", "theuser")
.withEnv("PASS", "foobar")
.withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin")
.waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*\\s", 1))
.withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
private static final String INFINISPAN_VERSION = System.getProperty("infinispan.docker.image.version", "11.0.9.Final");
public RemoteInfinispanTestSupport()
{
this(null);
}
public RemoteInfinispanTestSupport(String cacheName)
{
if (cacheName == null)
cacheName = DEFAULT_CACHE_NAME + System.currentTimeMillis();
_name = cacheName;
if (!INFINISPAN.isRunning())
{
try
{
long start = System.currentTimeMillis();
INFINISPAN.start();
System.setProperty("hotrod.host", INFINISPAN.getContainerIpAddress());
LOG.info("Infinispan container started for {}:{} - {}ms",
INFINISPAN.getContainerIpAddress(),
INFINISPAN.getMappedPort(11222),
System.currentTimeMillis() - start);
}
catch (Exception e)
{
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
try
{
//Testcontainers.exposeHostPorts(11222);
long start = System.currentTimeMillis();
String infinispanVersion = System.getProperty("infinispan.docker.image.version", "11.0.9.Final");
infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "infinispan/server") +
":" + infinispanVersion)
.withEnv("USER", "theuser")
.withEnv("PASS", "foobar")
.withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin")
.waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*\\s", 1))
.withExposedPorts(4712, 4713, 8088, 8089, 8443, 9990, 9993, 11211, 11222, 11223, 11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
infinispan.start();
String host = infinispan.getContainerIpAddress();
System.setProperty("hotrod.host", host);
int port = infinispan.getMappedPort(11222);
LOG.info("Infinispan container started for {}:{} - {}ms", host, port,
System.currentTimeMillis() - start);
SearchMapping mapping = new SearchMapping();
mapping.entity(InfinispanSessionData.class).indexed().providedId()
.property("expiry", ElementType.METHOD).field();
.property("expiry", ElementType.METHOD).field();
Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping);
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().withProperties(properties)
.addServer().host(host).port(port)
// we just want to limit connectivity to list of host:port we knows at start
// as infinispan create new host:port dynamically but due to how docker expose host/port we cannot do that
.clientIntelligence(ClientIntelligence.BASIC)
.marshaller(new ProtoStreamMarshaller());
.addServer()
.host(INFINISPAN.getContainerIpAddress())
.port(INFINISPAN.getMappedPort(11222))
// we just want to limit connectivity to list of host:port we knows at start
// as infinispan create new host:port dynamically but due to how docker expose host/port we cannot do that
.clientIntelligence(ClientIntelligence.BASIC)
.marshaller(new ProtoStreamMarshaller());
if (infinispanVersion.startsWith("1"))
if (INFINISPAN_VERSION.startsWith("1"))
{
configurationBuilder.security().authentication()
.saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar");
.saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar");
}
configurationBuilder.addContextInitializer(new InfinispanSerializationContextInitializer());
Configuration configuration = configurationBuilder.build();
@ -117,7 +141,7 @@ public class RemoteInfinispanTestSupport
IO.copy(is, baos);
}
String content = baos.toString("UTF-8");
String content = baos.toString(StandardCharsets.UTF_8);
_manager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content);
}
catch (Exception e)
@ -125,19 +149,7 @@ public class RemoteInfinispanTestSupport
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
public RemoteInfinispanTestSupport()
{
this(null);
}
public RemoteInfinispanTestSupport(String cacheName)
{
if (cacheName == null)
cacheName = DEFAULT_CACHE_NAME + System.currentTimeMillis();
_name = cacheName;
}
public RemoteCache<String, InfinispanSessionData> getCache()
@ -163,6 +175,11 @@ public class RemoteInfinispanTestSupport
_cache.clear();
}
public void shutdown() throws Exception
{
INFINISPAN.stop();
}
public void createSession(InfinispanSessionData data)
throws Exception
{

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.server.session.SessionDataStore;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.eclipse.jetty.server.session.TestServer;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
@ -157,4 +158,10 @@ public class CachingSessionDataStoreTest
}
}
}
@AfterAll
public static void shutdown() throws Exception
{
MemcachedTestHelper.shutdown();
}
}

View File

@ -152,24 +152,28 @@ public class MemcachedTestHelper
.withExposedPorts(11211)
.withLogConsumer(new Slf4jLogConsumer(MEMCACHED_LOG));
static
public static void shutdown() throws Exception
{
try
{
long start = System.currentTimeMillis();
memcached.start();
LOG.info("time to start memcache instance {}ms on {}:{}", System.currentTimeMillis() - start,
memcached.getHost(), memcached.getMappedPort(11211));
}
catch (Exception e)
{
LOG.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
memcached.stop();
}
public static SessionDataStoreFactory newSessionDataStoreFactory()
{
if (!memcached.isRunning())
{
try
{
long start = System.currentTimeMillis();
memcached.start();
LOG.info("time to start memcache instance {}ms on {}:{}", System.currentTimeMillis() - start,
memcached.getHost(), memcached.getMappedPort(11211));
}
catch (Exception e)
{
LOG.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
MockDataStoreFactory storeFactory = new MockDataStoreFactory();
MemcachedSessionDataMapFactory mapFactory = new MemcachedSessionDataMapFactory();
String host = memcached.getContainerIpAddress();

View File

@ -50,7 +50,6 @@ public class AttributeNameTest
@BeforeAll
public static void beforeClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.createCollection();
}
@ -58,6 +57,7 @@ public class AttributeNameTest
public static void afterClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.shutdown();
}
@Test

View File

@ -25,7 +25,6 @@ public class ClusteredInvalidateSessionTest extends AbstractClusteredInvalidatio
@BeforeAll
public static void beforeClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.createCollection();
}
@ -33,6 +32,7 @@ public class ClusteredInvalidateSessionTest extends AbstractClusteredInvalidatio
public static void afterClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.shutdown();
}
@Override

View File

@ -29,7 +29,6 @@ public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessi
@BeforeAll
public static void beforeClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.createCollection();
}
@ -37,6 +36,7 @@ public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessi
public static void afterClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.shutdown();
}
@Override

View File

@ -25,7 +25,6 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav
@BeforeAll
public static void beforeClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.createCollection();
}
@ -33,6 +32,7 @@ public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScav
public static void afterClass() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.shutdown();
}
@Override

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.server.session.SessionDataStore;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -47,7 +48,6 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest
@BeforeEach
public void beforeEach() throws Exception
{
MongoTestHelper.dropCollection();
MongoTestHelper.createCollection();
}
@ -57,6 +57,12 @@ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest
MongoTestHelper.dropCollection();
}
@AfterAll
public static void shutdown() throws Exception
{
MongoTestHelper.shutdown();
}
@Override
public SessionDataStoreFactory createSessionDataStoreFactory()
{

View File

@ -29,10 +29,8 @@ import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -61,27 +59,12 @@ public class MongoTestHelper
static String mongoHost;
static int mongoPort;
static
{
try
{
long start = System.currentTimeMillis();
mongo.start();
mongoHost = mongo.getHost();
mongoPort = mongo.getMappedPort(MONGO_PORT);
LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort,
System.currentTimeMillis() - start);
mongoClient = new MongoClient(mongoHost, mongoPort);
}
catch (Exception e)
{
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
public static MongoClient getMongoClient() throws UnknownHostException
{
if (mongoClient == null)
{
mongoClient = new MongoClient(mongoHost, mongoPort);
}
return mongoClient;
}
@ -90,6 +73,11 @@ public class MongoTestHelper
getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME).drop();
}
public static void shutdown() throws Exception
{
mongo.stop();
}
public static void createCollection() throws UnknownHostException, MongoException
{
getMongoClient().getDB(DB_NAME).createCollection(COLLECTION_NAME, null);
@ -102,6 +90,25 @@ public class MongoTestHelper
public static MongoSessionDataStoreFactory newSessionDataStoreFactory()
{
if (!mongo.isRunning())
{
try
{
long start = System.currentTimeMillis();
mongo.start();
mongoHost = mongo.getHost();
mongoPort = mongo.getMappedPort(MONGO_PORT);
LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort,
System.currentTimeMillis() - start);
mongoClient = new MongoClient(mongoHost, mongoPort);
}
catch (Exception e)
{
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
MongoSessionDataStoreFactory storeFactory = new MongoSessionDataStoreFactory();
storeFactory.setHost(mongoHost);
storeFactory.setPort(mongoPort);