@@ -412,6 +412,58 @@ public void TestMixedUpsertsUnordered()
412
412
}
413
413
}
414
414
415
+ [ Test ]
416
+ [ TestCase ( false ) ]
417
+ [ TestCase ( true ) ]
418
+ public void TestNoJournal ( bool ordered )
419
+ {
420
+ using ( _server . RequestStart ( null , ReadPreference . Primary ) )
421
+ {
422
+ var serverInstance = _server . RequestConnection . ServerInstance ;
423
+ if ( serverInstance . InstanceType == MongoServerInstanceType . StandAlone )
424
+ {
425
+ _collection . Drop ( ) ;
426
+ var documents = new [ ]
427
+ {
428
+ new BsonDocument ( "x" , 1 )
429
+ } ;
430
+
431
+ var bulk = InitializeBulkOperation ( _collection , ordered ) ;
432
+ bulk . Insert ( documents [ 0 ] ) ;
433
+
434
+ var writeConcern = new WriteConcern { Journal = true } ;
435
+ if ( IsJournalEnabled ( serverInstance ) )
436
+ {
437
+ var result = bulk . Execute ( writeConcern ) ;
438
+ var expectedResult = new ExpectedResult { InsertedCount = 1 , RequestCount = 1 } ;
439
+ CheckExpectedResult ( expectedResult , result ) ;
440
+ Assert . That ( _collection . FindAll ( ) , Is . EquivalentTo ( documents ) ) ;
441
+ }
442
+ else
443
+ {
444
+ if ( serverInstance . Supports ( FeatureId . WriteCommands ) )
445
+ {
446
+ Assert . Throws < MongoCommandException > ( ( ) => { bulk . Execute ( writeConcern ) ; } ) ;
447
+ Assert . AreEqual ( 0 , _collection . Count ( ) ) ;
448
+ }
449
+ else
450
+ {
451
+ var exception = Assert . Throws < BulkWriteException > ( ( ) => { bulk . Execute ( writeConcern ) ; } ) ;
452
+ var result = exception . Result ;
453
+
454
+ var expectedResult = new ExpectedResult { InsertedCount = 1 , RequestCount = 1 } ;
455
+ CheckExpectedResult ( expectedResult , result ) ;
456
+ Assert . That ( _collection . FindAll ( ) , Is . EquivalentTo ( documents ) ) ;
457
+
458
+ Assert . AreEqual ( 0 , exception . UnprocessedRequests . Count ) ;
459
+ Assert . IsNotNull ( exception . WriteConcernError ) ;
460
+ Assert . AreEqual ( 0 , exception . WriteErrors . Count ) ;
461
+ }
462
+ }
463
+ }
464
+ }
465
+ }
466
+
415
467
[ Test ]
416
468
public void TestOrderedBatchWithErrors ( )
417
469
{
@@ -1185,6 +1237,35 @@ public void TestUpsertWithOneMatchingDocument(bool ordered)
1185
1237
}
1186
1238
}
1187
1239
1240
+ [ Test ]
1241
+ [ TestCase ( false ) ]
1242
+ [ TestCase ( true ) ]
1243
+ public void TestW0DoesNotReportErrors ( bool ordered )
1244
+ {
1245
+ using ( _server . RequestStart ( null , ReadPreference . Primary ) )
1246
+ {
1247
+ var serverInstance = _server . RequestConnection . ServerInstance ;
1248
+
1249
+ var documents = new [ ]
1250
+ {
1251
+ new BsonDocument ( "_id" , 1 ) ,
1252
+ new BsonDocument ( "_id" , 1 )
1253
+ } ;
1254
+
1255
+ _collection . Drop ( ) ;
1256
+ var bulk = InitializeBulkOperation ( _collection , ordered ) ;
1257
+ bulk . Insert ( documents [ 0 ] ) ;
1258
+ bulk . Insert ( documents [ 1 ] ) ;
1259
+ var result = bulk . Execute ( WriteConcern . Unacknowledged ) ;
1260
+
1261
+ var expectedResult = new ExpectedResult { IsAcknowledged = false , RequestCount = 2 } ;
1262
+ CheckExpectedResult ( expectedResult , result ) ;
1263
+
1264
+ var expectedDocuments = new [ ] { documents [ 0 ] } ;
1265
+ Assert . That ( _collection . FindAll ( ) , Is . EquivalentTo ( expectedDocuments ) ) ;
1266
+ }
1267
+ }
1268
+
1188
1269
[ Test ]
1189
1270
[ TestCase ( false ) ]
1190
1271
[ TestCase ( true ) ]
@@ -1203,7 +1284,7 @@ public void TestW2AgainstStandalone(bool ordered)
1203
1284
1204
1285
if ( serverInstance . Supports ( FeatureId . WriteCommands ) )
1205
1286
{
1206
- var exception = Assert . Throws < MongoCommandException > ( ( ) => { bulk . Execute ( WriteConcern . W2 ) ; } ) ;
1287
+ Assert . Throws < MongoCommandException > ( ( ) => { bulk . Execute ( WriteConcern . W2 ) ; } ) ;
1207
1288
Assert . AreEqual ( 0 , _collection . Count ( ) ) ;
1208
1289
}
1209
1290
else
@@ -1264,6 +1345,28 @@ private BulkWriteOperation InitializeBulkOperation(MongoCollection collection, b
1264
1345
return ordered ? collection . InitializeOrderedBulkOperation ( ) : _collection . InitializeUnorderedBulkOperation ( ) ;
1265
1346
}
1266
1347
1348
+ private bool IsJournalEnabled ( MongoServerInstance serverInstance )
1349
+ {
1350
+ using ( _server . RequestStart ( null , serverInstance ) )
1351
+ {
1352
+ var adminDatabase = _server . GetDatabase ( "admin" ) ;
1353
+ var command = new CommandDocument ( "getCmdLineOpts" , 1 ) ;
1354
+ var result = adminDatabase . RunCommand ( command ) ;
1355
+
1356
+ BsonValue parsed ;
1357
+ if ( result . Response . TryGetValue ( "parsed" , out parsed ) )
1358
+ {
1359
+ BsonValue nojournal ;
1360
+ if ( parsed . AsBsonDocument . TryGetValue ( "nojournal" , out nojournal ) )
1361
+ {
1362
+ return ! nojournal . ToBoolean ( ) ;
1363
+ }
1364
+ }
1365
+
1366
+ return true ;
1367
+ }
1368
+ }
1369
+
1267
1370
// nested classes
1268
1371
private class ExpectedResult
1269
1372
{
0 commit comments