@@ -38,6 +38,7 @@ import static com.mongodb.ClusterFixture.getPrimary
38
38
import static com.mongodb.ClusterFixture.getSslSettings
39
39
import static com.mongodb.ClusterFixture.serverVersionAtLeast
40
40
import static com.mongodb.WriteConcern.ACKNOWLEDGED
41
+ import static com.mongodb.connection.ProtocolTestHelper.execute
41
42
42
43
@IgnoreIf ({ !serverVersionAtLeast([2 , 6 , 0 ]) })
43
44
class WriteCommandProtocolSpecification extends OperationFunctionalSpecification {
@@ -47,7 +48,7 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
47
48
48
49
def setupSpec () {
49
50
connection = new InternalStreamConnectionFactory (new NettyStreamFactory (SocketSettings . builder(). build(), getSslSettings()),
50
- getCredentialList(), new NoOpConnectionListener ())
51
+ getCredentialList(), new NoOpConnectionListener ())
51
52
.create(new ServerId (new ClusterId (), getPrimary()))
52
53
connection. open();
53
54
}
@@ -62,13 +63,17 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
62
63
63
64
def insertRequest = [new InsertRequest (document)]
64
65
def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertRequest)
66
+
65
67
when :
66
- def result = protocol . execute(connection)
68
+ def result = execute(protocol, connection, async )
67
69
68
70
then :
69
71
result. insertedCount == 1
70
72
result. upserts == []
71
73
collectionHelper. find(document, new BsonDocumentCodec ()). first() == document
74
+
75
+ where :
76
+ async << [false , true ]
72
77
}
73
78
74
79
def ' should insert documents' () {
@@ -78,22 +83,25 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
78
83
def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , requests)
79
84
80
85
when :
81
- protocol . execute(connection)
86
+ execute(protocol, connection, async )
82
87
83
88
then :
84
89
collectionHelper. count() == 2
90
+
91
+ where :
92
+ async << [false , true ]
85
93
}
86
94
87
95
def ' should throw exception' () {
88
96
given :
89
97
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 )))]
92
100
)
93
101
protocol. execute(connection)
94
102
95
103
when :
96
- protocol . execute(connection) // now do it again
104
+ execute(protocol, connection, async)
97
105
98
106
then :
99
107
def e = thrown(MongoBulkWriteException )
@@ -112,6 +120,9 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
112
120
code == 11000
113
121
message != null
114
122
}
123
+
124
+ where :
125
+ async << [false , true ]
115
126
}
116
127
117
128
@Category (Slow )
@@ -133,11 +144,14 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
133
144
def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertList)
134
145
135
146
when :
136
- def result = protocol . execute(connection)
147
+ def result = execute(protocol, connection, async )
137
148
138
149
then :
139
150
result. insertedCount == 4
140
151
documents. size() == collectionHelper. count()
152
+
153
+ where :
154
+ async << [false , true ]
141
155
}
142
156
143
157
@Category (Slow )
@@ -164,11 +178,14 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
164
178
def protocol = new InsertCommandProtocol (getNamespace(), true , ACKNOWLEDGED , null , insertList)
165
179
166
180
when :
167
- protocol . execute(connection)
181
+ execute(protocol, connection, async )
168
182
169
183
then :
170
184
def exception = thrown(MongoBulkWriteException )
171
185
exception. writeResult. insertedCount == 1
186
+
187
+ where :
188
+ async << [false , true ]
172
189
}
173
190
174
191
@Category (Slow )
@@ -198,7 +215,7 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
198
215
def protocol = new InsertCommandProtocol (getNamespace(), false , ACKNOWLEDGED , null , insertList)
199
216
200
217
when :
201
- protocol . execute(connection)
218
+ execute(protocol, connection, async )
202
219
203
220
then :
204
221
def e = thrown(MongoBulkWriteException )
@@ -207,26 +224,33 @@ class WriteCommandProtocolSpecification extends OperationFunctionalSpecification
207
224
e. writeErrors[0 ]. index == 0
208
225
e. writeErrors[1 ]. index == 2
209
226
e. writeErrors[2 ]. index == 3
227
+
228
+ where :
229
+ async << [false , true ]
210
230
}
211
231
212
232
def ' should upsert items' () {
213
233
given :
214
234
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 )]
223
243
);
224
244
225
245
when :
226
- def result = protocol. execute(connection);
246
+ def result = execute(protocol, connection, async)
247
+
227
248
228
249
then :
229
250
result. matchedCount == 0 ;
230
251
result. upserts == [new BulkWriteUpsert (0 , new BsonInt32 (1 )), new BulkWriteUpsert (1 , new BsonInt32 (2 ))]
252
+
253
+ where :
254
+ async << [false , true ]
231
255
}
232
256
}
0 commit comments