Skip to content

Commit 4d90bec

Browse files
committed
Async: Ensure renameCollection options are passed to the operation.
JAVA-2779
1 parent 4c0a837 commit 4d90bec

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

driver-async/src/main/com/mongodb/async/client/MongoCollectionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ public void renameCollection(final MongoNamespace newCollectionNamespace, final
10871087
@Override
10881088
public void renameCollection(final MongoNamespace newCollectionNamespace, final RenameCollectionOptions options,
10891089
final SingleResultCallback<Void> callback) {
1090-
executeRenameCollection(null, newCollectionNamespace, new RenameCollectionOptions(), callback);
1090+
executeRenameCollection(null, newCollectionNamespace, options, callback);
10911091
}
10921092

10931093
@Override
@@ -1100,7 +1100,7 @@ public void renameCollection(final ClientSession clientSession, final MongoNames
11001100
public void renameCollection(final ClientSession clientSession, final MongoNamespace newCollectionNamespace,
11011101
final RenameCollectionOptions options, final SingleResultCallback<Void> callback) {
11021102
notNull("clientSession", clientSession);
1103-
executeRenameCollection(clientSession, newCollectionNamespace, new RenameCollectionOptions(), callback);
1103+
executeRenameCollection(clientSession, newCollectionNamespace, options, callback);
11041104
}
11051105

11061106
private void executeRenameCollection(final ClientSession clientSession, final MongoNamespace newCollectionNamespace,

driver-async/src/test/unit/com/mongodb/async/client/MongoCollectionSpecification.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import com.mongodb.client.model.IndexOptions
5454
import com.mongodb.client.model.InsertManyOptions
5555
import com.mongodb.client.model.InsertOneModel
5656
import com.mongodb.client.model.InsertOneOptions
57+
import com.mongodb.client.model.RenameCollectionOptions
5758
import com.mongodb.client.model.ReplaceOneModel
5859
import com.mongodb.client.model.UpdateManyModel
5960
import com.mongodb.client.model.UpdateOneModel
@@ -1298,10 +1299,11 @@ class MongoCollectionSpecification extends Specification {
12981299

12991300
def 'should use RenameCollectionOperation correctly'() {
13001301
given:
1301-
def executor = new TestOperationExecutor([null])
1302+
def executor = new TestOperationExecutor([null, null])
13021303
def collection = new MongoCollectionImpl(namespace, Document, codecRegistry, readPreference, ACKNOWLEDGED,
13031304
true, readConcern, executor)
13041305
def newNamespace = new MongoNamespace(namespace.getDatabaseName(), 'newName')
1306+
def renameCollectionOptions = new RenameCollectionOptions().dropTarget(dropTarget)
13051307
def expectedOperation = new RenameCollectionOperation(namespace, newNamespace, ACKNOWLEDGED)
13061308
def renameCollection = collection.&renameCollection
13071309

@@ -1313,8 +1315,16 @@ class MongoCollectionSpecification extends Specification {
13131315
expect operation, isTheSameAs(expectedOperation)
13141316
executor.getClientSession() == session
13151317

1318+
when:
1319+
execute(renameCollection, session, newNamespace, renameCollectionOptions)
1320+
operation = executor.getWriteOperation() as RenameCollectionOperation
1321+
1322+
then:
1323+
expect operation, isTheSameAs(expectedOperation.dropTarget(dropTarget))
1324+
executor.getClientSession() == session
1325+
13161326
where:
1317-
session << [null, Stub(ClientSession)]
1327+
[session, dropTarget] << [[null, Stub(ClientSession)], [true, false]].combinations()
13181328
}
13191329

13201330
def 'should not expect to mutate the document when inserting'() {

driver/src/test/unit/com/mongodb/MongoCollectionSpecification.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.mongodb.client.model.IndexOptions
3939
import com.mongodb.client.model.InsertManyOptions
4040
import com.mongodb.client.model.InsertOneModel
4141
import com.mongodb.client.model.InsertOneOptions
42+
import com.mongodb.client.model.RenameCollectionOptions
4243
import com.mongodb.client.model.ReplaceOneModel
4344
import com.mongodb.client.model.UpdateManyModel
4445
import com.mongodb.client.model.UpdateOneModel
@@ -1285,10 +1286,11 @@ class MongoCollectionSpecification extends Specification {
12851286

12861287
def 'should use RenameCollectionOperation correctly'() {
12871288
given:
1288-
def executor = new TestOperationExecutor([null])
1289+
def executor = new TestOperationExecutor([null, null])
12891290
def collection = new MongoCollectionImpl(namespace, Document, codecRegistry, readPreference, ACKNOWLEDGED,
12901291
true, readConcern, executor)
12911292
def newNamespace = new MongoNamespace(namespace.getDatabaseName(), 'newName')
1293+
def renameCollectionOptions = new RenameCollectionOptions().dropTarget(dropTarget)
12921294
def expectedOperation = new RenameCollectionOperation(namespace, newNamespace, ACKNOWLEDGED)
12931295
def renameCollection = collection.&renameCollection
12941296

@@ -1300,8 +1302,16 @@ class MongoCollectionSpecification extends Specification {
13001302
expect operation, isTheSameAs(expectedOperation)
13011303
executor.getClientSession() == session
13021304

1305+
when:
1306+
execute(renameCollection, session, newNamespace, renameCollectionOptions)
1307+
operation = executor.getWriteOperation() as RenameCollectionOperation
1308+
1309+
then:
1310+
expect operation, isTheSameAs(expectedOperation.dropTarget(dropTarget))
1311+
executor.getClientSession() == session
1312+
13031313
where:
1304-
session << [null, Stub(ClientSession)]
1314+
[session, dropTarget] << [[null, Stub(ClientSession)], [true, false]].combinations()
13051315
}
13061316

13071317
def 'should not expect to mutate the document when inserting'() {

0 commit comments

Comments
 (0)