@@ -35,12 +35,14 @@ import com.mongodb.internal.connection.Connection
35
35
import com.mongodb.internal.session.SessionContext
36
36
import org.bson.BsonBoolean
37
37
import org.bson.BsonDocument
38
+ import org.bson.BsonDouble
38
39
import org.bson.BsonInt32
39
40
import org.bson.BsonInt64
40
41
import org.bson.BsonJavaScript
41
42
import org.bson.BsonString
42
43
import org.bson.BsonTimestamp
43
44
import org.bson.Document
45
+ import org.bson.codecs.BsonDocumentCodec
44
46
import org.bson.codecs.DocumentCodec
45
47
import spock.lang.IgnoreIf
46
48
@@ -51,18 +53,18 @@ import static com.mongodb.internal.operation.OperationReadConcernHelper.appendRe
51
53
import static java.util.concurrent.TimeUnit.MILLISECONDS
52
54
53
55
class MapReduceWithInlineResultsOperationSpecification extends OperationFunctionalSpecification {
54
- private final documentCodec = new DocumentCodec ()
55
- def mapReduceOperation = new MapReduceWithInlineResultsOperation<Document > (
56
+ private final bsonDocumentCodec = new BsonDocumentCodec ()
57
+ def mapReduceOperation = new MapReduceWithInlineResultsOperation<BsonDocument > (
56
58
getNamespace(),
57
59
new BsonJavaScript (' function(){ emit( this.name , 1 ); }' ),
58
60
new BsonJavaScript (' function(key, values){ return values.length; }' ),
59
- documentCodec )
61
+ bsonDocumentCodec )
60
62
61
- def expectedResults = [[ ' _id' : ' Pete' , ' value' : 2.0 ] as Document ,
62
- [ ' _id' : ' Sam' , ' value' : 1.0 ] as Document ]
63
+ def expectedResults = [new BsonDocument ( ' _id' , new BsonString ( ' Pete' )) . append( ' value' , new BsonDouble ( 2.0 )) ,
64
+ new BsonDocument ( ' _id' , new BsonString ( ' Sam' )) . append( ' value' , new BsonDouble ( 1.0 )) ] as Set
63
65
64
66
def setup () {
65
- CollectionHelper<Document > helper = new CollectionHelper<Document > (documentCodec , getNamespace())
67
+ CollectionHelper<BsonDocument > helper = new CollectionHelper<BsonDocument > (bsonDocumentCodec , getNamespace())
66
68
Document pete = new Document (' name' , ' Pete' ). append(' job' , ' handyman' )
67
69
Document sam = new Document (' name' , ' Sam' ). append(' job' , ' plumber' )
68
70
Document pete2 = new Document (' name' , ' Pete' ). append(' job' , ' electrician' )
@@ -73,7 +75,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
73
75
when :
74
76
def mapF = new BsonJavaScript (' function(){ }' )
75
77
def reduceF = new BsonJavaScript (' function(key, values){ }' )
76
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, mapF, reduceF, documentCodec )
78
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, mapF, reduceF, bsonDocumentCodec )
77
79
78
80
then :
79
81
operation. getMapFunction() == mapF
@@ -97,7 +99,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
97
99
def finalizeF = new BsonJavaScript (' function(key, value){}' )
98
100
def mapF = new BsonJavaScript (' function(){ }' )
99
101
def reduceF = new BsonJavaScript (' function(key, values){ }' )
100
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, mapF, reduceF, documentCodec )
102
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, mapF, reduceF, bsonDocumentCodec )
101
103
.filter(filter)
102
104
.finalizeFunction(finalizeF)
103
105
.scope(scope)
@@ -127,7 +129,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
127
129
def operation = mapReduceOperation
128
130
129
131
when :
130
- def results = executeAndCollectBatchCursorResults(operation, async)
132
+ def results = executeAndCollectBatchCursorResults(operation, async) as Set
131
133
132
134
then :
133
135
results == expectedResults
@@ -139,7 +141,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
139
141
def ' should use the ReadBindings readPreference to set slaveOK' () {
140
142
when :
141
143
def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
142
- new BsonJavaScript (' function(key, values){ }' ), documentCodec )
144
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec )
143
145
144
146
then :
145
147
testOperationSlaveOk(operation, [3 , 4 , 0 ], readPreference, async, helper. commandResult)
@@ -151,7 +153,7 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
151
153
def ' should create the expected command' () {
152
154
when :
153
155
def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
154
- new BsonJavaScript (' function(key, values){ }' ), documentCodec )
156
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec )
155
157
def expectedCommand = new BsonDocument (' mapreduce' , new BsonString (helper. namespace. getCollectionName()))
156
158
.append(' map' , operation. getMapFunction())
157
159
.append(' reduce' , operation. getReduceFunction())
@@ -198,8 +200,8 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
198
200
199
201
def ' should throw an exception when using an unsupported ReadConcern' () {
200
202
given :
201
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
202
- new BsonJavaScript (' function(key, values){ }' ), documentCodec )
203
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, new BsonJavaScript (' function(){ }' ),
204
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec )
203
205
204
206
when :
205
207
testOperationThrows(operation, [3 , 0 , 0 ], readConcern, async)
@@ -214,8 +216,8 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
214
216
215
217
def ' should throw an exception when using an unsupported Collation' () {
216
218
given :
217
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
218
- new BsonJavaScript (' function(key, values){ }' ), documentCodec ). collation(defaultCollation)
219
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, new BsonJavaScript (' function(){ }' ),
220
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec ). collation(defaultCollation)
219
221
220
222
when :
221
223
testOperationThrows(operation, [3 , 2 , 0 ], async)
@@ -233,16 +235,16 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
233
235
given :
234
236
def document = Document . parse(' {_id: 1, str: "foo"}' )
235
237
getCollectionHelper(). insertDocuments(document)
236
- def operation = new MapReduceWithInlineResultsOperation<Document > (
238
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (
237
239
namespace,
238
240
new BsonJavaScript (' function(){ emit( this._id, this.str ); }' ),
239
241
new BsonJavaScript (' function(key, values){ return key, values; }' ),
240
- documentCodec )
242
+ bsonDocumentCodec )
241
243
.filter(BsonDocument . parse(' {str: "FOO"}' ))
242
244
.collation(caseInsensitiveCollation)
243
245
244
246
when :
245
- def results = executeAndCollectBatchCursorResults(operation, async)
247
+ def results = executeAndCollectBatchCursorResults(operation, async) as Set
246
248
247
249
then :
248
250
results == [Document . parse(' {_id: 1.0, value: "foo"}' )]
@@ -269,8 +271,8 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
269
271
}''' )
270
272
appendReadConcernToCommand(sessionContext, commandDocument)
271
273
272
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
273
- new BsonJavaScript (' function(key, values){ }' ), documentCodec )
274
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, new BsonJavaScript (' function(){ }' ),
275
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec )
274
276
275
277
when :
276
278
operation. execute(binding)
@@ -316,8 +318,8 @@ class MapReduceWithInlineResultsOperationSpecification extends OperationFunction
316
318
}''' )
317
319
appendReadConcernToCommand(sessionContext, commandDocument)
318
320
319
- def operation = new MapReduceWithInlineResultsOperation<Document > (helper. namespace, new BsonJavaScript (' function(){ }' ),
320
- new BsonJavaScript (' function(key, values){ }' ), documentCodec )
321
+ def operation = new MapReduceWithInlineResultsOperation<BsonDocument > (helper. namespace, new BsonJavaScript (' function(){ }' ),
322
+ new BsonJavaScript (' function(key, values){ }' ), bsonDocumentCodec )
321
323
322
324
when :
323
325
executeAsync(operation, binding)
0 commit comments