diff --git a/driver-sync/src/test/functional/com/mongodb/client/ClientSideEncryptionExternalKeyVaultTest.java b/driver-sync/src/test/functional/com/mongodb/client/ClientSideEncryptionExternalKeyVaultTest.java index f4b6b336e96..da513bb2a9e 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/ClientSideEncryptionExternalKeyVaultTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/ClientSideEncryptionExternalKeyVaultTest.java @@ -20,9 +20,11 @@ import com.mongodb.ClientEncryptionSettings; import com.mongodb.MongoClientSettings; import com.mongodb.MongoCredential; +import com.mongodb.MongoNamespace; import com.mongodb.MongoSecurityException; import com.mongodb.WriteConcern; import com.mongodb.client.model.vault.EncryptOptions; +import com.mongodb.client.test.CollectionHelper; import com.mongodb.client.vault.ClientEncryption; import com.mongodb.client.vault.ClientEncryptions; import org.bson.BsonBinary; @@ -57,6 +59,7 @@ public class ClientSideEncryptionExternalKeyVaultTest { private MongoClient client, clientEncrypted; private ClientEncryption clientEncryption; private final boolean withExternalKeyVault; + private static final MongoNamespace NAMESPACE = new MongoNamespace("db", ClientSideEncryptionExternalKeyVaultTest.class.getName()); public ClientSideEncryptionExternalKeyVaultTest(final boolean withExternalKeyVault) { this.withExternalKeyVault = withExternalKeyVault; @@ -84,7 +87,7 @@ public void setUp() throws IOException, URISyntaxException { + "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk"); localMasterkey.put("key", localMasterkeyBytes); kmsProviders.put("local", localMasterkey); - schemaMap.put("db.coll", bsonDocumentFromPath("external-schema.json")); + schemaMap.put(NAMESPACE.getFullName(), bsonDocumentFromPath("external-schema.json")); AutoEncryptionSettings.Builder autoEncryptionSettingsBuilder = AutoEncryptionSettings.builder() .keyVaultNamespace("keyvault.datakeys") @@ -123,8 +126,8 @@ public void setUp() throws IOException, URISyntaxException { public void testExternal() { boolean authExceptionThrown = false; MongoCollection coll = clientEncrypted - .getDatabase("db") - .getCollection("coll", BsonDocument.class); + .getDatabase(NAMESPACE.getDatabaseName()) + .getCollection(NAMESPACE.getCollectionName(), BsonDocument.class); try { coll.insertOne(new BsonDocument().append("encrypted", new BsonString("test"))); } catch (MongoSecurityException mse) { @@ -169,5 +172,7 @@ public void after() { // ignore } } + + CollectionHelper.drop(NAMESPACE); } } diff --git a/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java index 7138cdfe67e..016887c33b7 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java @@ -34,6 +34,7 @@ import com.mongodb.client.model.bulk.ClientBulkWriteOptions; import com.mongodb.client.model.bulk.ClientBulkWriteResult; import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; +import com.mongodb.client.test.CollectionHelper; import com.mongodb.event.CommandStartedEvent; import com.mongodb.internal.connection.TestCommandListener; import org.bson.BsonArray; @@ -47,6 +48,7 @@ import org.bson.RawBsonDocument; import org.bson.codecs.configuration.CodecRegistry; import org.bson.codecs.pojo.PojoCodecProvider; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -96,7 +98,7 @@ * CRUD Prose Tests. */ public class CrudProseTest { - private static final MongoNamespace NAMESPACE = new MongoNamespace("db", "coll"); + private static final MongoNamespace NAMESPACE = new MongoNamespace("db", CrudProseTest.class.getName()); @DisplayName("1. WriteConcernError.details exposes writeConcernError.errInfo") @Test @@ -367,7 +369,8 @@ private void testBulkWriteSplitsWhenExceedingMaxMessageSizeBytesDueToNsInfo( Document helloResponse = droppedDatabase(client).runCommand(new Document("hello", 1)); int maxBsonObjectSize = helloResponse.getInteger("maxBsonObjectSize"); int maxMessageSizeBytes = helloResponse.getInteger("maxMessageSizeBytes"); - int opsBytes = maxMessageSizeBytes - 1122; + // By the spec test, we have to subtract only 1122, however, we have different collection name. + int opsBytes = maxMessageSizeBytes - 1118 - NAMESPACE.getCollectionName().length(); int numModels = opsBytes / maxBsonObjectSize; int remainderBytes = opsBytes % maxBsonObjectSize; List models = new ArrayList<>(nCopies( @@ -613,4 +616,9 @@ private static ClientBulkWriteResult runInTransaction(final ClientSession sessio throw throwable; } } + + @AfterAll + public static void cleanUp() { + CollectionHelper.drop(NAMESPACE); + } }