@@ -37,6 +37,7 @@ import spock.lang.Shared
3737
3838import static com.mongodb.ClusterFixture.getPrimary
3939import static com.mongodb.ClusterFixture.getSslSettings
40+ import static com.mongodb.bulk.WriteRequest.Type.REPLACE
4041import static com.mongodb.bulk.WriteRequest.Type.UPDATE
4142import static com.mongodb.connection.ConnectionFixture.getCredentialListWithCache
4243import static com.mongodb.internal.connection.ProtocolTestHelper.execute
@@ -131,6 +132,42 @@ class WriteProtocolCommandEventSpecification extends OperationFunctionalSpecific
131132 async << [false , true ]
132133 }
133134
135+ def ' should deliver started and completed command events for a replace' () {
136+ given :
137+ def filter = new BsonDocument (' _id' , new BsonInt32 (1 ))
138+ def update = new BsonDocument (' x' , new BsonInt32 (1 ))
139+ def updateRequest = new UpdateRequest (filter, update, REPLACE ). multi(false ). upsert(true )
140+ def protocol = new UpdateProtocol (getNamespace(), true , updateRequest)
141+ def commandListener = new TestCommandListener ()
142+ protocol. commandListener = commandListener
143+
144+ when :
145+ execute(protocol, connection, async)
146+
147+ then :
148+ commandListener. eventsWereDelivered([new CommandStartedEvent (1 , connection. getDescription(), getDatabaseName(), ' update' ,
149+ new BsonDocument (' update' , new BsonString (getCollectionName()))
150+ .append(' ordered' , BsonBoolean . TRUE )
151+ .append(' writeConcern' ,
152+ new BsonDocument (' w' , new BsonInt32 (0 )))
153+ .append(' updates' , new BsonArray (
154+ [new BsonDocument (' q' , filter)
155+ .append(' u' , update)
156+ .append(' upsert' , BsonBoolean . TRUE )]))),
157+ new CommandSucceededEvent (1 , connection. getDescription(), ' update' ,
158+ new BsonDocument (' ok' , new BsonInt32 (1 )), 0 )])
159+
160+ cleanup :
161+ // force acknowledgement
162+ new CommandProtocolImpl (getDatabaseName(), new BsonDocument (' drop' , new BsonString (getCollectionName())),
163+ NO_OP_FIELD_NAME_VALIDATOR , ReadPreference . primary(), new BsonDocumentCodec ())
164+ .sessionContext(NoOpSessionContext . INSTANCE )
165+ .execute(connection)
166+
167+ where :
168+ async << [false , true ]
169+ }
170+
134171 def ' should deliver started and completed command events for a delete' () {
135172 given :
136173 def filter = new BsonDocument (' _id' , new BsonInt32 (1 ))
0 commit comments