diff --git a/Jenkinsfile b/Jenkinsfile index 270223b4297..3689b353f83 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { agent { node { label 'linux' } } steps { timeout(time: 120, unit: 'MINUTES') { - mavenBuild("jdk8", "-T3 -Pmongodb clean install", "maven3", true) + mavenBuild("jdk8", "-T3 clean install", "maven3", true) // Collect up the jacoco execution results (only on main build) jacoco inclusionPattern: '**/org/eclipse/jetty/**/*.class', exclusionPattern: '' + @@ -45,7 +45,7 @@ pipeline { agent { node { label 'linux' } } steps { timeout(time: 120, unit: 'MINUTES') { - mavenBuild("jdk11", "-T3 -Pmongodb clean install", "maven3", true) + mavenBuild("jdk11", "-T3 clean install", "maven3", true) warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'Java']] junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml' } @@ -56,7 +56,7 @@ pipeline { agent { node { label 'linux' } } steps { timeout(time: 120, unit: 'MINUTES') { - mavenBuild("jdk14", "-T3 -Pmongodb clean install", "maven3", true) + mavenBuild("jdk14", "-T3 clean install", "maven3", true) warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'Java']] junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml' } @@ -139,7 +139,7 @@ def mavenBuild(jdk, cmdline, mvnName, junitPublishDisabled) { mavenOpts: mavenOpts, mavenLocalRepo: localRepo) { // Some common Maven command line + provided command line - sh "mvn -Pci -V -B -e -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME + sh "mvn -Premote-session-tests -Pci -V -B -e -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME } } diff --git a/jetty-util/src/main/config/modules/slf4j-api.mod b/jetty-util/src/main/config/modules/slf4j-api.mod index ef29cce1351..058be589807 100644 --- a/jetty-util/src/main/config/modules/slf4j-api.mod +++ b/jetty-util/src/main/config/modules/slf4j-api.mod @@ -16,7 +16,7 @@ maven://org.slf4j/slf4j-api/${slf4j.version}|lib/slf4j/slf4j-api-${slf4j.version lib/slf4j/slf4j-api-${slf4j.version}.jar [ini] -slf4j.version?=1.7.25 +slf4j.version?=1.7.30 jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/ [license] diff --git a/pom.xml b/pom.xml index 41df0eee699..b32caefcaea 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ UTF-8 1.4 8.20 - 1.7.25 + 1.7.30 2.11.2 3.4.2 1.2.3 @@ -32,7 +32,7 @@ 1.21 benchmarks 1.4.0 - 5.5.1 + 5.6.2 3.6.0 1.3.1 3.1.0 @@ -1080,6 +1080,16 @@ junit-jupiter ${junit.version} + + org.testcontainers + testcontainers + 1.14.1 + + + org.testcontainers + junit-jupiter + 1.14.1 + org.eclipse.jetty.toolchain diff --git a/tests/test-sessions/test-mongodb-sessions/pom.xml b/tests/test-sessions/test-mongodb-sessions/pom.xml index a3ffc36c528..ade0d5a343b 100644 --- a/tests/test-sessions/test-mongodb-sessions/pom.xml +++ b/tests/test-sessions/test-mongodb-sessions/pom.xml @@ -12,6 +12,8 @@ ${project.groupId}.sessions.mongo localhost + + 2.2.7 @@ -95,13 +97,28 @@ jetty-test-helper test + + org.testcontainers + testcontainers + test + + + org.testcontainers + junit-jupiter + test + + + org.slf4j + slf4j-simple + test + - mongodb + remote-session-tests - mongodb.enabled + mongo.enabled true @@ -112,51 +129,11 @@ maven-surefire-plugin - ${embedmongo.port} - ${embedmongo.host} + ${mongo.docker.version} false - - com.github.joelittlejohn.embedmongo - embedmongo-maven-plugin - 0.4.1 - - - - true - - ${project.build.directory}/mongotest - - - file - - ${project.build.directory}/embedmongo.log - - - - false - https://jenkins.webtide.net/userContent/ - 2.2.1 - - - - start - process-test-classes - - start - - - - stop - test - - stop - - - - diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java index b7ee862861a..db2366b2f6a 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreTest.java @@ -42,15 +42,16 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; */ public class MongoSessionDataStoreTest extends AbstractSessionDataStoreTest { + @BeforeEach - public void beforeClass() throws Exception + public void beforeEach() throws Exception { MongoTestHelper.dropCollection(); MongoTestHelper.createCollection(); } @AfterEach - public void afterClass() throws Exception + public void afterEach() throws Exception { MongoTestHelper.dropCollection(); } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestHelper.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestHelper.java index 0de4af40445..bafaa285e3b 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestHelper.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestHelper.java @@ -32,8 +32,10 @@ import com.mongodb.MongoException; import com.mongodb.WriteConcern; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.util.ClassLoadingObjectInputStream; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -44,39 +46,71 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class MongoTestHelper { - private static final Logger LOG = Log.getLogger(MongoTestHelper.class); - static int __workers = 0; + private static final Logger LOG = LoggerFactory.getLogger(MongoTestHelper.class); + private static final Logger MONGO_LOG = LoggerFactory.getLogger("org.eclipse.jetty.nosql.mongodb.MongoLogs"); public static final String DB_NAME = "HttpSessions"; public static final String COLLECTION_NAME = "testsessions"; - static MongoClient _mongoClient; + static GenericContainer mongo = + new GenericContainer("mongo:" + System.getProperty("mongo.docker.version", "2.2.7")) + .withLogConsumer(new Slf4jLogConsumer(MONGO_LOG)); - static + static MongoClient mongoClient; + + public static void startMongo() { try { - _mongoClient = - new MongoClient(System.getProperty("embedmongo.host"), Integer.getInteger("embedmongoPort")); + long start = System.currentTimeMillis(); + mongo.start(); + String containerIpAddress = mongo.getContainerIpAddress(); + int mongoPort = mongo.getMappedPort(27017); + LOG.info("Mongo container started for {}:{} - {}ms", containerIpAddress, mongoPort, + System.currentTimeMillis() - start); + System.setProperty("embedmongoHost", containerIpAddress); + System.setProperty("embedmongoPort", Integer.toString(mongoPort)); } - catch (UnknownHostException e) + catch (Exception e) { - e.printStackTrace(); + LOG.error(e.getMessage(), e); + throw new RuntimeException(e); } } - public static void dropCollection() throws MongoException, UnknownHostException + public static void stopMongo() { - _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME).drop(); + mongo.stop(); + mongoClient = null; + } + + public static MongoClient getMongoClient() throws UnknownHostException + { + boolean restart = false; + if (mongo == null || !mongo.isRunning()) + { + startMongo(); + restart = true; + } + if (mongoClient == null || restart) + { + mongoClient = new MongoClient(System.getProperty("embedmongoHost"), Integer.getInteger("embedmongoPort")); + } + return mongoClient; + } + + public static void dropCollection() throws Exception + { + getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME).drop(); } public static void createCollection() throws UnknownHostException, MongoException { - _mongoClient.getDB(DB_NAME).createCollection(COLLECTION_NAME, null); + getMongoClient().getDB(DB_NAME).createCollection(COLLECTION_NAME, null); } public static DBCollection getCollection() throws UnknownHostException, MongoException { - return _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + return getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); } public static MongoSessionDataStoreFactory newSessionDataStoreFactory() @@ -92,7 +126,7 @@ public class MongoTestHelper public static boolean checkSessionExists(String id) throws Exception { - DBCollection collection = _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); DBObject fields = new BasicDBObject(); fields.put(MongoSessionDataStore.EXPIRY, 1); @@ -109,7 +143,7 @@ public class MongoTestHelper public static boolean checkSessionPersisted(SessionData data) throws Exception { - DBCollection collection = _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); DBObject fields = new BasicDBObject(); @@ -117,7 +151,7 @@ public class MongoTestHelper if (sessionDocument == null) return false; //doesn't exist - LOG.info("{}", sessionDocument); + LOG.debug("{}", sessionDocument); Boolean valid = (Boolean)sessionDocument.get(MongoSessionDataStore.VALID); @@ -183,7 +217,7 @@ public class MongoTestHelper Map attributes) throws Exception { - DBCollection collection = _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.ID, id); @@ -193,7 +227,7 @@ public class MongoTestHelper boolean upsert = false; BasicDBObject sets = new BasicDBObject(); - Object version = new Long(1); + Object version = 1L; // New session @@ -232,7 +266,7 @@ public class MongoTestHelper throws Exception { - DBCollection collection = _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.ID, id); @@ -242,7 +276,7 @@ public class MongoTestHelper boolean upsert = false; BasicDBObject sets = new BasicDBObject(); - Object version = new Long(1); + Object version = 1L; // New session upsert = true; @@ -278,7 +312,7 @@ public class MongoTestHelper throws Exception { //make old-style session to test if we can retrieve it - DBCollection collection = _mongoClient.getDB(DB_NAME).getCollection(COLLECTION_NAME); + DBCollection collection = getMongoClient().getDB(DB_NAME).getCollection(COLLECTION_NAME); // Form query for upsert BasicDBObject key = new BasicDBObject(MongoSessionDataStore.ID, id); @@ -288,7 +322,7 @@ public class MongoTestHelper boolean upsert = false; BasicDBObject sets = new BasicDBObject(); - Object version = new Long(1); + Object version = 1L; // New session upsert = true; diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/resources/simplelogger.properties b/tests/test-sessions/test-mongodb-sessions/src/test/resources/simplelogger.properties new file mode 100644 index 00000000000..5f859960729 --- /dev/null +++ b/tests/test-sessions/test-mongodb-sessions/src/test/resources/simplelogger.properties @@ -0,0 +1,3 @@ +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simpleLogger.log.org.eclipse.jetty.nosql.mongodb.MongoLogs=error +org.slf4j.simpleLogger.log.org.eclipse.jetty.nosql.mongodb.MongoTestHelper=info