|
24 | 24 | import com.mongodb.MongoSecurityException;
|
25 | 25 | import com.mongodb.MongoSocketException;
|
26 | 26 | import com.mongodb.assertions.Assertions;
|
| 27 | +import com.mongodb.client.ClientSession; |
| 28 | +import com.mongodb.client.FindIterable; |
27 | 29 | import com.mongodb.client.Fixture;
|
28 | 30 | import com.mongodb.client.MongoClient;
|
29 | 31 | import com.mongodb.client.MongoClients;
|
| 32 | +import com.mongodb.client.MongoCollection; |
30 | 33 | import com.mongodb.client.TestListener;
|
31 | 34 | import com.mongodb.event.CommandListener;
|
32 | 35 | import com.mongodb.lang.Nullable;
|
@@ -334,12 +337,17 @@ public void test3p3UnexpectedErrorDoesNotClearCache() {
|
334 | 337 |
|
335 | 338 | @Test
|
336 | 339 | public void test4p1Reauthentication() {
|
| 340 | + testReauthentication(false); |
| 341 | + } |
| 342 | + |
| 343 | + private void testReauthentication(final boolean inSession) { |
337 | 344 | TestCallback callback = createCallback();
|
338 | 345 | MongoClientSettings clientSettings = createSettings(callback);
|
339 |
| - try (MongoClient mongoClient = createMongoClient(clientSettings)) { |
| 346 | + try (MongoClient mongoClient = createMongoClient(clientSettings); |
| 347 | + ClientSession session = inSession ? mongoClient.startSession() : null) { |
340 | 348 | failCommand(391, 1, "find");
|
341 | 349 | // #. Perform a find operation that succeeds.
|
342 |
| - performFind(mongoClient); |
| 350 | + performFind(mongoClient, session); |
343 | 351 | }
|
344 | 352 | assertEquals(2, callback.invocations.get());
|
345 | 353 | }
|
@@ -392,6 +400,11 @@ private static void performInsert(final MongoClient mongoClient) {
|
392 | 400 | .insertOne(Document.parse("{ x: 1 }"));
|
393 | 401 | }
|
394 | 402 |
|
| 403 | + @Test |
| 404 | + public void test4p5ReauthenticationInSession() { |
| 405 | + testReauthentication(true); |
| 406 | + } |
| 407 | + |
395 | 408 | @Test
|
396 | 409 | public void test5p1AzureSucceedsWithNoUsername() {
|
397 | 410 | assumeAzure();
|
@@ -914,12 +927,14 @@ private <T extends Throwable> void assertFindFails(
|
914 | 927 | }
|
915 | 928 | }
|
916 | 929 |
|
917 |
| - private void performFind(final MongoClient mongoClient) { |
918 |
| - mongoClient |
919 |
| - .getDatabase("test") |
920 |
| - .getCollection("test") |
921 |
| - .find() |
922 |
| - .first(); |
| 930 | + private static void performFind(final MongoClient mongoClient) { |
| 931 | + performFind(mongoClient, null); |
| 932 | + } |
| 933 | + |
| 934 | + private static void performFind(final MongoClient mongoClient, @Nullable final ClientSession session) { |
| 935 | + MongoCollection<Document> collection = mongoClient.getDatabase("test").getCollection("test"); |
| 936 | + FindIterable<Document> findIterable = session == null ? collection.find() : collection.find(session); |
| 937 | + findIterable.first(); |
923 | 938 | }
|
924 | 939 |
|
925 | 940 | protected void delayNextFind() {
|
|
0 commit comments