From e9dfdf5045e89a9ce4ed6cdbefb224caf170937e Mon Sep 17 00:00:00 2001 From: Pawel Nowak Date: Fri, 21 Aug 2020 20:51:29 +0200 Subject: [PATCH 1/2] fix mongo driver dependency conflict --- README.md | 12 +-- pom.xml | 6 +- .../java/com/github/mongobeej/Mongobee.java | 89 +++---------------- .../github/mongobeej/dao/ChangeEntryDao.java | 28 ++---- .../com/github/mongobeej/dao/LockDao.java | 2 +- .../github/mongobeej/MongobeeBaseTest.java | 8 +- .../com/github/mongobeej/MongobeeEnvTest.java | 4 +- .../github/mongobeej/MongobeeProfileTest.java | 25 +++--- .../com/github/mongobeej/MongobeeTest.java | 20 ++--- .../mongobeej/dao/ChangeEntryDaoTest.java | 2 +- .../utils/MongoEnvironmentCreator.java | 7 +- 11 files changed, 56 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 405e965..0a86260 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ With Maven com.github.cybuch mongobeej - 1.0.0 + 1.0.1 ``` With Gradle ```groovy -compile 'com.github.cybuch:mongobeej:1.0.0' +compile 'com.github.cybuch:mongobeej:1.0.1' ``` ### Migrating from Mongobee @@ -220,18 +220,18 @@ You can exclude mongo-java-driver from **mongobeeJ** and use your dependency on ```xml org.mongodb - mongo-java-driver - 3.12.7 + mongodb-driver-sync + 4.0.5 com.github.mongobeej mongobeej - 1.0.0 + 1.0.1 org.mongodb - mongo-java-driver + mongodb-driver-sync diff --git a/pom.xml b/pom.xml index 516c548..1cef439 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.github.cybuch mongobeej - 1.0.0 + 1.0.1-SNAPSHOT @@ -53,8 +53,8 @@ org.mongodb - mongo-java-driver - 3.12.7 + mongodb-driver-sync + 4.0.5 org.springframework diff --git a/src/main/java/com/github/mongobeej/Mongobee.java b/src/main/java/com/github/mongobeej/Mongobee.java index 5b37178..7326ade 100644 --- a/src/main/java/com/github/mongobeej/Mongobee.java +++ b/src/main/java/com/github/mongobeej/Mongobee.java @@ -7,10 +7,8 @@ import com.github.mongobeej.exception.MongobeeConnectionException; import com.github.mongobeej.exception.MongobeeException; import com.github.mongobeej.utils.ChangeService; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import org.slf4j.Logger; @@ -25,7 +23,6 @@ import static com.mongodb.ServerAddress.defaultHost; import static com.mongodb.ServerAddress.defaultPort; -import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.springframework.util.StringUtils.hasText; /** @@ -46,9 +43,8 @@ public class Mongobee implements InitializingBean { private ChangeEntryDao dao; private boolean enabled = true; private String changeLogsScanPackage; - private MongoClientURI mongoClientURI; - private MongoClient legacyMongoClient; - private com.mongodb.client.MongoClient mongoClient; + private ConnectionString mongoClientURI; + private MongoClient mongoClient; private String dbName; private Environment springEnvironment; private MongoTemplate mongoTemplate; @@ -60,7 +56,7 @@ public class Mongobee implements InitializingBean { *

It is recommended to use constructors with MongoURI

*/ public Mongobee() { - this(new MongoClientURI("mongodb://" + defaultHost() + ":" + defaultPort() + "/")); + this(new ConnectionString("mongodb://" + defaultHost() + ":" + defaultPort() + "/")); } /** @@ -69,29 +65,15 @@ public Mongobee() { *

* * @param mongoClientURI uri to your db - * @see MongoClientURI + * @see ConnectionString */ - public Mongobee(MongoClientURI mongoClientURI) { + public Mongobee(ConnectionString mongoClientURI) { this.mongoClientURI = mongoClientURI; this.setDbName(mongoClientURI.getDatabase()); this.dao = new ChangeEntryDao(DEFAULT_CHANGELOG_COLLECTION_NAME, DEFAULT_LOCK_COLLECTION_NAME, DEFAULT_WAIT_FOR_LOCK, DEFAULT_CHANGE_LOG_LOCK_WAIT_TIME, DEFAULT_CHANGE_LOG_LOCK_POLL_RATE, DEFAULT_THROW_EXCEPTION_IF_CANNOT_OBTAIN_LOCK); } - /** - *

Constructor takes db.mongodb.MongoClient object as a parameter. - *

For more details about {@link MongoClient} please see com.mongodb.MongoClient docs - *

- * - * @param legacyMongoClient database connection client - * @see MongoClient - */ - public Mongobee(MongoClient legacyMongoClient) { - this.legacyMongoClient = legacyMongoClient; - this.dao = new ChangeEntryDao(DEFAULT_CHANGELOG_COLLECTION_NAME, DEFAULT_LOCK_COLLECTION_NAME, DEFAULT_WAIT_FOR_LOCK, - DEFAULT_CHANGE_LOG_LOCK_WAIT_TIME, DEFAULT_CHANGE_LOG_LOCK_POLL_RATE, DEFAULT_THROW_EXCEPTION_IF_CANNOT_OBTAIN_LOCK); - } - /** *

Mongobee runner. Correct MongoDB URI should be provided.

*

The format of the URI is: @@ -114,10 +96,10 @@ public Mongobee(MongoClient legacyMongoClient) { *

For details, please see com.mongodb.MongoClientURI * * @param mongoURI with correct format - * @see com.mongodb.MongoClientURI + * @see com.mongodb.ConnectionString */ public Mongobee(String mongoURI) { - this(new MongoClientURI(mongoURI)); + this(new ConnectionString(mongoURI)); } /** @@ -159,8 +141,6 @@ public void execute() throws MongobeeException { if (mongoClient != null) { dao.connectMongoDb(mongoClient, dbName); - } else if (this.legacyMongoClient != null) { - dao.connectMongoDb(this.legacyMongoClient, dbName); } else { dao.connectMongoDb(this.mongoClientURI, dbName); } @@ -255,61 +235,12 @@ private MongoTemplate createMongoTemplate() { com.mongodb.client.MongoClient mongoClient; if (this.mongoClient != null) { mongoClient = this.mongoClient; - } else if (legacyMongoClient != null) { - mongoClient = fromLegacyClient(); } else { mongoClient = MongoClients.create(mongoClientURI.toString()); } return new MongoTemplate(mongoClient, dbName); } - private com.mongodb.client.MongoClient fromLegacyClient() { - MongoClientOptions mongoClientOptions = legacyMongoClient.getMongoClientOptions(); - MongoClientSettings.Builder mongoClientSettingsBuilder = MongoClientSettings.builder() - .readPreference(legacyMongoClient.getReadPreference()) - .writeConcern(legacyMongoClient.getWriteConcern()) - .retryWrites(mongoClientOptions.getRetryWrites()) - .readConcern(legacyMongoClient.getReadConcern()) - .codecRegistry(mongoClientOptions.getCodecRegistry()) - .compressorList(mongoClientOptions.getCompressorList()) - .applicationName(mongoClientOptions.getApplicationName()) - .commandListenerList(mongoClientOptions.getCommandListeners()) - .codecRegistry(mongoClientOptions.getCodecRegistry()) - .applyToClusterSettings(clusterSettings -> { - clusterSettings.hosts(legacyMongoClient.getAllAddress()); - clusterSettings.localThreshold(mongoClientOptions.getLocalThreshold(), MILLISECONDS); - clusterSettings.serverSelectionTimeout(mongoClientOptions.getServerSelectionTimeout(), MILLISECONDS); - clusterSettings.serverSelector(mongoClientOptions.getServerSelector()); - clusterSettings.requiredReplicaSetName(mongoClientOptions.getRequiredReplicaSetName()); - mongoClientOptions.getClusterListeners().forEach(clusterSettings::addClusterListener); - }) - .applyToConnectionPoolSettings(connectionPoolSettings -> { - mongoClientOptions.getConnectionPoolListeners().forEach(connectionPoolSettings::addConnectionPoolListener); - connectionPoolSettings.maxConnectionIdleTime(mongoClientOptions.getMaxConnectionIdleTime(), MILLISECONDS); - connectionPoolSettings.maxConnectionLifeTime(mongoClientOptions.getMaxConnectionLifeTime(), MILLISECONDS); - connectionPoolSettings.maxWaitTime(mongoClientOptions.getMaxWaitTime(), MILLISECONDS); - }) - .applyToSocketSettings(socketSettings -> { - socketSettings.connectTimeout(mongoClientOptions.getConnectTimeout(), MILLISECONDS); - socketSettings.readTimeout(mongoClientOptions.getSocketTimeout(), MILLISECONDS); - }) - .applyToServerSettings(serverSettings -> { - mongoClientOptions.getServerListeners().forEach(serverSettings::addServerListener); - serverSettings.minHeartbeatFrequency(mongoClientOptions.getMinHeartbeatFrequency(), MILLISECONDS); - serverSettings.heartbeatFrequency(mongoClientOptions.getHeartbeatFrequency(), MILLISECONDS); - - }) - .applyToSslSettings(sslSettings -> { - sslSettings.enabled(mongoClientOptions.isSslEnabled()); - sslSettings.invalidHostNameAllowed(mongoClientOptions.isSslInvalidHostNameAllowed()); - sslSettings.context(mongoClientOptions.getSslContext()); - }); - if (legacyMongoClient.getCredential() != null) { - mongoClientSettingsBuilder.credential(legacyMongoClient.getCredential()); - } - return MongoClients.create(mongoClientSettingsBuilder.build()); - } - private void validateConfig() throws MongobeeConfigurationException { if (!hasText(dbName)) { throw new MongobeeConfigurationException("DB name is not set. It should be defined in MongoDB URI or via setter"); @@ -344,7 +275,7 @@ public Mongobee setDbName(String dbName) { * @param mongoClientURI object with defined mongo uri * @return Mongobee object for fluent interface */ - public Mongobee setMongoClientURI(MongoClientURI mongoClientURI) { + public Mongobee setMongoClientURI(ConnectionString mongoClientURI) { this.mongoClientURI = mongoClientURI; return this; } diff --git a/src/main/java/com/github/mongobeej/dao/ChangeEntryDao.java b/src/main/java/com/github/mongobeej/dao/ChangeEntryDao.java index fcf5549..c4fe71d 100644 --- a/src/main/java/com/github/mongobeej/dao/ChangeEntryDao.java +++ b/src/main/java/com/github/mongobeej/dao/ChangeEntryDao.java @@ -4,8 +4,8 @@ import com.github.mongobeej.exception.MongobeeConfigurationException; import com.github.mongobeej.exception.MongobeeConnectionException; import com.github.mongobeej.exception.MongobeeLockException; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; @@ -21,8 +21,7 @@ public class ChangeEntryDao { private static final Logger logger = LoggerFactory.getLogger("Mongobee dao"); private MongoDatabase mongoDatabase; - private com.mongodb.client.MongoClient mongoClient; - private MongoClient legacyMongoClient; + private MongoClient mongoClient; private ChangeEntryIndexDao indexDao; private String changelogCollectionName; private boolean waitForLock; @@ -52,7 +51,7 @@ public MongoDatabase getMongoDatabase() { return mongoDatabase; } - public MongoDatabase connectMongoDb(com.mongodb.client.MongoClient mongoClient, String dbName) throws MongobeeConfigurationException { + public MongoDatabase connectMongoDb(MongoClient mongoClient, String dbName) throws MongobeeConfigurationException { if (!hasText(dbName)) { throw new MongobeeConfigurationException("DB name is not set. Should be defined in MongoDB URI or via setter"); } else { @@ -64,21 +63,7 @@ public MongoDatabase connectMongoDb(com.mongodb.client.MongoClient mongoClient, } } - - @Deprecated - public MongoDatabase connectMongoDb(MongoClient mongo, String dbName) throws MongobeeConfigurationException { - if (!hasText(dbName)) { - throw new MongobeeConfigurationException("DB name is not set. Should be defined in MongoDB URI or via setter"); - } else { - this.legacyMongoClient = mongo; - mongoDatabase = mongo.getDatabase(dbName); - ensureChangeLogCollectionIndex(mongoDatabase.getCollection(changelogCollectionName)); - initializeLock(); - return mongoDatabase; - } - } - - public MongoDatabase connectMongoDb(MongoClientURI mongoClientURI, String dbName) + public MongoDatabase connectMongoDb(ConnectionString mongoClientURI, String dbName) throws MongobeeConfigurationException { final com.mongodb.client.MongoClient mongoClient = MongoClients.create(mongoClientURI.toString()); final String database = (!hasText(dbName)) ? mongoClientURI.getDatabase() : dbName; @@ -167,9 +152,6 @@ private void ensureChangeLogCollectionIndex(MongoCollection collection } public void close() { - if (legacyMongoClient != null) { - legacyMongoClient.close(); - } if (mongoClient != null) { mongoClient.close(); } diff --git a/src/main/java/com/github/mongobeej/dao/LockDao.java b/src/main/java/com/github/mongobeej/dao/LockDao.java index 850e84f..049f66f 100644 --- a/src/main/java/com/github/mongobeej/dao/LockDao.java +++ b/src/main/java/com/github/mongobeej/dao/LockDao.java @@ -65,7 +65,7 @@ public void releaseLock(MongoDatabase db) { * @return true if the lock is currently held */ public boolean isLockHeld(MongoDatabase db) { - return db.getCollection(lockCollectionName).count() == 1; + return db.getCollection(lockCollectionName).countDocuments() == 1; } public void setLockCollectionName(String lockCollectionName) { diff --git a/src/test/java/com/github/mongobeej/MongobeeBaseTest.java b/src/test/java/com/github/mongobeej/MongobeeBaseTest.java index adf01ca..26226a4 100644 --- a/src/test/java/com/github/mongobeej/MongobeeBaseTest.java +++ b/src/test/java/com/github/mongobeej/MongobeeBaseTest.java @@ -4,8 +4,8 @@ import com.github.mongobeej.dao.ChangeEntryDao; import com.github.mongobeej.dao.ChangeEntryIndexDao; import com.github.mongobeej.utils.MongoEnvironmentCreator; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; import org.junit.Before; import org.mockito.Mock; @@ -30,9 +30,7 @@ public void init() throws Exception { MongoEnvironmentCreator.MongoEnvironment mongoEnvironment = MongoEnvironmentCreator.createMongoEnvironment(); mongobee = new Mongobee(mongoEnvironment.getMongoClient()); mongoDatabase = mongoEnvironment.getMongoDatabase(); - when(changeEntryDao.connectMongoDb(any(MongoClientURI.class), anyString())) - .thenReturn(mongoDatabase); - when(changeEntryDao.connectMongoDb(any(com.mongodb.client.MongoClient.class), anyString())) + when(changeEntryDao.connectMongoDb(any(ConnectionString.class), anyString())) .thenReturn(mongoDatabase); when(changeEntryDao.connectMongoDb(any(MongoClient.class), anyString())) .thenReturn(mongoDatabase); diff --git a/src/test/java/com/github/mongobeej/MongobeeEnvTest.java b/src/test/java/com/github/mongobeej/MongobeeEnvTest.java index 9bab574..6b7ac98 100644 --- a/src/test/java/com/github/mongobeej/MongobeeEnvTest.java +++ b/src/test/java/com/github/mongobeej/MongobeeEnvTest.java @@ -27,7 +27,7 @@ public void shouldRunChangesetWithEnvironment() throws Exception { // then long change1 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Envtest1")); + .countDocuments(changeQuery("Envtest1")); assertEquals(1, change1); } @@ -44,7 +44,7 @@ public void shouldRunChangesetWithNullEnvironment() throws Exception { // then long change1 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Envtest1")); + .countDocuments(changeQuery("Envtest1")); assertEquals(1, change1); } diff --git a/src/test/java/com/github/mongobeej/MongobeeProfileTest.java b/src/test/java/com/github/mongobeej/MongobeeProfileTest.java index c3930ed..7929913 100644 --- a/src/test/java/com/github/mongobeej/MongobeeProfileTest.java +++ b/src/test/java/com/github/mongobeej/MongobeeProfileTest.java @@ -5,7 +5,6 @@ import com.github.mongobeej.test.changelogs.AnotherMongobeeTestResource; import com.github.mongobeej.test.profiles.def.UnProfiledChangeLog; import com.github.mongobeej.test.profiles.dev.ProfiledDevChangeLog; -import org.bson.Document; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,13 +31,13 @@ public void shouldRunDevProfileAndNonAnnotated() throws Exception { // then long change1 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev1")); + .countDocuments(changeQuery("Pdev1")); assertEquals(1, change1); // no-@Profile should not match long change2 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev4")); + .countDocuments(changeQuery("Pdev4")); assertEquals(1, change2); // @Profile("dev") should not match long change3 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev3")); + .countDocuments(changeQuery("Pdev3")); assertEquals(0, change3); // @Profile("default") should not match } @@ -54,19 +53,19 @@ public void shouldRunUnprofiledChangeLog() throws Exception { // then long change1 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev1")); + .countDocuments(changeQuery("Pdev1")); assertEquals(1, change1); long change2 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev2")); + .countDocuments(changeQuery("Pdev2")); assertEquals(1, change2); long change3 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev3")); + .countDocuments(changeQuery("Pdev3")); assertEquals(1, change3); // @Profile("dev") should not match long change4 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev4")); + .countDocuments(changeQuery("Pdev4")); assertEquals(0, change4); // @Profile("pro") should not match long change5 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("Pdev5")); + .countDocuments(changeQuery("Pdev5")); assertEquals(1, change5); // @Profile("!pro") should match } @@ -81,7 +80,7 @@ public void shouldNotRunAnyChangeSet() throws Exception { mongobee.execute(); // then - long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).count(new Document()); + long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).countDocuments(); assertEquals(0, changes); } @@ -96,7 +95,7 @@ public void shouldRunChangeSetsWhenNoEnv() throws Exception { mongobee.execute(); // then - long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).count(new Document()); + long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).countDocuments(); assertEquals(CHANGELOG_COUNT, changes); } @@ -111,7 +110,7 @@ public void shouldRunChangeSetsWhenEmptyEnv() throws Exception { mongobee.execute(); // then - long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).count(new Document()); + long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).countDocuments(); assertEquals(CHANGELOG_COUNT, changes); } @@ -126,7 +125,7 @@ public void shouldRunAllChangeSets() throws Exception { mongobee.execute(); // then - long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).count(new Document()); + long changes = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME).countDocuments(); assertEquals(CHANGELOG_COUNT, changes); } diff --git a/src/test/java/com/github/mongobeej/MongobeeTest.java b/src/test/java/com/github/mongobeej/MongobeeTest.java index ca38fe9..148976f 100644 --- a/src/test/java/com/github/mongobeej/MongobeeTest.java +++ b/src/test/java/com/github/mongobeej/MongobeeTest.java @@ -7,8 +7,8 @@ import com.github.mongobeej.exception.MongobeeException; import com.github.mongobeej.test.changelogs.MongobeeTestResource; import com.github.mongobeej.utils.MongoEnvironmentCreator.MongoEnvironment; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; +import com.mongodb.ConnectionString; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.junit.After; @@ -46,9 +46,7 @@ public class MongobeeTest { @Before public void init() throws MongobeeException { mongoDatabase = mongoEnvironment.getMongoDatabase(); - when(changeEntryDao.connectMongoDb(any(MongoClientURI.class), anyString())) - .thenReturn(mongoDatabase); - when(changeEntryDao.connectMongoDb(any(com.mongodb.client.MongoClient.class), anyString())) + when(changeEntryDao.connectMongoDb(any(ConnectionString.class), anyString())) .thenReturn(mongoDatabase); when(changeEntryDao.connectMongoDb(any(MongoClient.class), anyString())) .thenReturn(mongoDatabase); @@ -65,7 +63,7 @@ public void init() throws MongobeeException { @Test(expected = MongobeeConfigurationException.class) public void shouldThrowAnExceptionIfNoDbNameSet() throws Exception { - Mongobee runner = new Mongobee(new MongoClientURI("mongodb://localhost:27017/")); + Mongobee runner = new Mongobee(new ConnectionString("mongodb://localhost:27017/")); runner.setEnabled(true); runner.setChangeLogsScanPackage(MongobeeTestResource.class.getPackage().getName()); runner.execute(); @@ -85,19 +83,19 @@ public void shouldExecuteAllChangeSets() throws Exception { // dbchangelog collection checking long change1 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("test1")); + .countDocuments(changeQuery("test1")); assertEquals(1, change1); long change2 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("test2")); + .countDocuments(changeQuery("test2")); assertEquals(1, change2); long change3 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("test3")); + .countDocuments(changeQuery("test3")); assertEquals(1, change3); long change4 = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(changeQuery("test4")); + .countDocuments(changeQuery("test4")); assertEquals(1, change4); long changeAll = mongoDatabase.getCollection(CHANGELOG_COLLECTION_NAME) - .count(new Document().append(ChangeEntry.KEY_AUTHOR, "testuser")); + .countDocuments(new Document().append(ChangeEntry.KEY_AUTHOR, "testuser")); assertEquals(9, changeAll); } diff --git a/src/test/java/com/github/mongobeej/dao/ChangeEntryDaoTest.java b/src/test/java/com/github/mongobeej/dao/ChangeEntryDaoTest.java index 63ec360..bd3a82a 100644 --- a/src/test/java/com/github/mongobeej/dao/ChangeEntryDaoTest.java +++ b/src/test/java/com/github/mongobeej/dao/ChangeEntryDaoTest.java @@ -4,7 +4,7 @@ import com.github.mongobeej.exception.MongobeeLockException; import com.github.mongobeej.utils.MongoDatabaseArgumentMatcher; import com.github.mongobeej.utils.MongoEnvironmentCreator.MongoEnvironment; -import com.mongodb.MongoClient; +import com.mongodb.client.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; diff --git a/src/test/java/com/github/mongobeej/utils/MongoEnvironmentCreator.java b/src/test/java/com/github/mongobeej/utils/MongoEnvironmentCreator.java index 03fa24c..e0f2252 100644 --- a/src/test/java/com/github/mongobeej/utils/MongoEnvironmentCreator.java +++ b/src/test/java/com/github/mongobeej/utils/MongoEnvironmentCreator.java @@ -1,7 +1,7 @@ package com.github.mongobeej.utils; -import com.mongodb.MongoClient; -import com.mongodb.ServerAddress; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import de.bwaldvogel.mongo.MongoServer; import de.bwaldvogel.mongo.backend.memory.MemoryBackend; @@ -34,7 +34,8 @@ public MongoDatabase getMongoDatabase() { public static MongoEnvironment createMongoEnvironment() { MongoServer mongoServer = new MongoServer(new MemoryBackend()); InetSocketAddress serverAddress = mongoServer.bind(); - MongoClient mongoClient = new MongoClient(new ServerAddress(serverAddress)); + String mongoUri = "mongodb:/" + serverAddress.getAddress().toString() + ":" + serverAddress.getPort() + "/" + DB_NAME; + MongoClient mongoClient = MongoClients.create(mongoUri); return new MongoEnvironment(mongoClient); } } From 9312f2e775bb6b7e68f7500fdbfb8513b5f34042 Mon Sep 17 00:00:00 2001 From: Pawel Nowak Date: Sun, 23 Aug 2020 00:00:28 +0200 Subject: [PATCH 2/2] add deprecation notice --- README.md | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 0a86260..16d45c7 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ [![Licence](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/cybuch/mongobeeJ/blob/master/LICENSE) --- - **mongobeeJ** is a Java tool which helps you to *manage changes* in your MongoDB and *synchronize* them with your application. The concept is very similar to other db migration tools such as [Liquibase](http://www.liquibase.org) or [Flyway](http://flywaydb.org) but *without using XML/JSON/YML files*. mongobeeJ is built on top of [mongobee](https://github.com/mongobee/mongobee) The goal is to keep this tool simple and comfortable to use. - **mongobeeJ** provides new approach for adding changes (change sets) based on Java classes and methods with appropriate annotations. -## Getting started +## Deprecation Notice +**mongobeeJ** is no longer actively developed. It will be supported (bug fixes and dependency upgrades) for the sake of legacy projects that use **mongobeeJ** or **mongobee**. +However, it's recommended to migrate active projects from **mongobeeJ** to other tools like [Mongock](https://github.com/cloudyrock/mongock) or [Sherlock](https://coditory.github.io/sherlock-distributed-lock/migrator/). + +### Getting started ### Add a dependency @@ -200,39 +202,3 @@ public Mongobee mongobee(Environment environment) { //... etc } ``` - -## Known issues - -##### Mongo java driver conflicts - -**mongobeeJ** depends on `mongo-java-driver`. If your application has mongo-java-driver dependency too, there could be a library conflicts in some cases. - -**Exception**: -``` -com.mongodb.WriteConcernException: { "serverUsed" : "localhost" , -"err" : "invalid ns to index" , "code" : 10096 , "n" : 0 , -"connectionId" : 955 , "ok" : 1.0} -``` - -**Workaround**: - -You can exclude mongo-java-driver from **mongobeeJ** and use your dependency only. Maven example (pom.xml) below: -```xml - - org.mongodb - mongodb-driver-sync - 4.0.5 - - - - com.github.mongobeej - mongobeej - 1.0.1 - - - org.mongodb - mongodb-driver-sync - - - -```