Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public void executeAsync(final AsyncWriteBinding binding, final SingleResultCall
writeConcernErrorTransformerAsync(binding.getOperationContext().getTimeoutContext()), (result, commandExecutionError) -> {
try {
swallowOrThrow(commandExecutionError);
callback.onResult(result, null);
cb.onResult(result, null);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This the reason for the unreleased connection - it used the original and not decorated callback that handles the releasing.

The rest of the PR is updating the test suite to ensure there are no future regressions. The core is the SyncMongoClient close method that now has a listener that counts the connections out and in. It also asserts that all connections are released.

} catch (Throwable mongoCommandException) {
callback.onResult(null, mongoCommandException);
cb.onResult(null, mongoCommandException);
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ static <R, T extends ReferenceCounted> void withAsyncSuppliedResource(final Asyn
AsyncCallbackSupplier<R> curriedFunction = c -> function.apply(resource, c);
curriedFunction.whenComplete(resource::release).get(errorHandlingCallback);
} catch (Exception e) {
if (resource.getCount() > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This more closely mirrors the SyncOperationHelper and will ensure any errors thrown outside of the callback also release the resource.

resource.release();
}
errorHandlingCallback.onResult(null, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OidcAuthenticationAsyncProseTests extends OidcAuthenticationProseTe

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
class ClientMetadataProseTest extends AbstractClientMetadataProseTest {

protected MongoClient createMongoClient(@Nullable final MongoDriverInformation mongoDriverInformation, final MongoClientSettings mongoClientSettings) {
return new SyncMongoClient(MongoClients.create(mongoClientSettings, mongoDriverInformation));
return new SyncMongoClient(mongoClientSettings, mongoDriverInformation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void testAsyncTransportSettings() {
.transportSettings(asyncTransportSettings)
.build();

try (MongoClient client = new SyncMongoClient(MongoClients.create(mongoClientSettings))) {
try (MongoClient client = new SyncMongoClient(mongoClientSettings)) {
client.listDatabases().first();
}
verify(executorService, atLeastOnce()).execute(any());
Expand All @@ -67,7 +67,7 @@ void testExternalExecutorWasShutDown(final boolean tlsEnabled) throws Interrupte
.transportSettings(asyncTransportSettings)
.build();

try (MongoClient ignored = new SyncMongoClient(MongoClients.create(mongoClientSettings))) {
try (MongoClient ignored = new SyncMongoClient(mongoClientSettings)) {
// ignored
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
*/
public class AtlasSearchIndexManagementProseTest extends AbstractAtlasSearchIndexManagementProseTest {
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setUp() {

// Step 1: create unencrypted client
commandListener = new TestCommandListener();
client = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().addCommandListener(commandListener).build()));
client = new SyncMongoClient(getMongoClientSettingsBuilder().addCommandListener(commandListener));
client.getDatabase("keyvault").getCollection("datakeys").drop();
client.getDatabase("db").getCollection("coll").drop();

Expand Down Expand Up @@ -114,12 +114,11 @@ public void setUp() {
}};

String keyVaultNamespace = "keyvault.datakeys";
clientEncrypted = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder()
clientEncrypted = new SyncMongoClient(getMongoClientSettingsBuilder()
.autoEncryptionSettings(AutoEncryptionSettings.builder()
.keyVaultNamespace(keyVaultNamespace)
.kmsProviders(kmsProviders)
.schemaMap(schemaMap)
.build())
.build()));

clientEncryption = ClientEncryptions.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClientEncryptionRewrapManyDataKeyProseTest extends AbstractClientEn

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class ClientEncryptionTextExplicitEncryptionTest extends AbstractClientEncryptionTextExplicitEncryptionTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClientSideEncryption25LookupProseTests extends com.mongodb.client.C

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
final class ClientSideEncryptionAutoDataKeysTest extends AbstractClientSideEncryptionAutoDataKeysTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected ClientEncryption createClientEncryption(final ClientEncryptionSettings

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
public class ClientSideEncryptionDeadlockTest extends AbstractClientSideEncryptionDeadlockTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class ClientSideEncryptionDecryptionEventsTest extends AbstractClientSideEncryptionDecryptionEventsTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
final class ClientSideEncryptionNotCreateMongocryptdClientTest extends AbstractClientSideEncryptionNotCreateMongocryptdClientTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
final class ClientSideEncryptionNotSpawnMongocryptdTest extends AbstractClientSideEncryptionNotSpawnMongocryptdTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ClientSideEncryptionRangeExplicitEncryptionTest extends AbstractClientSideEncryptionRangeExplicitEncryptionTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class ClientSideEncryptionUniqueIndexKeyAltNamesTest extends AbstractClientSideEncryptionUniqueIndexKeyAltNamesTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ClientSideExplicitEncryptionTest extends AbstractClientSideEncrypti

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ public final class ClientSideOperationTimeoutProseTest extends AbstractClientSid

@Override
protected com.mongodb.client.MongoClient createMongoClient(final MongoClientSettings mongoClientSettings) {
wrapped = createReactiveClient(mongoClientSettings);
return new SyncMongoClient(wrapped);
SyncMongoClient client = new SyncMongoClient(mongoClientSettings);
wrapped = client.getWrapped();
return client;
}

private static MongoClient createReactiveClient(final MongoClientSettings.Builder builder) {
return MongoClients.create(builder.build());
}

private static MongoClient createReactiveClient(final MongoClientSettings mongoClientSettings) {
return MongoClients.create(mongoClientSettings);
}

@Override
protected com.mongodb.client.gridfs.GridFSBucket createGridFsBucket(final com.mongodb.client.MongoDatabase mongoDatabase,
final String bucketName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
final class CrudProseTest extends com.mongodb.client.CrudProseTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings.Builder mongoClientSettingsBuilder) {
return new SyncMongoClient(MongoClients.create(mongoClientSettingsBuilder.build()));
return new SyncMongoClient(mongoClientSettingsBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
public class DnsConfigurationTest extends AbstractDnsConfigurationTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
public class ExplainTest extends AbstractExplainTest {
@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(
MongoClientSettings.builder(settings).contextProvider(CONTEXT_PROVIDER).build()
));
return new SyncMongoClient(MongoClientSettings.builder(settings).contextProvider(CONTEXT_PROVIDER));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected MongoDatabase getDatabase(final String databaseName) {

private com.mongodb.client.MongoClient createMongoClient() {
if (mongoClient == null) {
mongoClient = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().build()));
mongoClient = new SyncMongoClient(getMongoClientSettingsBuilder());
}
return mongoClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
public class MongoWriteConcernWithResponseExceptionTest {
@Test
public void doesNotLeak() throws InterruptedException {
com.mongodb.client.MongoWriteConcernWithResponseExceptionTest.doesNotLeak(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)));
com.mongodb.client.MongoWriteConcernWithResponseExceptionTest.doesNotLeak(SyncMongoClient::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ List<DynamicTest> testMongoIterableFirstPassesTheContext() {

private MongoClient getMongoClient() {
if (mongoClient == null) {
mongoClient = new SyncMongoClient(
MongoClients.create(getMongoClientSettingsBuilder()
.contextProvider(CONTEXT_PROVIDER)
.build()));
mongoClient = new SyncMongoClient(getMongoClientSettingsBuilder()
.contextProvider(CONTEXT_PROVIDER));
}
return mongoClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public ReactiveInitialDnsSeedlistDiscoveryTest(final String filename, final Stri

@Override
public MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class RetryableReadsProseTest {
@Test
void poolClearedExceptionMustBeRetryable() throws InterruptedException, ExecutionException, TimeoutException {
RetryableWritesProseTest.poolClearedExceptionMustBeRetryable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> mongoCollection.find(eq(0)).iterator().hasNext(), "find", false);
}

Expand All @@ -52,7 +52,7 @@ void poolClearedExceptionMustBeRetryable() throws InterruptedException, Executio
@Test
void retriesOnDifferentMongosWhenAvailable() {
RetryableWritesProseTest.retriesOnDifferentMongosWhenAvailable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> {
try (MongoCursor<Document> cursor = mongoCollection.find().iterator()) {
return cursor.hasNext();
Expand All @@ -68,7 +68,7 @@ void retriesOnDifferentMongosWhenAvailable() {
@Test
void retriesOnSameMongosWhenAnotherNotAvailable() {
RetryableWritesProseTest.retriesOnSameMongosWhenAnotherNotAvailable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> {
try (MongoCursor<Document> cursor = mongoCollection.find().iterator()) {
return cursor.hasNext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setUp() {
@Test
public void poolClearedExceptionMustBeRetryable() throws InterruptedException, ExecutionException, TimeoutException {
com.mongodb.client.RetryableWritesProseTest.poolClearedExceptionMustBeRetryable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);
}

Expand All @@ -58,7 +58,7 @@ public void poolClearedExceptionMustBeRetryable() throws InterruptedException, E
@Test
public void originalErrorMustBePropagatedIfNoWritesPerformed() throws InterruptedException {
com.mongodb.client.RetryableWritesProseTest.originalErrorMustBePropagatedIfNoWritesPerformed(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)));
SyncMongoClient::new);
}

/**
Expand All @@ -67,7 +67,7 @@ public void originalErrorMustBePropagatedIfNoWritesPerformed() throws Interrupte
@Test
public void retriesOnDifferentMongosWhenAvailable() {
com.mongodb.client.RetryableWritesProseTest.retriesOnDifferentMongosWhenAvailable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);
}

Expand All @@ -77,7 +77,7 @@ public void retriesOnDifferentMongosWhenAvailable() {
@Test
public void retriesOnSameMongosWhenAnotherNotAvailable() {
com.mongodb.client.RetryableWritesProseTest.retriesOnSameMongosWhenAnotherNotAvailable(
mongoClientSettings -> new SyncMongoClient(MongoClients.create(mongoClientSettings)),
SyncMongoClient::new,
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

final class ServerSelectionProseTest extends AbstractServerSelectionProseTest {
protected MongoClient createClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
public class SessionsProseTest extends AbstractSessionsProseTest {
@Override
protected MongoClient getMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
return new SyncMongoClient(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
public class X509AuthenticationTest extends AbstractX509AuthenticationTest {
@Override
protected com.mongodb.client.MongoClient createMongoClient(final MongoClientSettings mongoClientSettings) {
return new SyncMongoClient(MongoClients.create(mongoClientSettings));
return new SyncMongoClient(mongoClientSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public ClientEncryption createClientEncryption(final ClientEncryptionSettings.Bu

@Override
protected MongoClient createMongoClient(final MongoClientSettings.Builder builder) {
return new SyncMongoClient(com.mongodb.reactivestreams.client.MongoClients.create(builder.build()));
return new SyncMongoClient(builder);
}
}
Loading