-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove write and read concern from Atlas Search Index commands. #1241
Changes from all commits
91c1ab9
9c90cee
60121d2
cf50924
7f0c6f1
1df77ed
d3eebfe
f0d69a9
39f9e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,12 @@ | |
package com.mongodb.client; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
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; | ||
|
@@ -38,7 +43,9 @@ | |
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; | ||
import static org.hamcrest.Matchers.contains; | ||
|
||
|
@@ -74,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"); //TODO enable by flag | ||
Assumptions.assumeTrue(serverVersionAtLeast(6, 0)); | ||
Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); | ||
} | ||
|
||
private static boolean hasAtlasSearchIndexHelperEnabled() { | ||
|
@@ -84,7 +91,29 @@ private static boolean hasAtlasSearchIndexHelperEnabled() { | |
|
||
@BeforeEach | ||
public void setUp() { | ||
client = createMongoClient(getMongoClientSettings()); | ||
MongoClientSettings mongoClientSettings = getMongoClientSettingsBuilder() | ||
.writeConcern(WriteConcern.MAJORITY) | ||
.readConcern(ReadConcern.MAJORITY) | ||
.addCommandListener(new CommandListener() { | ||
@Override | ||
public void commandStarted(final CommandStartedEvent 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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized that I had noticed this earlier and then neglected to comment on it: asserting like this in any event listener is likely a no-op since the driver (I think) swallows exceptions thrown by listeners and in any case it may throw on a different thread for reactive tests. You need to instead set some state in the listener and then assert on that state in the main test code. There are examples of this in many places in the driver. Since this PR is already merged, you'll have to address it in a follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is a good example of where writing a failing test first, TDD style, can catch errors in the test itself) |
||
assertFalse(command.containsKey("readConcern")); | ||
} | ||
} | ||
|
||
private boolean isSearchIndexCommand(final CommandStartedEvent event) { | ||
return event.getCommand().toJson().contains("SearchIndex"); | ||
} | ||
}) | ||
.build(); | ||
|
||
client = createMongoClient(mongoClientSettings); | ||
db = client.getDatabase("test"); | ||
|
||
String collectionName = UUID.randomUUID().toString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why, in driver-sync's MongoCollectionImpl, read concern seems to have been removed, while here it seems like we're adding it. Can you clarify the intent?