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