From 91c1ab90e652951d3c655bb4a5231839996e9773 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Wed, 1 Nov 2023 21:49:02 -0700 Subject: [PATCH 1/9] Remove write concern from Atlas Search Index commands. JAVA-5233 --- .../operation/AbstractWriteSearchIndexOperation.java | 10 +--------- .../operation/CreateSearchIndexesOperation.java | 11 +++-------- .../internal/operation/DropSearchIndexOperation.java | 11 +++-------- .../com/mongodb/internal/operation/Operations.java | 7 +++---- .../operation/UpdateSearchIndexesOperation.java | 12 +++--------- .../AbstractAtlasSearchIndexManagementProseTest.java | 10 ++++++++-- 6 files changed, 21 insertions(+), 40 deletions(-) diff --git a/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java b/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java index 83fbd97081f..82da3fc7646 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java @@ -19,7 +19,6 @@ import com.mongodb.MongoCommandException; import com.mongodb.MongoNamespace; -import com.mongodb.WriteConcern; import com.mongodb.internal.async.SingleResultCallback; import com.mongodb.internal.binding.AsyncWriteBinding; import com.mongodb.internal.binding.WriteBinding; @@ -40,12 +39,9 @@ */ abstract class AbstractWriteSearchIndexOperation implements AsyncWriteOperation, WriteOperation { private final MongoNamespace namespace; - private final WriteConcern writeConcern; - AbstractWriteSearchIndexOperation(final MongoNamespace mongoNamespace, - final WriteConcern writeConcern) { + AbstractWriteSearchIndexOperation(final MongoNamespace mongoNamespace) { this.namespace = mongoNamespace; - this.writeConcern = writeConcern; } @Override @@ -101,8 +97,4 @@ void swallowOrThrow(@Nullable final E mongoExecutionExcept MongoNamespace getNamespace() { return namespace; } - - WriteConcern getWriteConcern() { - return writeConcern; - } } diff --git a/driver-core/src/main/com/mongodb/internal/operation/CreateSearchIndexesOperation.java b/driver-core/src/main/com/mongodb/internal/operation/CreateSearchIndexesOperation.java index 0832668a85a..1a44d887586 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/CreateSearchIndexesOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/CreateSearchIndexesOperation.java @@ -17,7 +17,6 @@ package com.mongodb.internal.operation; import com.mongodb.MongoNamespace; -import com.mongodb.WriteConcern; import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.BsonString; @@ -26,7 +25,6 @@ import java.util.stream.Collectors; import static com.mongodb.assertions.Assertions.assertNotNull; -import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; /** * An operation that creates one or more Atlas Search indexes. @@ -37,9 +35,8 @@ final class CreateSearchIndexesOperation extends AbstractWriteSearchIndexOperati private static final String COMMAND_NAME = "createSearchIndexes"; private final List indexRequests; - CreateSearchIndexesOperation(final MongoNamespace namespace, final List indexRequests, - final WriteConcern writeConcern) { - super(namespace, writeConcern); + CreateSearchIndexesOperation(final MongoNamespace namespace, final List indexRequests) { + super(namespace); this.indexRequests = assertNotNull(indexRequests); } @@ -61,9 +58,7 @@ private static BsonDocument convert(final SearchIndexRequest request) { @Override BsonDocument buildCommand() { - BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) + return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) .append("indexes", convert(indexRequests)); - appendWriteConcernToCommand(getWriteConcern(), command); - return command; } } diff --git a/driver-core/src/main/com/mongodb/internal/operation/DropSearchIndexOperation.java b/driver-core/src/main/com/mongodb/internal/operation/DropSearchIndexOperation.java index 422af56b55b..657dedca942 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/DropSearchIndexOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/DropSearchIndexOperation.java @@ -17,13 +17,11 @@ package com.mongodb.internal.operation; import com.mongodb.MongoNamespace; -import com.mongodb.WriteConcern; import com.mongodb.lang.Nullable; import org.bson.BsonDocument; import org.bson.BsonString; import static com.mongodb.internal.operation.CommandOperationHelper.isNamespaceError; -import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; /** * An operation that drops an Alas Search index. @@ -34,9 +32,8 @@ final class DropSearchIndexOperation extends AbstractWriteSearchIndexOperation { private static final String COMMAND_NAME = "dropSearchIndex"; private final String indexName; - DropSearchIndexOperation(final MongoNamespace namespace, final String indexName, - final WriteConcern writeConcern) { - super(namespace, writeConcern); + DropSearchIndexOperation(final MongoNamespace namespace, final String indexName) { + super(namespace); this.indexName = indexName; } @@ -49,9 +46,7 @@ void swallowOrThrow(@Nullable final E mongoExecutionExcept @Override BsonDocument buildCommand() { - BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) + return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) .append("name", new BsonString(indexName)); - appendWriteConcernToCommand(getWriteConcern(), command); - return command; } } diff --git a/driver-core/src/main/com/mongodb/internal/operation/Operations.java b/driver-core/src/main/com/mongodb/internal/operation/Operations.java index f0f6e72b680..ed84e9b2e72 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/Operations.java +++ b/driver-core/src/main/com/mongodb/internal/operation/Operations.java @@ -651,20 +651,19 @@ CreateSearchIndexesOperation createSearchIndexes(final List in .map(this::createSearchIndexRequest) .collect(Collectors.toList()); - return new CreateSearchIndexesOperation(assertNotNull(namespace), indexRequests, writeConcern); + return new CreateSearchIndexesOperation(assertNotNull(namespace), indexRequests); } UpdateSearchIndexesOperation updateSearchIndex(final String indexName, final Bson definition) { BsonDocument definitionDocument = assertNotNull(toBsonDocument(definition)); SearchIndexRequest searchIndexRequest = new SearchIndexRequest(definitionDocument, indexName); - return new UpdateSearchIndexesOperation(assertNotNull(namespace), searchIndexRequest, - writeConcern); + return new UpdateSearchIndexesOperation(assertNotNull(namespace), searchIndexRequest); } DropSearchIndexOperation dropSearchIndex(final String indexName) { - return new DropSearchIndexOperation(assertNotNull(namespace), indexName, writeConcern); + return new DropSearchIndexOperation(assertNotNull(namespace), indexName); } diff --git a/driver-core/src/main/com/mongodb/internal/operation/UpdateSearchIndexesOperation.java b/driver-core/src/main/com/mongodb/internal/operation/UpdateSearchIndexesOperation.java index 72402a0d22e..7bd33730680 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/UpdateSearchIndexesOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/UpdateSearchIndexesOperation.java @@ -17,12 +17,9 @@ package com.mongodb.internal.operation; import com.mongodb.MongoNamespace; -import com.mongodb.WriteConcern; import org.bson.BsonDocument; import org.bson.BsonString; -import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; - /** * An operation that updates an Atlas Search index. * @@ -32,19 +29,16 @@ final class UpdateSearchIndexesOperation extends AbstractWriteSearchIndexOperati private static final String COMMAND_NAME = "updateSearchIndex"; private final SearchIndexRequest request; - UpdateSearchIndexesOperation(final MongoNamespace namespace, final SearchIndexRequest request, - final WriteConcern writeConcern) { - super(namespace, writeConcern); + UpdateSearchIndexesOperation(final MongoNamespace namespace, final SearchIndexRequest request) { + super(namespace); this.request = request; } @Override BsonDocument buildCommand() { - BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) + return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) .append("name", new BsonString(request.getIndexName())) .append("definition", request.getDefinition()); - appendWriteConcernToCommand(getWriteConcern(), command); - return command; } } diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index 47a0c5f3d45..f3260854345 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -17,6 +17,7 @@ package com.mongodb.client; import com.mongodb.MongoClientSettings; +import com.mongodb.WriteConcern; import com.mongodb.client.model.SearchIndexModel; import org.bson.Document; import org.bson.conversions.Bson; @@ -75,7 +76,7 @@ public abstract class AbstractAtlasSearchIndexManagementProseTest { protected AbstractAtlasSearchIndexManagementProseTest() { Assumptions.assumeTrue(serverVersionAtLeast(6, 0)); - Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); //TODO enable by flag + Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); } private static boolean hasAtlasSearchIndexHelperEnabled() { @@ -84,7 +85,12 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { @BeforeEach public void setUp() { - client = createMongoClient(getMongoClientSettings()); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder(getMongoClientSettings()) + /* Specifying the write concern here ensures that we test the use case where the write concern + is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */ + .writeConcern(WriteConcern.MAJORITY).build(); + + client = createMongoClient(mongoClientSettings); db = client.getDatabase("test"); String collectionName = UUID.randomUUID().toString(); From 9c90ceeecfaebf52cf2cb1c30c3691230d0227ee Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Thu, 2 Nov 2023 11:52:30 -0700 Subject: [PATCH 2/9] Use method helper. JAVA-5233 --- .../client/AbstractAtlasSearchIndexManagementProseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index f3260854345..f88e8aa5480 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -40,6 +40,7 @@ import static com.mongodb.ClusterFixture.serverVersionAtLeast; import static com.mongodb.client.Fixture.getMongoClientSettings; +import static com.mongodb.client.Fixture.getMongoClientSettingsBuilder; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -85,7 +86,7 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { @BeforeEach public void setUp() { - MongoClientSettings mongoClientSettings = MongoClientSettings.builder(getMongoClientSettings()) + MongoClientSettings mongoClientSettings = getMongoClientSettingsBuilder() /* Specifying the write concern here ensures that we test the use case where the write concern is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */ .writeConcern(WriteConcern.MAJORITY).build(); From 60121d2fae1a8bf9c57d17b1a857258f7a2b3be2 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Thu, 2 Nov 2023 15:11:11 -0700 Subject: [PATCH 3/9] Add use-case for read-concern. JAVA-5233 --- .../AbstractAtlasSearchIndexManagementProseTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index f88e8aa5480..28010376f1e 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -17,6 +17,7 @@ package com.mongodb.client; import com.mongodb.MongoClientSettings; +import com.mongodb.ReadConcern; import com.mongodb.WriteConcern; import com.mongodb.client.model.SearchIndexModel; import org.bson.Document; @@ -87,9 +88,11 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { @BeforeEach public void setUp() { MongoClientSettings mongoClientSettings = getMongoClientSettingsBuilder() - /* Specifying the write concern here ensures that we test the use case where the write concern + /* Specifying the write and read concerns here ensures that we test the use case where the write concern is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */ - .writeConcern(WriteConcern.MAJORITY).build(); + .writeConcern(WriteConcern.MAJORITY) + .readConcern(ReadConcern.MAJORITY) + .build(); client = createMongoClient(mongoClientSettings); db = client.getDatabase("test"); From cf50924eb54a73a7c267a22b2f7d7e81c390c4f7 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Thu, 2 Nov 2023 15:13:30 -0700 Subject: [PATCH 4/9] Change comment. JAVA-5233 --- .../client/AbstractAtlasSearchIndexManagementProseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index 28010376f1e..63bca1a08bc 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -88,7 +88,7 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { @BeforeEach public void setUp() { MongoClientSettings mongoClientSettings = getMongoClientSettingsBuilder() - /* Specifying the write and read concerns here ensures that we test the use case where the write concern + /* Specifying the write and read concerns here ensures that we test the use case where the write or read concern is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */ .writeConcern(WriteConcern.MAJORITY) .readConcern(ReadConcern.MAJORITY) From 7f0c6f14454ab1bd0c8ee8c19336e938f57fa180 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 6 Nov 2023 16:32:43 -0800 Subject: [PATCH 5/9] User default read concern in order to avoid including it in the Atlas Search Index commands. JAVA-5233 --- .../client/internal/MongoCollectionImpl.java | 4 ++- .../internal/MongoOperationPublisher.java | 11 ++++++++ .../ListSearchIndexesIterableImpl.java | 7 +++-- .../client/internal/MongoCollectionImpl.java | 2 +- ...ctAtlasSearchIndexManagementProseTest.java | 27 ++++++++++++++++--- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java index 953b45ac9ac..e7328d2ccd3 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java @@ -694,7 +694,9 @@ public ListSearchIndexesPublisher listSearchIndexes() { @Override public ListSearchIndexesPublisher listSearchIndexes(final Class resultClass) { notNull("resultClass", resultClass); - return new ListSearchIndexesPublisherImpl<>(mongoOperationPublisher.withDocumentClass(resultClass)); + + return new ListSearchIndexesPublisherImpl<>(mongoOperationPublisher + .withReadConcernAndDocumentClass(ReadConcern.DEFAULT, resultClass)); } @Override diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java index 966dcc8c64f..04fb6f619a3 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java @@ -77,6 +77,7 @@ import java.util.function.Function; import java.util.function.Supplier; +import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.assertions.Assertions.notNull; import static java.util.Collections.singletonList; import static org.bson.codecs.configuration.CodecRegistries.withUuidRepresentation; @@ -169,6 +170,16 @@ MongoOperationPublisher withDocumentClass(final Class documentClass) { return withNamespaceAndDocumentClass(getNamespace(), documentClass); } + MongoOperationPublisher withReadConcernAndDocumentClass(final ReadConcern readConcern, final Class documentClass) { + if (getReadConcern().equals(readConcern) && getDocumentClass().equals(documentClass)) { + return (MongoOperationPublisher) this; + } + return new MongoOperationPublisher<>(getNamespace(), assertNotNull(documentClass), + getCodecRegistry(), getReadPreference(), assertNotNull(readConcern), + getWriteConcern(), getRetryWrites(), getRetryReads(), uuidRepresentation, + autoEncryptionSettings, executor); + } + @SuppressWarnings("unchecked") MongoOperationPublisher withNamespaceAndDocumentClass(final MongoNamespace namespace, final Class documentClass) { if (getNamespace().equals(namespace) && getDocumentClass().equals(documentClass)) { diff --git a/driver-sync/src/main/com/mongodb/client/internal/ListSearchIndexesIterableImpl.java b/driver-sync/src/main/com/mongodb/client/internal/ListSearchIndexesIterableImpl.java index fc949859530..0ffc9cea7a5 100644 --- a/driver-sync/src/main/com/mongodb/client/internal/ListSearchIndexesIterableImpl.java +++ b/driver-sync/src/main/com/mongodb/client/internal/ListSearchIndexesIterableImpl.java @@ -53,10 +53,9 @@ final class ListSearchIndexesIterableImpl extends MongoIterableImpl resultClass, - final CodecRegistry codecRegistry, final ReadPreference readPreference, - final boolean retryReads) { - super(null, executor, readConcern, readPreference, retryReads); + final Class resultClass, final CodecRegistry codecRegistry, + final ReadPreference readPreference, final boolean retryReads) { + super(null, executor, ReadConcern.DEFAULT, readPreference, retryReads); this.resultClass = resultClass; this.operations = new SyncOperations<>(namespace, BsonDocument.class, readPreference, codecRegistry, retryReads); diff --git a/driver-sync/src/main/com/mongodb/client/internal/MongoCollectionImpl.java b/driver-sync/src/main/com/mongodb/client/internal/MongoCollectionImpl.java index 98ed5ec334f..2d9e6cf42e8 100755 --- a/driver-sync/src/main/com/mongodb/client/internal/MongoCollectionImpl.java +++ b/driver-sync/src/main/com/mongodb/client/internal/MongoCollectionImpl.java @@ -947,7 +947,7 @@ private ListIndexesIterable createListIndexesIterable(@Nullab } private ListSearchIndexesIterable createListSearchIndexesIterable(final Class resultClass) { - return new ListSearchIndexesIterableImpl<>(getNamespace(), executor, readConcern, + return new ListSearchIndexesIterableImpl<>(getNamespace(), executor, resultClass, codecRegistry, readPreference, retryReads); } diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index 63bca1a08bc..c7fd6086b34 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -20,6 +20,9 @@ import com.mongodb.ReadConcern; import com.mongodb.WriteConcern; import com.mongodb.client.model.SearchIndexModel; +import com.mongodb.event.CommandListener; +import com.mongodb.event.CommandStartedEvent; +import org.bson.BsonDocument; import org.bson.Document; import org.bson.conversions.Bson; import org.junit.jupiter.api.AfterEach; @@ -40,6 +43,7 @@ import java.util.stream.StreamSupport; import static com.mongodb.ClusterFixture.serverVersionAtLeast; +import static com.mongodb.assertions.Assertions.assertFalse; import static com.mongodb.client.Fixture.getMongoClientSettings; import static com.mongodb.client.Fixture.getMongoClientSettingsBuilder; import static org.hamcrest.MatcherAssert.assertThat; @@ -88,10 +92,25 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { @BeforeEach public void setUp() { MongoClientSettings mongoClientSettings = getMongoClientSettingsBuilder() - /* Specifying the write and read concerns here ensures that we test the use case where the write or read concern - is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */ .writeConcern(WriteConcern.MAJORITY) .readConcern(ReadConcern.MAJORITY) + .addCommandListener(new CommandListener() { + @Override + public void commandStarted(final CommandStartedEvent event) { + /* This tests the use case where the write or read concern + is not passed down to the server for any of Atlas Index Search commands. + If a write concern is attached to the command, the server will fail with an error. */ + if (!isCollectionCreationCommand(event)) { + BsonDocument command = event.getCommand(); + assertFalse(command.containsKey("writeConcern")); + assertFalse(command.containsKey("readConcern")); + } + } + + private boolean isCollectionCreationCommand(final CommandStartedEvent event) { + return "create".equals(event.getCommandName()); + } + }) .build(); client = createMongoClient(mongoClientSettings); @@ -119,10 +138,10 @@ public void shouldCreateAndListSearchIndexes() throws InterruptedException { SearchIndexModel searchIndexModel = new SearchIndexModel(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //when - String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); + // String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //then - Assertions.assertEquals(TEST_SEARCH_INDEX_NAME_1, createdSearchIndexName); + //Assertions.assertEquals(TEST_SEARCH_INDEX_NAME_1, createdSearchIndexName); assertIndexesChanges(isQueryable(), searchIndexModel); } From 1df77edd84e187c29f34f17e574f7228e63e101f Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 6 Nov 2023 16:37:56 -0800 Subject: [PATCH 6/9] Uncomment code. JAVA-5233 --- .../client/AbstractAtlasSearchIndexManagementProseTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index c7fd6086b34..b42014c13f3 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -138,10 +138,10 @@ public void shouldCreateAndListSearchIndexes() throws InterruptedException { SearchIndexModel searchIndexModel = new SearchIndexModel(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //when - // String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); + String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //then - //Assertions.assertEquals(TEST_SEARCH_INDEX_NAME_1, createdSearchIndexName); + Assertions.assertEquals(TEST_SEARCH_INDEX_NAME_1, createdSearchIndexName); assertIndexesChanges(isQueryable(), searchIndexModel); } From d3eebfeadd9f7a3a6881d7aaf227cf3b97e17a45 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 6 Nov 2023 17:21:52 -0800 Subject: [PATCH 7/9] Change test. JAVA-5233 --- ...actAtlasSearchIndexManagementProseTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index b42014c13f3..fd7bc428576 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -81,8 +81,8 @@ public abstract class AbstractAtlasSearchIndexManagementProseTest { protected abstract MongoClient createMongoClient(MongoClientSettings settings); protected AbstractAtlasSearchIndexManagementProseTest() { - Assumptions.assumeTrue(serverVersionAtLeast(6, 0)); - Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); + Assumptions.assumeTrue(serverVersionAtLeast(6, 0)); + Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); } private static boolean hasAtlasSearchIndexHelperEnabled() { @@ -97,18 +97,18 @@ public void setUp() { .addCommandListener(new CommandListener() { @Override public void commandStarted(final CommandStartedEvent event) { - /* This tests the use case where the write or read concern - is not passed down to the server for any of Atlas Index Search commands. - If a write concern is attached to the command, the server will fail with an error. */ - if (!isCollectionCreationCommand(event)) { + /* This test case examines scenarios where the write or read concern is not forwarded to the server + for any Atlas Index Search commands. If a write or read concern is included in the command, + the server will return an error. */ + if (isSearchIndexCommand(event)) { BsonDocument command = event.getCommand(); assertFalse(command.containsKey("writeConcern")); assertFalse(command.containsKey("readConcern")); } } - private boolean isCollectionCreationCommand(final CommandStartedEvent event) { - return "create".equals(event.getCommandName()); + private boolean isSearchIndexCommand(final CommandStartedEvent event) { + return event.getCommand().toJson().contains("SearchIndex"); } }) .build(); @@ -138,7 +138,7 @@ public void shouldCreateAndListSearchIndexes() throws InterruptedException { SearchIndexModel searchIndexModel = new SearchIndexModel(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //when - String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); + String createdSearchIndexName = collection.createSearchIndex(TEST_SEARCH_INDEX_NAME_1, NOT_DYNAMIC_MAPPING_DEFINITION); //then Assertions.assertEquals(TEST_SEARCH_INDEX_NAME_1, createdSearchIndexName); From f0d69a94c7cb18c581fe539326d8292357ffb16a Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 7 Nov 2023 09:03:51 -0800 Subject: [PATCH 8/9] Remove unnecessary method. JAVA-5233 --- .../client/internal/MongoCollectionImpl.java | 3 ++- .../client/internal/MongoOperationPublisher.java | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java index e7328d2ccd3..d9fa18c6a54 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoCollectionImpl.java @@ -696,7 +696,8 @@ public ListSearchIndexesPublisher listSearchIndexes(final Cla notNull("resultClass", resultClass); return new ListSearchIndexesPublisherImpl<>(mongoOperationPublisher - .withReadConcernAndDocumentClass(ReadConcern.DEFAULT, resultClass)); + .withReadConcern(ReadConcern.DEFAULT) + .withDocumentClass(resultClass)); } @Override diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java index 04fb6f619a3..558833c432d 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java @@ -170,16 +170,6 @@ MongoOperationPublisher withDocumentClass(final Class documentClass) { return withNamespaceAndDocumentClass(getNamespace(), documentClass); } - MongoOperationPublisher withReadConcernAndDocumentClass(final ReadConcern readConcern, final Class documentClass) { - if (getReadConcern().equals(readConcern) && getDocumentClass().equals(documentClass)) { - return (MongoOperationPublisher) this; - } - return new MongoOperationPublisher<>(getNamespace(), assertNotNull(documentClass), - getCodecRegistry(), getReadPreference(), assertNotNull(readConcern), - getWriteConcern(), getRetryWrites(), getRetryReads(), uuidRepresentation, - autoEncryptionSettings, executor); - } - @SuppressWarnings("unchecked") MongoOperationPublisher withNamespaceAndDocumentClass(final MongoNamespace namespace, final Class documentClass) { if (getNamespace().equals(namespace) && getDocumentClass().equals(documentClass)) { From 39f9e6732b33b57ed2eeee734accbe4e4a3f98ca Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 7 Nov 2023 09:28:27 -0800 Subject: [PATCH 9/9] Static check fix. JAVA-5233 --- .../reactivestreams/client/internal/MongoOperationPublisher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java index 558833c432d..966dcc8c64f 100644 --- a/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java +++ b/driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/MongoOperationPublisher.java @@ -77,7 +77,6 @@ import java.util.function.Function; import java.util.function.Supplier; -import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.assertions.Assertions.notNull; import static java.util.Collections.singletonList; import static org.bson.codecs.configuration.CodecRegistries.withUuidRepresentation;