def test_write_concern_failure_unordered(self): batch = self.coll.initialize_unordered_bulk_op() batch.insert({'a': 1}) batch.find({'a': 3}).upsert().update_one({'$set': {'a': 3, 'b': 1}}) batch.insert({'a': 2}) client = self.coll.database.connection # Using j=True without journaling is a hard failure. if server_started_with_option(client, '--nojournal', 'nojournal'): self.assertRaises(OperationFailure, batch.execute, {'j': True}) # So is using w > 1 with no replication. elif not self.is_repl: self.assertRaises(OperationFailure, batch.execute, { 'w': 5, 'wtimeout': 1 }) # Replication wtimeout is a 'soft' error. # It shouldn't stop batch processing. else: try: batch.execute({'w': self.w + 1, 'wtimeout': 1}) except BulkWriteError, exc: result = exc.details self.assertEqual(exc.code, 65) else:
def test_j_without_journal(self): client = self.coll.database.connection if not server_started_with_option(client, '--nojournal', 'nojournal'): raise SkipTest("Need mongod started with --nojournal") # Using j=True without journaling is a hard failure. batch = self.coll.initialize_ordered_bulk_op() batch.insert({}) self.assertRaises(OperationFailure, batch.execute, {'j': True})
def test_write_concern_failure_ordered(self): batch = self.coll.initialize_ordered_bulk_op() batch.insert({'a': 1}) batch.insert({'a': 2}) client = self.coll.database.connection # Using j=True without journaling is a hard failure. if server_started_with_option(client, '--nojournal', 'nojournal'): self.assertRaises(OperationFailure, batch.execute, {'j': True}) # So is using w > 1 with no replication. elif not self.is_repl: self.assertRaises(OperationFailure, batch.execute, {'w': 5, 'wtimeout': 1}) # Replication wtimeout is a 'soft' error. # It shouldn't stop batch processing. else: try: batch.execute({'w': self.w + 1, 'wtimeout': 1}) except BulkWriteError, exc: result = exc.error_document self.assertEqual(exc.code, 65) else: