diff --git a/BUILDING.adoc b/BUILDING.adoc
index 27d76641b68..98166cae282 100644
--- a/BUILDING.adoc
+++ b/BUILDING.adoc
@@ -85,6 +85,13 @@ You either need to have a user-level configuration in `~/.m2/toolchains.xml` or
./mvnw verify -Pjava8-tests,!java8-incompat-fixes
----
+[#docker]
+=== Docker tests
+
+Certain tests use Docker to spawn necessary external services.
+Docker tests are configured using the `docker` Maven profile, which is activated by default for the CI environment.
+You can locally enable this profile by passing a `-P docker` argument to your `./mvnw` commands.
+
[#website]
== Building the website
diff --git a/log4j-mongodb/pom.xml b/log4j-mongodb/pom.xml
index e76c2ad14c2..754b772f20b 100644
--- a/log4j-mongodb/pom.xml
+++ b/log4j-mongodb/pom.xml
@@ -30,56 +30,59 @@
org.apache.logging.log4j.core
- 5.1.4
-
- false
- true
+ 5.1.3
+ 2.0.15
+
org.mongodb
bson
- ${mongodb5.version}
+ ${mongodb.version}
+
org.mongodb
mongodb-driver-core
- ${mongodb5.version}
-
-
- org.mongodb
- mongodb-driver-legacy
- ${mongodb5.version}
+ ${mongodb.version}
+
org.mongodb
mongodb-driver-sync
- ${mongodb5.version}
+ ${mongodb.version}
+
+
org.apache.logging.log4j
log4j-api
+
org.apache.logging.log4j
log4j-mongodb4
+
org.mongodb
bson
+
org.mongodb
mongodb-driver-core
+
org.mongodb
mongodb-driver-sync
+
org.apache.logging.log4j
log4j-api-test
@@ -91,6 +94,7 @@
+
org.apache.logging.log4j
log4j-core-test
@@ -102,31 +106,19 @@
+
org.apache.commons
commons-lang3
test
-
- de.flapdoodle.embed
- de.flapdoodle.embed.mongo
- test
-
-
- de.flapdoodle.embed
- de.flapdoodle.embed.process
- test
-
-
- de.flapdoodle.reverse
- de.flapdoodle.reverse
- test
-
+
org.junit.jupiter
junit-jupiter-api
test
+
@@ -134,8 +126,7 @@
org.apache.maven.plugins
maven-surefire-plugin
-
- 1
+ true
@@ -145,6 +136,114 @@
+
+
+
+
+
+ docker
+
+
+
+
+ linux
+
+
+ env.CI
+ true
+
+
+
+
+
+
+
+ io.fabric8
+ docker-maven-plugin
+
+ all
+ true
+ true
+
+
+ mongo
+ mongo:latest
+
+
+
+ localhost:mongo.port:27017
+
+
+
+
+
+
+
+ start-mongo
+
+ start
+
+
+
+ stop-mongo
+
+ stop
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit-jupiter.version}
+
+
+ org.slf4j
+ slf4j-nop
+ ${slf4j2.version}
+
+
+
+
+
+ integration-test
+ verify
+
+
+ true
+
+ **/*IT.java
+
+
+
+ OFF
+
+ ${mongo.port}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedIT.java
similarity index 84%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedIT.java
index 07e39339941..56cf3a89bee 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedIT.java
@@ -23,17 +23,16 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-public abstract class AbstractMongoDbCappedTest {
+abstract class AbstractMongoDbCappedIT {
- @Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(AbstractMongoDbCappedTest.class);
+ protected void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(AbstractMongoDbCappedIT.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsIT.java
similarity index 88%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsIT.java
index c74172925f5..f63ecf4ecfd 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsIT.java
@@ -26,21 +26,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb-additional-fields.xml")
-public class MongoDbAdditionalFieldsTest {
+@LoggerContextSource("MongoDbAdditionalFields.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbAdditionalFieldsIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDbAdditionalFieldsTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDbAdditionalFieldsIT.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
assertNotNull(collection);
final FindIterable found = collection.find();
final Document first = found.first();
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureIT.java
similarity index 77%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureIT.java
index 3247dc28c06..5a44aa5456e 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureIT.java
@@ -25,20 +25,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb-auth-failure.xml")
-public class MongoDbAuthFailureTest {
+@LoggerContextSource("MongoDbAuthFailureIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbAuthFailureIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDbAuthFailureTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDbAuthFailureIT.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDbTestConstants.DATABASE_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
+ ;
assertNotNull(collection);
final Document first = collection.find().first();
assertNull(first);
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntIT.java
similarity index 64%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntIT.java
index 34f921fe7bf..887132ded40 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntIT.java
@@ -16,11 +16,21 @@
*/
package org.apache.logging.log4j.mongodb;
+import com.mongodb.client.MongoClient;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb-capped-long.xml")
-public class MongoDbCappedLongTest extends AbstractMongoDbCappedTest {
+@LoggerContextSource("MongoDbCappedIntIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbCappedIntIT extends AbstractMongoDbCappedIT {
- // test is in superclass
+ @Test
+ @Override
+ protected void test(LoggerContext ctx, MongoClient mongoClient) {
+ super.test(ctx, mongoClient);
+ }
}
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongIT.java
similarity index 64%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongIT.java
index 500964aff08..bb6b4e65722 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongIT.java
@@ -16,11 +16,21 @@
*/
package org.apache.logging.log4j.mongodb;
+import com.mongodb.client.MongoClient;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb-capped-int.xml")
-public class MongoDbCappedIntTest extends AbstractMongoDbCappedTest {
+@LoggerContextSource("MongoDbCappedLongIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbCappedLongIT extends AbstractMongoDbCappedIT {
- // test is in superclass
+ @Test
+ @Override
+ protected void test(LoggerContext ctx, MongoClient mongoClient) {
+ super.test(ctx, mongoClient);
+ }
}
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbIT.java
similarity index 84%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbIT.java
index 5c4bbb750c1..d0f43cc70fd 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbIT.java
@@ -26,21 +26,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb.xml")
-public class MongoDbTest {
+@LoggerContextSource("MongoDbIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDbTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDbIT.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
assertNotNull(collection);
final FindIterable found = collection.find();
final Document first = found.first();
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageIT.java
similarity index 81%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageIT.java
index 2733554dbd3..b285529c0ce 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageIT.java
@@ -23,24 +23,28 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@UsingMongoDb
-@LoggerContextSource("log4j2-mongodb-map-message.xml")
-public class MongoDbMapMessageTest {
+@LoggerContextSource("MongoDbMapMessageIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbMapMessageIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDbMapMessageTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDbMapMessageIT.class);
final MapMessage, Object> mapMessage = new MapMessage<>();
mapMessage.with("SomeName", "SomeValue");
mapMessage.with("SomeInt", 1);
logger.info(mapMessage);
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
index 4b1f394b765..1246d48e496 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
@@ -18,67 +18,19 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
-import de.flapdoodle.embed.mongo.commands.ServerAddress;
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.mongo.packageresolver.Command;
-import de.flapdoodle.embed.mongo.transitions.Mongod;
-import de.flapdoodle.embed.mongo.transitions.PackageOfCommandDistribution;
-import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess;
-import de.flapdoodle.embed.mongo.types.DistributionBaseUrl;
-import de.flapdoodle.embed.process.config.store.FileSet;
-import de.flapdoodle.embed.process.config.store.FileType;
-import de.flapdoodle.embed.process.config.store.Package;
-import de.flapdoodle.embed.process.distribution.Distribution;
-import de.flapdoodle.embed.process.io.ProcessOutput;
-import de.flapdoodle.embed.process.io.Processors;
-import de.flapdoodle.embed.process.io.StreamProcessor;
-import de.flapdoodle.embed.process.types.Name;
-import de.flapdoodle.embed.process.types.ProcessConfig;
-import de.flapdoodle.os.OSType;
-import de.flapdoodle.reverse.TransitionWalker.ReachedState;
-import de.flapdoodle.reverse.transitions.Derive;
-import de.flapdoodle.reverse.transitions.Start;
-import java.util.Objects;
import java.util.function.Supplier;
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.TestProperties;
import org.apache.logging.log4j.test.junit.ExtensionContextAnchor;
-import org.apache.logging.log4j.test.junit.TestPropertySource;
import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver;
+import org.apache.logging.log4j.util.PropertiesUtil;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
-public class MongoDbResolver extends TypeBasedParameterResolver implements BeforeAllCallback {
+class MongoDbResolver extends TypeBasedParameterResolver implements BeforeAllCallback {
- private static final Logger LOGGER = StatusLogger.getLogger();
- private static final String LOGGING_TARGET_PROPERTY = "log4j2.mongoDbLoggingTarget";
-
- private static final int BUILDER_TIMEOUT_MILLIS = 30000;
-
- private static ProcessOutput getProcessOutput(final LoggingTarget loggingTarget, final String label) {
- if (loggingTarget != null) {
- switch (loggingTarget) {
- case STATUS_LOGGER:
- return ProcessOutput.builder()
- .output(Processors.named(
- "[" + label + " output]", new StatusLoggerStreamProcessor(Level.INFO)))
- .error(Processors.named(
- "[" + label + " error]", new StatusLoggerStreamProcessor(Level.ERROR)))
- .commands(new StatusLoggerStreamProcessor(Level.DEBUG))
- .build();
- case CONSOLE:
- return ProcessOutput.namedConsole(label);
- default:
- }
- }
- throw new NotImplementedException(Objects.toString(loggingTarget));
- }
+ static final String PORT_PROPERTY = "log4j2.mongo.port";
public MongoDbResolver() {
super(MongoClient.class);
@@ -86,40 +38,7 @@ public MongoDbResolver() {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
- final TestProperties props = TestPropertySource.createProperties(context);
- final Mongod mongod = Mongod.builder()
- .processOutput(Derive.given(Name.class)
- .state(ProcessOutput.class)
- .deriveBy(name -> getProcessOutput(
- LoggingTarget.getLoggingTarget(LoggingTarget.STATUS_LOGGER), name.value())))
- .processConfig(Start.to(ProcessConfig.class)
- .initializedWith(ProcessConfig.defaults().withStopTimeoutInMillis(BUILDER_TIMEOUT_MILLIS))
- .withTransitionLabel("create default"))
- // workaround for https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/309
- .packageOfDistribution(new PackageOfCommandDistribution() {
-
- @Override
- protected Package packageOf(
- Command command, Distribution distribution, DistributionBaseUrl baseUrl) {
- if (distribution.platform().operatingSystem().type() == OSType.Windows) {
- final Package relativePackage =
- commandPackageResolver().apply(command).packageFor(distribution);
- final FileSet.Builder fileSetBuilder = FileSet.builder()
- .addEntry(FileType.Library, "ssleay32.dll")
- .addEntry(FileType.Library, "libeay32.dll");
- relativePackage.fileSet().entries().forEach(fileSetBuilder::addEntries);
- return Package.builder()
- .archiveType(relativePackage.archiveType())
- .fileSet(fileSetBuilder.build())
- .url(baseUrl.value() + relativePackage.url())
- .hint(relativePackage.hint())
- .build();
- }
- return super.packageOf(command, distribution, baseUrl);
- }
- })
- .build();
- ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(mongod, props), context);
+ ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(), context);
}
@Override
@@ -129,25 +48,13 @@ public MongoClient resolveParameter(ParameterContext parameterContext, Extension
.get();
}
- public enum LoggingTarget {
- CONSOLE,
- STATUS_LOGGER;
-
- public static LoggingTarget getLoggingTarget(final LoggingTarget defaultValue) {
- return LoggingTarget.valueOf(System.getProperty(LOGGING_TARGET_PROPERTY, defaultValue.name()));
- }
- }
-
private static final class MongoClientHolder implements CloseableResource, Supplier {
- private final ReachedState state;
private final MongoClient mongoClient;
- public MongoClientHolder(final Mongod mongod, final TestProperties props) {
- state = mongod.start(Version.Main.V7_0);
- final RunningMongodProcess mongodProcess = state.current();
- final ServerAddress addr = mongodProcess.getServerAddress();
- mongoClient = MongoClients.create(String.format("mongodb://%s:%d", addr.getHost(), addr.getPort()));
- props.setProperty(MongoDbTestConstants.PROP_NAME_PORT, addr.getPort());
+ public MongoClientHolder() {
+ mongoClient = MongoClients.create(String.format(
+ "mongodb://localhost:%d",
+ PropertiesUtil.getProperties().getIntegerProperty(MongoDbTestConstants.PROP_NAME_PORT, 27017)));
}
@Override
@@ -158,32 +65,6 @@ public MongoClient get() {
@Override
public void close() throws Exception {
mongoClient.close();
- state.close();
- }
- }
-
- private static final class StatusLoggerStreamProcessor implements StreamProcessor {
-
- private final Level level;
-
- public StatusLoggerStreamProcessor(Level level) {
- this.level = level;
- }
-
- @Override
- public void process(String line) {
- LOGGER.log(level, () -> stripLineEndings(line));
- }
-
- @Override
- public void onProcessed() {
- // noop
- }
-
- String stripLineEndings(String line) {
- // we still need to remove line endings that are passed on by
- // StreamToLineProcessor...
- return line.replaceAll("[\n\r]+", "");
}
}
}
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverIT.java
similarity index 86%
rename from log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java
rename to log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverIT.java
index 199cabcb2fe..dd6a544ca95 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverIT.java
@@ -20,6 +20,7 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoIterable;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;
/**
@@ -29,10 +30,12 @@
*
*/
@UsingMongoDb
-public class MongoDbResolverTest {
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDbResolverIT {
@Test
- public void testAccess(final MongoClient mongoClient) {
+ void testAccess(final MongoClient mongoClient) {
final MongoIterable databaseNames = mongoClient.listDatabaseNames();
assertNotNull(databaseNames);
assertNotNull(databaseNames.first());
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
index ed5435599b9..95ed9ccbb5d 100644
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
+++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
@@ -18,7 +18,6 @@
public class MongoDbTestConstants {
- public static final String PROP_NAME_PORT = "MongoDBTestPort";
- static final String COLLECTION_NAME = "testCollection";
+ public static final String PROP_NAME_PORT = "log4j.mongo.port";
static final String DATABASE_NAME = "testDb";
}
diff --git a/log4j-mongodb/src/test/resources/MongoDbAdditionalFields.xml b/log4j-mongodb/src/test/resources/MongoDbAdditionalFields.xml
new file mode 100644
index 00000000000..96528f13911
--- /dev/null
+++ b/log4j-mongodb/src/test/resources/MongoDbAdditionalFields.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-mongodb/src/test/resources/MongoDbAuthFailureIT.xml b/log4j-mongodb/src/test/resources/MongoDbAuthFailureIT.xml
new file mode 100644
index 00000000000..23fbbdf3aca
--- /dev/null
+++ b/log4j-mongodb/src/test/resources/MongoDbAuthFailureIT.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml b/log4j-mongodb/src/test/resources/MongoDbCappedIntIT.xml
similarity index 70%
rename from log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml
rename to log4j-mongodb/src/test/resources/MongoDbCappedIntIT.xml
index 746b19914e7..bdaa8e3f40d 100644
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml
+++ b/log4j-mongodb/src/test/resources/MongoDbCappedIntIT.xml
@@ -15,18 +15,22 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
-
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml b/log4j-mongodb/src/test/resources/MongoDbCappedLongIT.xml
similarity index 71%
rename from log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml
rename to log4j-mongodb/src/test/resources/MongoDbCappedLongIT.xml
index 941ea71c4e2..6e3b8d6aad8 100644
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml
+++ b/log4j-mongodb/src/test/resources/MongoDbCappedLongIT.xml
@@ -15,19 +15,23 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
-
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml b/log4j-mongodb/src/test/resources/MongoDbIT.xml
similarity index 68%
rename from log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml
rename to log4j-mongodb/src/test/resources/MongoDbIT.xml
index d9d27461a00..9c9ab6037ee 100644
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml
+++ b/log4j-mongodb/src/test/resources/MongoDbIT.xml
@@ -15,19 +15,19 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
-
-
-
-
-
+
+
-
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb/src/test/resources/MongoDbMapMessageIT.xml
similarity index 68%
rename from log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
rename to log4j-mongodb/src/test/resources/MongoDbMapMessageIT.xml
index 4b740bc947e..dc6aa6846bd 100644
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
+++ b/log4j-mongodb/src/test/resources/MongoDbMapMessageIT.xml
@@ -15,16 +15,20 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
-
+
+
-
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
deleted file mode 100644
index 4f0865b2c46..00000000000
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/log4j-mongodb4/pom.xml b/log4j-mongodb4/pom.xml
index af55eb78e14..04639d0b535 100644
--- a/log4j-mongodb4/pom.xml
+++ b/log4j-mongodb4/pom.xml
@@ -36,54 +36,60 @@
org.apache.logging.log4j.core
4.11.4
+ 1.7.36
+
org.mongodb
bson
${mongodb4.version}
+
org.mongodb
mongodb-driver-core
${mongodb4.version}
-
- org.mongodb
- mongodb-driver-legacy
- ${mongodb4.version}
-
+
org.mongodb
mongodb-driver-sync
${mongodb4.version}
+
+
org.apache.logging.log4j
log4j-api
+
org.apache.logging.log4j
log4j-core
+
org.mongodb
bson
+
org.mongodb
mongodb-driver-core
+
org.mongodb
mongodb-driver-sync
+
org.apache.logging.log4j
log4j-api-test
@@ -95,6 +101,7 @@
+
org.apache.logging.log4j
log4j-core-test
@@ -106,31 +113,19 @@
+
org.apache.commons
commons-lang3
test
-
- de.flapdoodle.embed
- de.flapdoodle.embed.mongo
- test
-
-
- de.flapdoodle.embed
- de.flapdoodle.embed.process
- test
-
-
- de.flapdoodle.reverse
- de.flapdoodle.reverse
- test
-
+
org.junit.jupiter
junit-jupiter-api
test
+
@@ -140,8 +135,7 @@
org.apache.maven.plugins
maven-surefire-plugin
-
- 1
+ true
@@ -155,4 +149,110 @@
+
+
+
+ docker
+
+
+
+
+ linux
+
+
+ env.CI
+ true
+
+
+
+
+
+
+
+ io.fabric8
+ docker-maven-plugin
+
+ all
+ true
+ true
+
+
+ mongo
+ mongo:latest
+
+
+
+ localhost:mongo.port:27017
+
+
+
+
+
+
+
+ start-mongo
+
+ start
+
+
+
+ stop-mongo
+
+ stop
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit-jupiter.version}
+
+
+ org.slf4j
+ slf4j-nop
+ ${slf4j.version}
+
+
+
+
+
+ integration-test
+ verify
+
+
+ true
+
+ **/*IT.java
+
+
+
+ OFF
+
+ ${mongo.port}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java
similarity index 84%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java
index 6f54e77c7e3..6be4f7f6852 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java
@@ -23,17 +23,16 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-public abstract class AbstractMongoDb4CappedTest {
+abstract class AbstractMongoDb4CappedIT {
- @Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(AbstractMongoDb4CappedTest.class);
+ protected void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(AbstractMongoDb4CappedIT.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDb4TestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsIT.java
similarity index 88%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsIT.java
index 27062452bf6..b5ccc77e735 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AdditionalFieldsIT.java
@@ -26,21 +26,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb-additional-fields.xml")
-public class MongoDb4AdditionalFieldsTest {
+@LoggerContextSource("MongoDb4AdditionalFields.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4AdditionalFieldsIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb4AdditionalFieldsTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDb4AdditionalFieldsIT.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDb4TestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
assertNotNull(collection);
final FindIterable found = collection.find();
final Document first = found.first();
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureIT.java
similarity index 76%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureIT.java
index 641305256c4..c5b5b15c6db 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4AuthFailureIT.java
@@ -25,20 +25,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb-auth-failure.xml")
-public class MongoDb4AuthFailureTest {
+@LoggerContextSource("MongoDb4AuthFailureIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4AuthFailureIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb4AuthFailureTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDb4AuthFailureIT.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDb4TestConstants.DATABASE_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
+ ;
assertNotNull(collection);
final Document first = collection.find().first();
assertNull(first);
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntIT.java
similarity index 64%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntIT.java
index 0a99dbf5b87..24add71aa5d 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntIT.java
@@ -16,11 +16,21 @@
*/
package org.apache.logging.log4j.mongodb4;
+import com.mongodb.client.MongoClient;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb-capped-long.xml")
-public class MongoDb4CappedLongTest extends AbstractMongoDb4CappedTest {
+@LoggerContextSource("MongoDb4CappedIntIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4CappedIntIT extends AbstractMongoDb4CappedIT {
- // test is in superclass
+ @Test
+ @Override
+ protected void test(LoggerContext ctx, MongoClient mongoClient) {
+ super.test(ctx, mongoClient);
+ }
}
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongIT.java
similarity index 64%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongIT.java
index e01e0c0d63b..580c6c60fa6 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedIntTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CappedLongIT.java
@@ -16,11 +16,21 @@
*/
package org.apache.logging.log4j.mongodb4;
+import com.mongodb.client.MongoClient;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb-capped-int.xml")
-public class MongoDb4CappedIntTest extends AbstractMongoDb4CappedTest {
+@LoggerContextSource("MongoDb4CappedLongIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4CappedLongIT extends AbstractMongoDb4CappedIT {
- // test is in superclass
+ @Test
+ @Override
+ protected void test(LoggerContext ctx, MongoClient mongoClient) {
+ super.test(ctx, mongoClient);
+ }
}
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Test.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4IT.java
similarity index 84%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Test.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4IT.java
index 140a9597505..ac0c550efca 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Test.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4IT.java
@@ -26,21 +26,25 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb.xml")
-public class MongoDb4Test {
+@LoggerContextSource("MongoDb4IT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4IT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb4Test.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDb4IT.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDb4TestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
assertNotNull(collection);
final FindIterable found = collection.find();
final Document first = found.first();
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageIT.java
similarity index 80%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageIT.java
index d8877392448..b7a384c23b1 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4MapMessageIT.java
@@ -23,24 +23,28 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@UsingMongoDb4
-@LoggerContextSource("log4j2-mongodb-map-message.xml")
-public class MongoDb4MapMessageTest {
+@LoggerContextSource("MongoDb4MapMessageIT.xml")
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4MapMessageIT {
@Test
- public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb4MapMessageTest.class);
+ void test(final LoggerContext ctx, final MongoClient mongoClient) {
+ final Logger logger = ctx.getLogger(MongoDb4MapMessageIT.class);
final MapMessage, Object> mapMessage = new MapMessage<>();
mapMessage.with("SomeName", "SomeValue");
mapMessage.with("SomeInt", 1);
logger.info(mapMessage);
final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection collection = database.getCollection(MongoDb4TestConstants.COLLECTION_NAME);
+ final MongoCollection collection =
+ database.getCollection(getClass().getSimpleName());
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
index 90c71606cfc..e7994f10297 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
@@ -18,69 +18,19 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
-import de.flapdoodle.embed.mongo.commands.ServerAddress;
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.mongo.packageresolver.Command;
-import de.flapdoodle.embed.mongo.transitions.Mongod;
-import de.flapdoodle.embed.mongo.transitions.PackageOfCommandDistribution;
-import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess;
-import de.flapdoodle.embed.mongo.types.DistributionBaseUrl;
-import de.flapdoodle.embed.process.config.store.FileSet;
-import de.flapdoodle.embed.process.config.store.FileType;
-import de.flapdoodle.embed.process.config.store.Package;
-import de.flapdoodle.embed.process.distribution.Distribution;
-import de.flapdoodle.embed.process.io.ProcessOutput;
-import de.flapdoodle.embed.process.io.Processors;
-import de.flapdoodle.embed.process.io.StreamProcessor;
-import de.flapdoodle.embed.process.types.Name;
-import de.flapdoodle.embed.process.types.ProcessConfig;
-import de.flapdoodle.os.OSType;
-import de.flapdoodle.reverse.TransitionWalker.ReachedState;
-import de.flapdoodle.reverse.transitions.Derive;
-import de.flapdoodle.reverse.transitions.Start;
-import java.util.Objects;
import java.util.function.Supplier;
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.TestProperties;
import org.apache.logging.log4j.test.junit.ExtensionContextAnchor;
-import org.apache.logging.log4j.test.junit.TestPropertySource;
import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver;
+import org.apache.logging.log4j.util.PropertiesUtil;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
-public class MongoDb4Resolver extends TypeBasedParameterResolver implements BeforeAllCallback {
+class MongoDb4Resolver extends TypeBasedParameterResolver implements BeforeAllCallback {
- private static final Logger LOGGER = StatusLogger.getLogger();
- private static final String LOGGING_TARGET_PROPERTY = "log4j2.mongoDbLoggingTarget";
-
- private static final int BUILDER_TIMEOUT_MILLIS = 30000;
-
- private static ProcessOutput getProcessOutput(final LoggingTarget loggingTarget, final String label) {
- if (loggingTarget != null) {
- switch (loggingTarget) {
- case STATUS_LOGGER:
- // @formatter:off
- return ProcessOutput.builder()
- .output(Processors.named(
- "[" + label + " output]", new StatusLoggerStreamProcessor(Level.INFO)))
- .error(Processors.named(
- "[" + label + " error]", new StatusLoggerStreamProcessor(Level.ERROR)))
- .commands(new StatusLoggerStreamProcessor(Level.DEBUG))
- .build();
- // @formatter:on
- case CONSOLE:
- return ProcessOutput.namedConsole(label);
- default:
- }
- }
- throw new NotImplementedException(Objects.toString(loggingTarget));
- }
+ static final String PORT_PROPERTY = "log4j2.mongo.port";
public MongoDb4Resolver() {
super(MongoClient.class);
@@ -88,40 +38,7 @@ public MongoDb4Resolver() {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
- final TestProperties props = TestPropertySource.createProperties(context);
- final Mongod mongod = Mongod.builder()
- .processOutput(Derive.given(Name.class)
- .state(ProcessOutput.class)
- .deriveBy(name -> getProcessOutput(
- LoggingTarget.getLoggingTarget(LoggingTarget.STATUS_LOGGER), name.value())))
- .processConfig(Start.to(ProcessConfig.class)
- .initializedWith(ProcessConfig.defaults().withStopTimeoutInMillis(BUILDER_TIMEOUT_MILLIS))
- .withTransitionLabel("create default"))
- // workaround for https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/309
- .packageOfDistribution(new PackageOfCommandDistribution() {
-
- @Override
- protected Package packageOf(
- Command command, Distribution distribution, DistributionBaseUrl baseUrl) {
- if (distribution.platform().operatingSystem().type() == OSType.Windows) {
- final Package relativePackage =
- commandPackageResolver().apply(command).packageFor(distribution);
- final FileSet.Builder fileSetBuilder = FileSet.builder()
- .addEntry(FileType.Library, "ssleay32.dll")
- .addEntry(FileType.Library, "libeay32.dll");
- relativePackage.fileSet().entries().forEach(fileSetBuilder::addEntries);
- return Package.builder()
- .archiveType(relativePackage.archiveType())
- .fileSet(fileSetBuilder.build())
- .url(baseUrl.value() + relativePackage.url())
- .hint(relativePackage.hint())
- .build();
- }
- return super.packageOf(command, distribution, baseUrl);
- }
- })
- .build();
- ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(mongod, props), context);
+ ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(), context);
}
@Override
@@ -131,25 +48,13 @@ public MongoClient resolveParameter(ParameterContext parameterContext, Extension
.get();
}
- public enum LoggingTarget {
- CONSOLE,
- STATUS_LOGGER;
-
- public static LoggingTarget getLoggingTarget(final LoggingTarget defaultValue) {
- return LoggingTarget.valueOf(System.getProperty(LOGGING_TARGET_PROPERTY, defaultValue.name()));
- }
- }
-
private static final class MongoClientHolder implements CloseableResource, Supplier {
- private final ReachedState state;
private final MongoClient mongoClient;
- public MongoClientHolder(final Mongod mongod, final TestProperties props) {
- state = mongod.start(Version.Main.V7_0);
- final RunningMongodProcess mongodProcess = state.current();
- final ServerAddress addr = mongodProcess.getServerAddress();
- mongoClient = MongoClients.create(String.format("mongodb://%s:%d", addr.getHost(), addr.getPort()));
- props.setProperty(MongoDb4TestConstants.PROP_NAME_PORT, addr.getPort());
+ public MongoClientHolder() {
+ mongoClient = MongoClients.create(String.format(
+ "mongodb://localhost:%d",
+ PropertiesUtil.getProperties().getIntegerProperty(MongoDb4TestConstants.PROP_NAME_PORT, 27017)));
}
@Override
@@ -160,32 +65,6 @@ public MongoClient get() {
@Override
public void close() throws Exception {
mongoClient.close();
- state.close();
- }
- }
-
- private static final class StatusLoggerStreamProcessor implements StreamProcessor {
-
- private final Level level;
-
- public StatusLoggerStreamProcessor(Level level) {
- this.level = level;
- }
-
- @Override
- public void process(String line) {
- LOGGER.log(level, () -> stripLineEndings(line));
- }
-
- @Override
- public void onProcessed() {
- // noop
- }
-
- String stripLineEndings(String line) {
- // we still need to remove line endings that are passed on by
- // StreamToLineProcessor...
- return line.replaceAll("[\n\r]+", "");
}
}
}
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverIT.java
similarity index 86%
rename from log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverTest.java
rename to log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverIT.java
index 9d0bebe5e0b..d63b07072bf 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverTest.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ResolverIT.java
@@ -20,6 +20,7 @@
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoIterable;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;
/**
@@ -29,10 +30,12 @@
*
*/
@UsingMongoDb4
-public class MongoDb4ResolverTest {
+// Print debug status logger output upon failure
+@UsingStatusListener
+class MongoDb4ResolverIT {
@Test
- public void testAccess(final MongoClient mongoClient) {
+ void testAccess(final MongoClient mongoClient) {
final MongoIterable databaseNames = mongoClient.listDatabaseNames();
assertNotNull(databaseNames);
assertNotNull(databaseNames.first());
diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4TestConstants.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4TestConstants.java
index 6f43c72527e..5245c686700 100644
--- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4TestConstants.java
+++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4TestConstants.java
@@ -18,7 +18,6 @@
public class MongoDb4TestConstants {
- public static final String PROP_NAME_PORT = "MongoDBTestPort";
- static final String COLLECTION_NAME = "testCollection";
+ public static final String PROP_NAME_PORT = "log4j.mongo.port";
static final String DATABASE_NAME = "testDb";
}
diff --git a/log4j-mongodb4/src/test/resources/MongoDb4AdditionalFields.xml b/log4j-mongodb4/src/test/resources/MongoDb4AdditionalFields.xml
new file mode 100644
index 00000000000..6892bcac508
--- /dev/null
+++ b/log4j-mongodb4/src/test/resources/MongoDb4AdditionalFields.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb4/src/test/resources/MongoDb4AuthFailureIT.xml
similarity index 67%
rename from log4j-mongodb4/src/test/resources/log4j2-mongodb-auth-failure.xml
rename to log4j-mongodb4/src/test/resources/MongoDb4AuthFailureIT.xml
index 0674de4fa0c..fa8a46bbebe 100644
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb-auth-failure.xml
+++ b/log4j-mongodb4/src/test/resources/MongoDb4AuthFailureIT.xml
@@ -15,16 +15,20 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
+ connection="mongodb://log4jUser:12345678@localhost:${sys:log4j.mongo.port:-27017}/testDb.MongoDb4AuthFailureIT" />
-
+
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-int.xml b/log4j-mongodb4/src/test/resources/MongoDb4CappedIntIT.xml
similarity index 70%
rename from log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-int.xml
rename to log4j-mongodb4/src/test/resources/MongoDb4CappedIntIT.xml
index 03aca2ebbea..2e9a11cb68a 100644
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-int.xml
+++ b/log4j-mongodb4/src/test/resources/MongoDb4CappedIntIT.xml
@@ -15,18 +15,22 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
-
+
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-long.xml b/log4j-mongodb4/src/test/resources/MongoDb4CappedLongIT.xml
similarity index 71%
rename from log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-long.xml
rename to log4j-mongodb4/src/test/resources/MongoDb4CappedLongIT.xml
index ddde9bcb05e..b79a4dc59e8 100644
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb-capped-long.xml
+++ b/log4j-mongodb4/src/test/resources/MongoDb4CappedLongIT.xml
@@ -15,19 +15,23 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
-
+
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb4/src/test/resources/MongoDb4IT.xml
similarity index 68%
rename from log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
rename to log4j-mongodb4/src/test/resources/MongoDb4IT.xml
index e84603a0a52..6ab35f8765a 100644
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
+++ b/log4j-mongodb4/src/test/resources/MongoDb4IT.xml
@@ -15,16 +15,19 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
-
+
+
-
+
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb4/src/test/resources/MongoDb4MapMessageIT.xml
similarity index 68%
rename from log4j-mongodb4/src/test/resources/log4j2-mongodb-map-message.xml
rename to log4j-mongodb4/src/test/resources/MongoDb4MapMessageIT.xml
index a84154e78da..8990a64afcc 100644
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb-map-message.xml
+++ b/log4j-mongodb4/src/test/resources/MongoDb4MapMessageIT.xml
@@ -15,16 +15,20 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
-
+
+
-
+
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb-additional-fields.xml b/log4j-mongodb4/src/test/resources/log4j2-mongodb-additional-fields.xml
deleted file mode 100644
index eec98585cd9..00000000000
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb-additional-fields.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/log4j-mongodb4/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb4/src/test/resources/log4j2-mongodb.xml
deleted file mode 100644
index b36a58affc9..00000000000
--- a/log4j-mongodb4/src/test/resources/log4j2-mongodb.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml
index 9753e45d30f..969c18523c5 100644
--- a/log4j-parent/pom.xml
+++ b/log4j-parent/pom.xml
@@ -82,8 +82,6 @@
8.15.1
0.9.0
7.0.5
- 4.13.1
- 1.8.0
3.0.22
33.3.0-jre
2.2.224
@@ -372,24 +370,6 @@
${commons-pool2.version}
-
- de.flapdoodle.embed
- de.flapdoodle.embed.mongo
- ${flapdoodle-embed.version}
-
-
-
- de.flapdoodle.embed
- de.flapdoodle.embed.process
- ${flapdoodle-embed.version}
-
-
-
- de.flapdoodle.reverse
- de.flapdoodle.reverse
- ${flapdoodle-reverse.version}
-
-
com.conversantmedia
disruptor
@@ -900,7 +880,7 @@
-
+
io.fabric8
docker-maven-plugin
diff --git a/src/changelog/.2.x.x/2229_mongodb_docker.xml b/src/changelog/.2.x.x/2229_mongodb_docker.xml
new file mode 100644
index 00000000000..1d5b36ed1ca
--- /dev/null
+++ b/src/changelog/.2.x.x/2229_mongodb_docker.xml
@@ -0,0 +1,8 @@
+
+
+
+ Switch MongoDB tests to use Docker.
+