@@ -1084,6 +1084,80 @@ public void TestInsertBatchContinueOnError()
1084
1084
}
1085
1085
}
1086
1086
1087
+ [ Test ]
1088
+ public void TestInsertBatchMultipleBatchesWriteConcernDisabledContinueOnErrorFalse ( )
1089
+ {
1090
+ var collectionName = Configuration . TestCollection . Name ;
1091
+ var collectionSettings = new MongoCollectionSettings { WriteConcern = WriteConcern . Unacknowledged } ;
1092
+ var collection = Configuration . TestDatabase . GetCollection < BsonDocument > ( collectionName , collectionSettings ) ;
1093
+ if ( collection . Exists ( ) ) { collection . Drop ( ) ; }
1094
+
1095
+ using ( Configuration . TestDatabase . RequestStart ( ) )
1096
+ {
1097
+ var maxMessageLength = Configuration . TestServer . RequestConnection . ServerInstance . MaxMessageLength ;
1098
+
1099
+ var filler = new string ( 'x' , maxMessageLength / 3 ) ; // after overhead results in two documents per sub-batch
1100
+ var documents = new BsonDocument [ ]
1101
+ {
1102
+ // first sub-batch
1103
+ new BsonDocument { { "_id" , 1 } , { "filler" , filler } } ,
1104
+ new BsonDocument { { "_id" , 2 } , { "filler" , filler } } ,
1105
+ // second sub-batch
1106
+ new BsonDocument { { "_id" , 3 } , { "filler" , filler } } ,
1107
+ new BsonDocument { { "_id" , 3 } , { "filler" , filler } } , // duplicate _id error
1108
+ // third sub-batch
1109
+ new BsonDocument { { "_id" , 4 } , { "filler" , filler } } ,
1110
+ new BsonDocument { { "_id" , 5 } , { "filler" , filler } } ,
1111
+ } ;
1112
+
1113
+ var options = new MongoInsertOptions { Flags = InsertFlags . None } ; // no ContinueOnError
1114
+ collection . InsertBatch ( documents , options ) ;
1115
+
1116
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 1 ) ) ) ;
1117
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 2 ) ) ) ;
1118
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 3 ) ) ) ;
1119
+ Assert . AreEqual ( 0 , collection . Count ( Query . EQ ( "_id" , 4 ) ) ) ;
1120
+ Assert . AreEqual ( 0 , collection . Count ( Query . EQ ( "_id" , 5 ) ) ) ;
1121
+ }
1122
+ }
1123
+
1124
+ [ Test ]
1125
+ public void TestInsertBatchMultipleBatchesWriteConcernDisabledContinueOnErrorTrue ( )
1126
+ {
1127
+ var collectionName = Configuration . TestCollection . Name ;
1128
+ var collectionSettings = new MongoCollectionSettings { WriteConcern = WriteConcern . Unacknowledged } ;
1129
+ var collection = Configuration . TestDatabase . GetCollection < BsonDocument > ( collectionName , collectionSettings ) ;
1130
+ if ( collection . Exists ( ) ) { collection . Drop ( ) ; }
1131
+
1132
+ using ( Configuration . TestDatabase . RequestStart ( ) )
1133
+ {
1134
+ var maxMessageLength = Configuration . TestServer . RequestConnection . ServerInstance . MaxMessageLength ;
1135
+
1136
+ var filler = new string ( 'x' , maxMessageLength / 3 ) ; // after overhead results in two documents per sub-batch
1137
+ var documents = new BsonDocument [ ]
1138
+ {
1139
+ // first sub-batch
1140
+ new BsonDocument { { "_id" , 1 } , { "filler" , filler } } ,
1141
+ new BsonDocument { { "_id" , 2 } , { "filler" , filler } } ,
1142
+ // second sub-batch
1143
+ new BsonDocument { { "_id" , 3 } , { "filler" , filler } } ,
1144
+ new BsonDocument { { "_id" , 3 } , { "filler" , filler } } , // duplicate _id error
1145
+ // third sub-batch
1146
+ new BsonDocument { { "_id" , 4 } , { "filler" , filler } } ,
1147
+ new BsonDocument { { "_id" , 5 } , { "filler" , filler } } ,
1148
+ } ;
1149
+
1150
+ var options = new MongoInsertOptions { Flags = InsertFlags . ContinueOnError } ;
1151
+ collection . InsertBatch ( documents , options ) ;
1152
+
1153
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 1 ) ) ) ;
1154
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 2 ) ) ) ;
1155
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 3 ) ) ) ;
1156
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 4 ) ) ) ;
1157
+ Assert . AreEqual ( 1 , collection . Count ( Query . EQ ( "_id" , 5 ) ) ) ;
1158
+ }
1159
+ }
1160
+
1087
1161
[ Test ]
1088
1162
public void TestIsCappedFalse ( )
1089
1163
{
0 commit comments