@@ -38,6 +38,7 @@ import static com.mongodb.ClusterFixture.getPrimary
3838import static com.mongodb.ClusterFixture.getSslSettings
3939import static com.mongodb.ClusterFixture.serverVersionAtLeast
4040import static com.mongodb.WriteConcern.ACKNOWLEDGED
41+ import static com.mongodb.connection.ProtocolTestHelper.execute
4142
4243@IgnoreIf ({ !serverVersionAtLeast([2 , 6 , 0 ]) })
4344class WriteCommandProtocolSpecification extends OperationFunctionalSpecification {
@@ -47,7 +48,7 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
4748
4849 def setupSpec () {
4950 connection = new InternalStreamConnectionFactory (new NettyStreamFactory (SocketSettings . builder(). build(), getSslSettings()),
50- getCredentialList(), new NoOpConnectionListener ())
51+ getCredentialList(), new NoOpConnectionListener ())
5152 .create(new ServerId (new ClusterId (), getPrimary()))
5253 connection. open();
5354 }
@@ -62,13 +63,17 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
6263
6364 def insertRequest = [new InsertRequest (document)]
6465 def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertRequest)
66+
6567 when :
66- def result = protocol . execute(connection)
68+ def result = execute(protocol, connection, async )
6769
6870 then :
6971 result. insertedCount == 1
7072 result. upserts == []
7173 collectionHelper. find(document, new BsonDocumentCodec ()). first() == document
74+
75+ where :
76+ async << [false , true ]
7277 }
7378
7479 def ' should insert documents' () {
@@ -78,22 +83,25 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
7883 def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , requests)
7984
8085 when :
81- protocol . execute(connection)
86+ execute(protocol, connection, async )
8287
8388 then :
8489 collectionHelper. count() == 2
90+
91+ where :
92+ async << [false , true ]
8593 }
8694
8795 def ' should throw exception' () {
8896 given :
8997 def protocol = new InsertCommandProtocol (getNamespace(), false , ACKNOWLEDGED , false ,
90- [new InsertRequest (new BsonDocument (' _id' , new BsonInt32 (1 ))),
91- new InsertRequest (new BsonDocument (' _id' , new BsonInt32 (2 )))]
98+ [new InsertRequest (new BsonDocument (' _id' , new BsonInt32 (1 ))),
99+ new InsertRequest (new BsonDocument (' _id' , new BsonInt32 (2 )))]
92100 )
93101 protocol. execute(connection)
94102
95103 when :
96- protocol . execute(connection) // now do it again
104+ execute(protocol, connection, async)
97105
98106 then :
99107 def e = thrown(MongoBulkWriteException )
@@ -112,6 +120,9 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
112120 code == 11000
113121 message != null
114122 }
123+
124+ where :
125+ async << [false , true ]
115126 }
116127
117128 @Category (Slow )
@@ -133,11 +144,14 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
133144 def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertList)
134145
135146 when :
136- def result = protocol . execute(connection)
147+ def result = execute(protocol, connection, async )
137148
138149 then :
139150 result. insertedCount == 4
140151 documents. size() == collectionHelper. count()
152+
153+ where :
154+ async << [false , true ]
141155 }
142156
143157 @Category (Slow )
@@ -164,11 +178,14 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
164178 def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertList)
165179
166180 when :
167- protocol . execute(connection)
181+ execute(protocol, connection, async )
168182
169183 then :
170184 def exception = thrown(MongoBulkWriteException )
171185 exception. writeResult. insertedCount == 1
186+
187+ where :
188+ async << [false , true ]
172189 }
173190
174191 @Category (Slow )
@@ -198,7 +215,7 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
198215 def protocol = new InsertCommandProtocol (getNamespace(), false , ACKNOWLEDGED , null , insertList)
199216
200217 when :
201- protocol . execute(connection)
218+ execute(protocol, connection, async )
202219
203220 then :
204221 def e = thrown(MongoBulkWriteException )
@@ -207,26 +224,33 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
207224 e. writeErrors[0 ]. index == 0
208225 e. writeErrors[1 ]. index == 2
209226 e. writeErrors[2 ]. index == 3
227+
228+ where :
229+ async << [false , true ]
210230 }
211231
212232 def ' should upsert items' () {
213233 given :
214234 def protocol = new UpdateCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null ,
215- [new UpdateRequest (new BsonDocument (' _id' , new BsonInt32 (1 )),
216- new BsonDocument (' $set' , new BsonDocument (' x' , new BsonInt32 (1 ))),
217- WriteRequest.Type . UPDATE )
218- .upsert(true ),
219- new UpdateRequest (new BsonDocument (' _id' , new BsonInt32 (2 )),
220- new BsonDocument (' $set' , new BsonDocument (' x' , new BsonInt32 (2 ))),
221- WriteRequest.Type . UPDATE )
222- .upsert(true )]
235+ [new UpdateRequest (new BsonDocument (' _id' , new BsonInt32 (1 )),
236+ new BsonDocument (' $set' , new BsonDocument (' x' , new BsonInt32 (1 ))),
237+ WriteRequest.Type . UPDATE )
238+ .upsert(true ),
239+ new UpdateRequest (new BsonDocument (' _id' , new BsonInt32 (2 )),
240+ new BsonDocument (' $set' , new BsonDocument (' x' , new BsonInt32 (2 ))),
241+ WriteRequest.Type . UPDATE )
242+ .upsert(true )]
223243 );
224244
225245 when :
226- def result = protocol. execute(connection);
246+ def result = execute(protocol, connection, async)
247+
227248
228249 then :
229250 result. matchedCount == 0 ;
230251 result. upserts == [new BulkWriteUpsert (0 , new BsonInt32 (1 )), new BulkWriteUpsert (1 , new BsonInt32 (2 ))]
252+
253+ where :
254+ async << [false , true ]
231255 }
232256}
0 commit comments