-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Reuse ConnectionSource to avoid extra server selection. #1813
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
Open
vbabanin
wants to merge
15
commits into
mongodb:main
Choose a base branch
from
vbabanin:JAVA-5974
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9bf8a1d
Reuse ConnectionSource to avoid extra server selection.
vbabanin c5ba7f5
Merge branch 'main' into JAVA-5974
vbabanin b125e5a
Retain wrapped ConnectionSource getReadConnectionSource.
vbabanin 835d556
Add comments for clarity.
vbabanin ccd52af
Update comment.
vbabanin 4d1da60
Merge branch 'main' into JAVA-5974
vbabanin b0e6100
Merge branch 'main' into JAVA-5974
vbabanin 830b009
Add integration tests.
vbabanin 50d0df3
Merge remote-tracking branch 'vbabanin/JAVA-5974' into JAVA-5974
vbabanin 8befb71
Remove unnecessary blank line in SyncOperationHelper.java
vbabanin 15152d4
Change comments.
vbabanin 467ae63
Change error message.
vbabanin 3a0e72e
Update driver-core/src/test/unit/com/mongodb/internal/operation/Chang…
rozza 0d2de36
Remove unused import for Mockito ArgumentMatchers.eq
rozza c7d1f8f
Merge branch 'main' into JAVA-5974
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ms/src/test/functional/com/mongodb/reactivestreams/client/ChangeStreamFunctionalTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2008-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.reactivestreams.client; | ||
|
|
||
| import com.mongodb.MongoClientSettings; | ||
| import com.mongodb.client.AbstractChangeSteamFunctionalTest; | ||
| import com.mongodb.client.MongoClient; | ||
| import com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient; | ||
|
|
||
| public class ChangeStreamFunctionalTest extends AbstractChangeSteamFunctionalTest { | ||
| @Override | ||
| protected MongoClient createMongoClient(final MongoClientSettings mongoClientSettings) { | ||
| return new SyncMongoClient(mongoClientSettings); | ||
| } | ||
| } |
105 changes: 105 additions & 0 deletions
105
driver-sync/src/test/functional/com/mongodb/client/AbstractChangeSteamFunctionalTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Copyright 2008-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.client; | ||
|
|
||
| import com.mongodb.ClusterFixture; | ||
| import com.mongodb.MongoClientSettings; | ||
| import com.mongodb.MongoNamespace; | ||
| import com.mongodb.client.model.changestream.ChangeStreamDocument; | ||
| import com.mongodb.client.test.CollectionHelper; | ||
| import org.bson.BsonDocument; | ||
| import org.bson.BsonTimestamp; | ||
| import org.bson.Document; | ||
| import org.bson.codecs.BsonDocumentCodec; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import static com.mongodb.client.Fixture.getDefaultDatabaseName; | ||
| import static java.lang.String.format; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| /** | ||
| * The {@link ChangeStreamProseTest}, which is defined only for sync driver, should be migrated to this class. | ||
| * Once this done, this class should be renamed to ChangeStreamProseTest. | ||
| */ | ||
| public abstract class AbstractChangeSteamFunctionalTest { | ||
|
|
||
| private static final String FAIL_COMMAND_NAME = "failCommand"; | ||
| private static final MongoNamespace NAMESPACE = new MongoNamespace(getDefaultDatabaseName(), "test"); | ||
| private final CollectionHelper<BsonDocument> collectionHelper = new CollectionHelper<>(new BsonDocumentCodec(), NAMESPACE); | ||
|
|
||
| protected abstract MongoClient createMongoClient(MongoClientSettings mongoClientSettings); | ||
|
|
||
| @Test | ||
| public void shouldDoOneServerSelectionForResumeAttempt() { | ||
|
Member
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. Seems to have failed a couple of times in the tests: |
||
| //given | ||
| assumeTrue(ClusterFixture.isDiscoverableReplicaSet()); | ||
| AtomicInteger serverSelectionCounter = new AtomicInteger(); | ||
| BsonTimestamp startTime = new BsonTimestamp((int) Instant.now().getEpochSecond(), 0); | ||
| try (MongoClient mongoClient = createMongoClient(Fixture.getMongoClientSettingsBuilder() | ||
| .applyToClusterSettings(builder -> builder.serverSelector(clusterDescription -> { | ||
| serverSelectionCounter.incrementAndGet(); | ||
| return clusterDescription.getServerDescriptions(); | ||
| })).build())) { | ||
|
|
||
| MongoCollection<Document> collection = mongoClient | ||
| .getDatabase(NAMESPACE.getDatabaseName()) | ||
| .getCollection(NAMESPACE.getCollectionName()); | ||
|
|
||
| collectionHelper.runAdminCommand("{" | ||
| + " configureFailPoint: \"" + FAIL_COMMAND_NAME + "\"," | ||
| + " mode: {" | ||
| + " times: 1" | ||
| + " }," | ||
| + " data: {" | ||
| + " failCommands: ['getMore']," | ||
| + " errorCode: 10107," | ||
| + " errorLabels: ['ResumableChangeStreamError']" | ||
| + " }" | ||
| + "}"); | ||
| // We insert document here, because async cursor performs aggregate and getMore right after we call cursor() | ||
| collection.insertOne(Document.parse("{ x: 1 }")); | ||
| serverSelectionCounter.set(0); | ||
|
|
||
| try (MongoChangeStreamCursor<ChangeStreamDocument<Document>> cursor = collection.watch() | ||
| .batchSize(0) | ||
| .startAtOperationTime(startTime) | ||
| .cursor()) { | ||
|
|
||
| //when | ||
| ChangeStreamDocument<Document> changeStreamDocument = cursor.next(); | ||
| //then | ||
| assertNotNull(changeStreamDocument); | ||
| int actualCountOfServerSelections = serverSelectionCounter.get(); | ||
| assertEquals(2, actualCountOfServerSelections, | ||
| format("Expected 2 server selections (initial aggregate command + resume attempt aggregate command), but there were %s", | ||
| actualCountOfServerSelections)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() throws InterruptedException { | ||
| ClusterFixture.disableFailPoint(FAIL_COMMAND_NAME); | ||
| collectionHelper.drop(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.