diff --git a/build.gradle b/build.gradle index a751252c0..987c5a0d2 100644 --- a/build.gradle +++ b/build.gradle @@ -442,7 +442,6 @@ def serverPackages = ["com.mongodb.stitch.server.core", "com.mongodb.stitch.server.services.aws.ses", "com.mongodb.stitch.server.services.fcm", "com.mongodb.stitch.server.services.http", - "com.mongodb.stitch.server.services.mongodb.local", "com.mongodb.stitch.server.services.mongodb.remote", "com.mongodb.stitch.server.services.twilio"] diff --git a/core/services/mongodb-remote/build.gradle b/core/services/mongodb-remote/build.gradle index 1cc7343cb..f4c9d3ded 100644 --- a/core/services/mongodb-remote/build.gradle +++ b/core/services/mongodb-remote/build.gradle @@ -17,7 +17,6 @@ dependencies { testImplementation project(':core:stitch-core-admin-client') testImplementation project(':core:stitch-core-testutils') - testImplementation project(':server:server-services:stitch-server-services-mongodb-local') testImplementation "org.mongodb:mongodb-driver-embedded:3.9.0-SNAPSHOT" testImplementation 'junit:junit:4.12' testImplementation "org.mockito:mockito-core:2.18.3" diff --git a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientImpl.java b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientImpl.java index 3e4084624..e65e7ed15 100644 --- a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientImpl.java +++ b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientImpl.java @@ -26,80 +26,94 @@ import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.SyncMongoClientFactory; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class CoreRemoteMongoClientImpl implements CoreRemoteMongoClient, StitchServiceBinder { private final CoreStitchServiceClient service; private final StitchAppClientInfo appInfo; - private final EmbeddedMongoClientFactory clientFactory; - private DataSynchronizer dataSynchronizer; + // Sync related fields + private boolean hasSync; + @Nullable private final EmbeddedMongoClientFactory clientFactory; + @Nullable private DataSynchronizer dataSynchronizer; @Nonnull private String lastActiveUserId; public CoreRemoteMongoClientImpl(final CoreStitchServiceClient service, final String instanceKey, final StitchAppClientInfo appInfo, - final EmbeddedMongoClientFactory clientFactory) { + final @Nullable EmbeddedMongoClientFactory clientFactory) { this.service = service; this.appInfo = appInfo; this.clientFactory = clientFactory; + + if (clientFactory != null) { + this.hasSync = true; + this.dataSynchronizer = new DataSynchronizer( + instanceKey, + service, + SyncMongoClientFactory.getClient( + appInfo, + service.getName(), + clientFactory + ), + this, + appInfo.getNetworkMonitor(), + appInfo.getAuthMonitor(), + appInfo.getEventDispatcher() + ); + // set this to an empty string to avoid cumbersome null + // checks when comparing to the next activeUser + this.lastActiveUserId = appInfo.getAuthMonitor().getActiveUserId() != null + ? appInfo.getAuthMonitor().getActiveUserId() : ""; + } else { + this.hasSync = false; + this.lastActiveUserId = ""; + } + this.service.bind(this); - // set this to an empty string to avoid cumbersome null - // checks when comparing to the next activeUser - this.lastActiveUserId = appInfo.getAuthMonitor().getActiveUserId() != null - ? appInfo.getAuthMonitor().getActiveUserId() : ""; - this.dataSynchronizer = new DataSynchronizer( - instanceKey, - service, - SyncMongoClientFactory.getClient( - appInfo, - service.getName(), - clientFactory - ), - this, - appInfo.getNetworkMonitor(), - appInfo.getAuthMonitor(), - appInfo.getEventDispatcher() - ); } private void onAuthEvent(final AuthEvent authEvent) { - switch (authEvent.getAuthEventType()) { - case USER_REMOVED: - final String userId = ((AuthEvent.UserRemoved)authEvent).getRemovedUser().getId(); - if (!SyncMongoClientFactory.deleteDatabase( - appInfo, - service.getName(), - clientFactory, - userId - )) { - System.err.println("Could not delete database for user id " + userId); - } - break; - case ACTIVE_USER_CHANGED: - if (!lastActiveUserId.equals(appInfo.getAuthMonitor().getActiveUserId())) { - this.lastActiveUserId = appInfo.getAuthMonitor().getActiveUserId() != null - ? appInfo.getAuthMonitor().getActiveUserId() : ""; - if (authEvent instanceof AuthEvent.ActiveUserChanged - && ((AuthEvent.ActiveUserChanged)authEvent).getCurrentActiveUser() != null) { - // reinitialize the DataSynchronizer entirely. - // any auth event will trigger this. - this.dataSynchronizer.reinitialize( - SyncMongoClientFactory.getClient( - appInfo, - service.getName(), - clientFactory - ) - ); - } else { - this.dataSynchronizer.stop(); + // Only perform user rebinding if this client has mobile sync functionality. + if (hasSync) { + switch (authEvent.getAuthEventType()) { + case USER_REMOVED: + final String userId = ((AuthEvent.UserRemoved)authEvent).getRemovedUser().getId(); + if (!SyncMongoClientFactory.deleteDatabase( + appInfo, + service.getName(), + clientFactory, + userId + )) { + System.err.println("Could not delete database for user id " + userId); } - } - break; - default: - // no-op - break; + break; + case ACTIVE_USER_CHANGED: + if (!lastActiveUserId.equals(appInfo.getAuthMonitor().getActiveUserId())) { + this.lastActiveUserId = appInfo.getAuthMonitor().getActiveUserId() != null + ? appInfo.getAuthMonitor().getActiveUserId() : ""; + if (authEvent instanceof AuthEvent.ActiveUserChanged + && ((AuthEvent.ActiveUserChanged)authEvent).getCurrentActiveUser() != null) { + // reinitialize the DataSynchronizer entirely. + // any auth event will trigger this. + this.dataSynchronizer.reinitialize( + SyncMongoClientFactory.getClient( + appInfo, + service.getName(), + clientFactory + ) + ); + } else { + this.dataSynchronizer.stop(); + } + } + break; + default: + // no-op + break; + } } } @@ -124,7 +138,7 @@ public CoreRemoteMongoDatabaseImpl getDatabase(final String databaseName) { return new CoreRemoteMongoDatabaseImpl( databaseName, service, - dataSynchronizer, + (hasSync) ? dataSynchronizer : null, appInfo.getNetworkMonitor() ); } @@ -135,7 +149,9 @@ public DataSynchronizer getDataSynchronizer() { @Override public void close() { - this.dataSynchronizer.stop(); - this.dataSynchronizer.close(); + if (hasSync) { + this.dataSynchronizer.stop(); + this.dataSynchronizer.close(); + } } } diff --git a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollection.java b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollection.java index d3265e736..156b8e547 100644 --- a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollection.java +++ b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollection.java @@ -33,6 +33,8 @@ import java.io.IOException; import java.util.List; +import javax.annotation.Nullable; + import org.bson.BsonDocument; import org.bson.BsonObjectId; import org.bson.BsonValue; @@ -40,6 +42,7 @@ import org.bson.conversions.Bson; import org.bson.types.ObjectId; + public interface CoreRemoteMongoCollection { /** @@ -521,5 +524,5 @@ Stream> watchCompact(final BsonValue... ids) * * @return set of sync operations for this collection */ - CoreSync sync(); + @Nullable CoreSync sync(); } diff --git a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java index bb45deaad..a1591e99a 100644 --- a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java +++ b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java @@ -42,6 +42,8 @@ import java.util.HashSet; import java.util.List; +import javax.annotation.Nullable; + import org.bson.BsonDocument; import org.bson.BsonObjectId; import org.bson.BsonValue; @@ -49,6 +51,7 @@ import org.bson.conversions.Bson; import org.bson.types.ObjectId; + public class CoreRemoteMongoCollectionImpl implements CoreRemoteMongoCollection { @@ -56,36 +59,42 @@ public class CoreRemoteMongoCollectionImpl private final Class documentClass; private final CoreStitchServiceClient service; private final Operations operations; + // Sync related fields - private final CoreSync coreSync; - private final DataSynchronizer dataSynchronizer; - private final NetworkMonitor networkMonitor; + @Nullable private final CoreSync coreSync; + @Nullable private final DataSynchronizer dataSynchronizer; + @Nullable private final NetworkMonitor networkMonitor; CoreRemoteMongoCollectionImpl(final MongoNamespace namespace, final Class documentClass, final CoreStitchServiceClient service, - final DataSynchronizer dataSynchronizer, - final NetworkMonitor networkMonitor) { + @Nullable final DataSynchronizer dataSynchronizer, + @Nullable final NetworkMonitor networkMonitor) { notNull("namespace", namespace); notNull("documentClass", documentClass); this.namespace = namespace; this.documentClass = documentClass; this.service = service; this.operations = new Operations<>(namespace, documentClass, service.getCodecRegistry()); + this.dataSynchronizer = dataSynchronizer; this.networkMonitor = networkMonitor; - this.coreSync = new CoreSyncImpl<>( - getNamespace(), - getDocumentClass(), - dataSynchronizer, - service, - new SyncOperations<>( - getNamespace(), - getDocumentClass(), - dataSynchronizer, - getCodecRegistry()) - ); + if (dataSynchronizer != null && this.networkMonitor != null) { + this.coreSync = new CoreSyncImpl<>( + getNamespace(), + getDocumentClass(), + dataSynchronizer, + service, + new SyncOperations<>( + getNamespace(), + getDocumentClass(), + dataSynchronizer, + getCodecRegistry()) + ); + } else { + this.coreSync = null; + } } /** @@ -788,7 +797,7 @@ public Stream> watchCompact(final BsonValue... ids } @Override - public CoreSync sync() { + public @Nullable CoreSync sync() { return this.coreSync; } } diff --git a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseImpl.java b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseImpl.java index 44f60e43e..acfd2c704 100644 --- a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseImpl.java +++ b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseImpl.java @@ -24,22 +24,25 @@ import com.mongodb.stitch.core.services.internal.CoreStitchServiceClient; import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.DataSynchronizer; +import javax.annotation.Nullable; + import org.bson.Document; + public class CoreRemoteMongoDatabaseImpl implements CoreRemoteMongoDatabase { private final String name; private final CoreStitchServiceClient service; // Sync related fields - private final DataSynchronizer dataSynchronizer; - private final NetworkMonitor networkMonitor; + @Nullable private final DataSynchronizer dataSynchronizer; + @Nullable private final NetworkMonitor networkMonitor; CoreRemoteMongoDatabaseImpl( final String name, final CoreStitchServiceClient service, - final DataSynchronizer dataSynchronizer, - final NetworkMonitor networkMonitor + @Nullable final DataSynchronizer dataSynchronizer, + @Nullable final NetworkMonitor networkMonitor ) { notNull("name", name); checkDatabaseNameValidity(name); diff --git a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteClientFactory.java b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteClientFactory.java index a4e561fdc..fbd0d0684 100644 --- a/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteClientFactory.java +++ b/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteClientFactory.java @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; + public abstract class CoreRemoteClientFactory { private static final Map syncInstances = new HashMap<>(); @@ -33,7 +35,7 @@ public abstract class CoreRemoteClientFactory { public static synchronized CoreRemoteMongoClient getClient( final CoreStitchServiceClient service, final StitchAppClientInfo appInfo, - final EmbeddedMongoClientFactory clientFactory + final @Nullable EmbeddedMongoClientFactory clientFactory ) { final String instanceKey = String.format("%s-%s", appInfo.getClientAppId(), service.getName()); if (syncInstances.containsKey(instanceKey)) { diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientUnitTests.java b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientUnitTests.java index 786e37d90..be2e52a27 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientUnitTests.java +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoClientUnitTests.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.CoreRemoteClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; import org.junit.After; import org.junit.Test; @@ -30,7 +29,6 @@ public class CoreRemoteMongoClientUnitTests { @After public void teardown() { CoreRemoteClientFactory.close(); - ServerEmbeddedMongoClientFactory.getInstance().close(); } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionUnitTests.java b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionUnitTests.java index 086fb70cf..d75c5ed6e 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionUnitTests.java +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionUnitTests.java @@ -46,7 +46,6 @@ import com.mongodb.stitch.core.services.mongodb.remote.RemoteUpdateOptions; import com.mongodb.stitch.core.services.mongodb.remote.RemoteUpdateResult; import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.CoreRemoteClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; import java.io.IOException; import java.util.ArrayList; @@ -81,7 +80,6 @@ public class CoreRemoteMongoCollectionUnitTests { @After public void teardown() { CoreRemoteClientFactory.close(); - ServerEmbeddedMongoClientFactory.getInstance().close(); } @Test @@ -132,7 +130,7 @@ public void testCount() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); doReturn(42L) @@ -193,7 +191,7 @@ public void testFindOne() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -267,7 +265,7 @@ public void testFind() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -346,7 +344,7 @@ public void testAggregate() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -411,7 +409,7 @@ public void testInsertOne() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -468,7 +466,7 @@ public void testDeleteOne() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); doReturn(new RemoteDeleteResult(1)) @@ -514,7 +512,7 @@ public void testDeleteMany() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); doReturn(new RemoteDeleteResult(1)) @@ -560,7 +558,7 @@ public void testUpdateOne() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final BsonObjectId id = new BsonObjectId(); @@ -629,7 +627,7 @@ public void testUpdateMany() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final BsonObjectId id = new BsonObjectId(); @@ -699,7 +697,7 @@ public void testFindOneAndUpdate() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -820,7 +818,7 @@ public void testFindOneAndReplace() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -941,7 +939,7 @@ public void testFindOneAndDelete() { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Document doc1 = new Document("one", 2); @@ -1029,7 +1027,7 @@ public void testWatchFullCollection() throws IOException, InterruptedException { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); @@ -1072,7 +1070,7 @@ public void testWatchWithFilter() throws IOException, InterruptedException { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); @@ -1118,7 +1116,7 @@ public void testWatchBsonValueIDs() throws IOException, InterruptedException { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); @@ -1161,7 +1159,7 @@ public void testWatchObjectIdIDs() throws IOException, InterruptedException { CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); @@ -1207,7 +1205,7 @@ public void testWatchCompactBsonValueIDs() throws IOException, InterruptedExcept CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); @@ -1250,7 +1248,7 @@ public void testWatchCompactObjectIdIDs() throws IOException, InterruptedExcepti CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); final CoreRemoteMongoCollection coll = getCollection(client); final Stream> mockStream = Mockito.mock(Stream.class); diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseUnitTests.java b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseUnitTests.java index 3c5e14e41..b9611c5cd 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseUnitTests.java +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoDatabaseUnitTests.java @@ -21,7 +21,6 @@ import com.mongodb.MongoNamespace; import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.CoreRemoteClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; import org.bson.Document; import org.junit.After; @@ -32,7 +31,6 @@ public class CoreRemoteMongoDatabaseUnitTests { @After public void teardown() { CoreRemoteClientFactory.close(); - ServerEmbeddedMongoClientFactory.getInstance().close(); } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/TestUtils.java b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/TestUtils.java index 02c1a9888..60f2596d4 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/TestUtils.java +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/internal/TestUtils.java @@ -26,7 +26,6 @@ import com.mongodb.stitch.core.services.internal.CoreStitchServiceClientImpl; import com.mongodb.stitch.core.services.internal.StitchServiceRoutes; import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.CoreRemoteClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -48,7 +47,7 @@ public static CoreRemoteMongoClient getClient() { return CoreRemoteClientFactory.getClient( service, getClientInfo(), - ServerEmbeddedMongoClientFactory.getInstance()); + null); } static CoreRemoteMongoDatabase getDatabase(final String name) { diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfigUnitTests.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfigUnitTests.kt index e04b876b2..30e0abcf6 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfigUnitTests.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfigUnitTests.kt @@ -9,7 +9,6 @@ import com.mongodb.stitch.core.internal.net.NetworkMonitor import com.mongodb.stitch.core.services.mongodb.remote.OperationType import com.mongodb.stitch.core.services.mongodb.remote.UpdateDescription import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.SyncUnitTestHarness.Companion.compareEvents -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonDocument import org.bson.BsonObjectId import org.bson.BsonString @@ -23,7 +22,7 @@ import org.junit.Test class CoreDocumentSynchronizationConfigUnitTests { @After fun teardown() { - ServerEmbeddedMongoClientFactory.getInstance().close() + UnitTestEmbeddedMongoClientFactory.getInstance().close() } private val namespace = MongoNamespace("foo", "bar") @@ -65,7 +64,7 @@ class CoreDocumentSynchronizationConfigUnitTests { ThreadDispatcher() ), "mongodblocal", - ServerEmbeddedMongoClientFactory.getInstance() + UnitTestEmbeddedMongoClientFactory.getInstance() ) private val coll by lazy { localClient.getDatabase(namespace.databaseName) diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncUnitTests.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncUnitTests.kt index 2620f6b44..77e008d48 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncUnitTests.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncUnitTests.kt @@ -5,7 +5,6 @@ import com.mongodb.MongoWriteException import com.mongodb.stitch.core.services.mongodb.remote.RemoteFindOptions import com.mongodb.stitch.core.services.mongodb.remote.sync.SyncCountOptions import com.mongodb.stitch.core.services.mongodb.remote.sync.SyncUpdateOptions -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonArray import org.bson.BsonBoolean import org.bson.BsonDocument @@ -76,7 +75,7 @@ class CoreSyncUnitTests { fun teardown() { harness.close() CoreRemoteClientFactory.close() - ServerEmbeddedMongoClientFactory.getInstance().close() + UnitTestEmbeddedMongoClientFactory.getInstance().close() } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerCRUDUnitTests.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerCRUDUnitTests.kt index b6d9577aa..eceb40a64 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerCRUDUnitTests.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerCRUDUnitTests.kt @@ -8,7 +8,6 @@ import com.mongodb.stitch.core.services.mongodb.remote.RemoteDeleteResult import com.mongodb.stitch.core.services.mongodb.remote.RemoteUpdateResult import com.mongodb.stitch.core.services.mongodb.remote.UpdateDescription import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.SyncUnitTestHarness.Companion.withoutSyncVersion -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonDocument import org.bson.BsonInt32 import org.bson.BsonString @@ -85,7 +84,7 @@ class DataSynchronizerCRUDUnitTests { fun teardown() { harness.close() CoreRemoteClientFactory.close() - ServerEmbeddedMongoClientFactory.getInstance().close() + UnitTestEmbeddedMongoClientFactory.getInstance().close() } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerUnitTests.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerUnitTests.kt index 328cd60ba..b6a11fa0f 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerUnitTests.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizerUnitTests.kt @@ -3,7 +3,6 @@ package com.mongodb.stitch.core.services.mongodb.remote.sync.internal import com.mongodb.stitch.core.services.mongodb.remote.RemoteUpdateResult import com.mongodb.stitch.core.services.mongodb.remote.UpdateDescription import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.SyncUnitTestHarness.Companion.withoutSyncVersion -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonBoolean import org.bson.BsonDocument @@ -34,7 +33,7 @@ class DataSynchronizerUnitTests { fun teardown() { harness.close() CoreRemoteClientFactory.close() - ServerEmbeddedMongoClientFactory.getInstance().close() + UnitTestEmbeddedMongoClientFactory.getInstance().close() } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListenerUnitTests.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListenerUnitTests.kt index b44aac767..724180f43 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListenerUnitTests.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListenerUnitTests.kt @@ -1,7 +1,6 @@ package com.mongodb.stitch.core.services.mongodb.remote.sync.internal import com.mongodb.stitch.core.internal.net.Event -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonObjectId import org.bson.Document import org.junit.After @@ -20,7 +19,7 @@ class NamespaceChangeStreamListenerUnitTests { @After fun teardown() { CoreRemoteClientFactory.close() - ServerEmbeddedMongoClientFactory.getInstance().close() + UnitTestEmbeddedMongoClientFactory.getInstance().close() } @Test diff --git a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncUnitTestHarness.kt b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncUnitTestHarness.kt index 112355030..b064d964f 100644 --- a/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncUnitTestHarness.kt +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncUnitTestHarness.kt @@ -32,7 +32,6 @@ import com.mongodb.stitch.core.services.mongodb.remote.sync.ChangeEventListener import com.mongodb.stitch.core.services.mongodb.remote.sync.ConflictHandler import com.mongodb.stitch.core.services.mongodb.remote.sync.ConflictResolution import com.mongodb.stitch.core.services.mongodb.remote.sync.CoreSync -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory import org.bson.BsonDocument import org.bson.BsonInt32 import org.bson.BsonInt64 @@ -363,7 +362,7 @@ class SyncUnitTestHarness : Closeable { ThreadDispatcher() ), "local", - ServerEmbeddedMongoClientFactory.getInstance() + UnitTestEmbeddedMongoClientFactory.getInstance() ) } diff --git a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/ServerEmbeddedMongoClientFactory.java b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/UnitTestEmbeddedMongoClientFactory.java similarity index 75% rename from server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/ServerEmbeddedMongoClientFactory.java rename to core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/UnitTestEmbeddedMongoClientFactory.java index 22a1083c4..5aa3f7668 100644 --- a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/ServerEmbeddedMongoClientFactory.java +++ b/core/services/mongodb-remote/src/test/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/UnitTestEmbeddedMongoClientFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.mongodb.stitch.server.services.mongodb.local.internal; +package com.mongodb.stitch.core.services.mongodb.remote.sync.internal; import com.mongodb.client.MongoClient; import com.mongodb.embedded.client.MongoClientSettings; @@ -24,22 +24,21 @@ import org.bson.codecs.configuration.CodecRegistry; -public final class ServerEmbeddedMongoClientFactory extends EmbeddedMongoClientFactory { +public final class UnitTestEmbeddedMongoClientFactory extends EmbeddedMongoClientFactory { + private static UnitTestEmbeddedMongoClientFactory factory; - private static ServerEmbeddedMongoClientFactory factory; - - private ServerEmbeddedMongoClientFactory() { + private UnitTestEmbeddedMongoClientFactory() { super(); MongoClients.init(MongoEmbeddedSettings.builder().build()); } - public static ServerEmbeddedMongoClientFactory getInstance() { - synchronized (ServerEmbeddedMongoClientFactory.class) { + public static UnitTestEmbeddedMongoClientFactory getInstance() { + synchronized (UnitTestEmbeddedMongoClientFactory.class) { if (factory != null) { return factory; } - factory = new ServerEmbeddedMongoClientFactory(); + factory = new UnitTestEmbeddedMongoClientFactory(); } return factory; } diff --git a/server/services/mongodb-local/.gitignore b/server/services/mongodb-local/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/server/services/mongodb-local/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/server/services/mongodb-local/build.gradle b/server/services/mongodb-local/build.gradle deleted file mode 100644 index 09a9829d9..000000000 --- a/server/services/mongodb-local/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -apply plugin: 'java-library' - -ext.pomDisplayName = "Server Local MongoDB Service" - -buildscript { - dependencies { - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - } -} - -dependencies { - implementation project(':server:stitch-server-core') - api project(':core:core-services:stitch-core-services-mongodb-local') - api('org.mongodb:mongodb-driver-embedded:3.9.0-SNAPSHOT') -} - -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/LocalMongoDbService.java b/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/LocalMongoDbService.java deleted file mode 100644 index bf8235acb..000000000 --- a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/LocalMongoDbService.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2018-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mongodb.stitch.server.services.mongodb.local; - -import com.mongodb.client.MongoClient; -import com.mongodb.stitch.core.services.mongodb.local.internal.LocalMongoClientFactory; -import com.mongodb.stitch.server.core.services.internal.ServiceClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; - -/** - * The LocalMongoDbService is used to access {@link LocalMongoDbService#clientFactory} which - * provides MongoClients used for local storage using the embedded MongoDB platform. - */ -public final class LocalMongoDbService { - private LocalMongoDbService() { - // prevent instantiation - } - - public static final ServiceClientFactory clientFactory = - (service, appInfo) -> LocalMongoClientFactory.getClient( - appInfo, ServerEmbeddedMongoClientFactory.getInstance()); -} diff --git a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/package-info.java b/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/package-info.java deleted file mode 100644 index 9d1df2e20..000000000 --- a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/internal/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2018-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * This internal package contains the Server SDK's client factory for working with the MongoDB - * embedded platform. - */ -package com.mongodb.stitch.server.services.mongodb.local.internal; diff --git a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/package-info.java b/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/package-info.java deleted file mode 100644 index e08df610b..000000000 --- a/server/services/mongodb-local/src/main/java/com/mongodb/stitch/server/services/mongodb/local/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2018-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** This package contains the local MongoClient used for local storage. */ -package com.mongodb.stitch.server.services.mongodb.local; diff --git a/server/services/mongodb-remote/build.gradle b/server/services/mongodb-remote/build.gradle index a3f5c6247..219ee685d 100644 --- a/server/services/mongodb-remote/build.gradle +++ b/server/services/mongodb-remote/build.gradle @@ -23,7 +23,6 @@ test { dependencies { implementation project(':server:stitch-server-core') api project(':core:core-services:stitch-core-services-mongodb-remote') - api project(':server:server-services:stitch-server-services-mongodb-local') testImplementation project(':server:stitch-server-testutils') testImplementation 'junit:junit:4.12' diff --git a/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClient.java b/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClient.java index df94353f3..9d36d734c 100644 --- a/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClient.java +++ b/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClient.java @@ -18,7 +18,6 @@ import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.CoreRemoteClientFactory; import com.mongodb.stitch.server.core.services.internal.NamedServiceClientFactory; -import com.mongodb.stitch.server.services.mongodb.local.internal.ServerEmbeddedMongoClientFactory; import com.mongodb.stitch.server.services.mongodb.remote.internal.RemoteMongoClientImpl; /** @@ -39,5 +38,5 @@ public interface RemoteMongoClient { CoreRemoteClientFactory.getClient( service, appInfo, - ServerEmbeddedMongoClientFactory.getInstance())); + null)); } diff --git a/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/internal/RemoteMongoClientImpl.java b/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/internal/RemoteMongoClientImpl.java index e6d1abd02..5cc83d595 100644 --- a/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/internal/RemoteMongoClientImpl.java +++ b/server/services/mongodb-remote/src/main/java/com/mongodb/stitch/server/services/mongodb/remote/internal/RemoteMongoClientImpl.java @@ -17,8 +17,6 @@ package com.mongodb.stitch.server.services.mongodb.remote.internal; import com.mongodb.stitch.core.services.mongodb.remote.internal.CoreRemoteMongoClient; -import com.mongodb.stitch.core.services.mongodb.remote.internal.CoreRemoteMongoClientImpl; -import com.mongodb.stitch.core.services.mongodb.remote.sync.internal.DataSynchronizer; import com.mongodb.stitch.server.services.mongodb.remote.RemoteMongoClient; import com.mongodb.stitch.server.services.mongodb.remote.RemoteMongoDatabase; @@ -39,8 +37,4 @@ public RemoteMongoClientImpl(final CoreRemoteMongoClient client) { public RemoteMongoDatabase getDatabase(final String databaseName) { return new RemoteMongoDatabaseImpl(proxy.getDatabase(databaseName)); } - - public DataSynchronizer getDataSynchronizer() { - return ((CoreRemoteMongoClientImpl)this.proxy).getDataSynchronizer(); - } } diff --git a/server/services/mongodb-remote/src/test/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClientIntTests.kt b/server/services/mongodb-remote/src/test/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClientIntTests.kt index 11db8ff36..724762910 100644 --- a/server/services/mongodb-remote/src/test/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClientIntTests.kt +++ b/server/services/mongodb-remote/src/test/java/com/mongodb/stitch/server/services/mongodb/remote/RemoteMongoClientIntTests.kt @@ -12,7 +12,6 @@ import com.mongodb.stitch.core.internal.common.BsonUtils import com.mongodb.stitch.core.services.mongodb.remote.OperationType import com.mongodb.stitch.core.services.mongodb.remote.RemoteCountOptions import com.mongodb.stitch.server.core.StitchAppClient -import com.mongodb.stitch.server.services.mongodb.remote.internal.RemoteMongoClientImpl import com.mongodb.stitch.server.testutils.BaseStitchServerIntTest import com.mongodb.stitch.core.services.mongodb.remote.RemoteFindOptions @@ -95,7 +94,6 @@ class RemoteMongoClientIntTests : BaseStitchServerIntTest() { @After override fun teardown() { - (mongoClient as RemoteMongoClientImpl).dataSynchronizer.close() super.teardown() } diff --git a/settings.gradle b/settings.gradle index ee5ea22f7..335822cb8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,7 +21,6 @@ include ':core:sdk', ':server:services:aws-ses', ':server:services:fcm', ':server:services:http', - ':server:services:mongodb-local', ':server:services:mongodb-remote', ':server:services:twilio', ':server:testutils', @@ -67,7 +66,6 @@ project(':server:services:aws-s3').name = 'stitch-server-services-aws-s3' project(':server:services:aws-ses').name = 'stitch-server-services-aws-ses' project(':server:services:fcm').name = 'stitch-server-services-fcm' project(':server:services:http').name = 'stitch-server-services-http' -project(':server:services:mongodb-local').name = 'stitch-server-services-mongodb-local' project(':server:services:mongodb-remote').name = 'stitch-server-services-mongodb-remote' project(':server:services:twilio').name = 'stitch-server-services-twilio' project(':server:testutils').name = 'stitch-server-testutils'