def test_db_instance(self): self.config(unreliable=True) cache = oslo_cache.get_cache(self.conf) control = mongodb.ControlDriver(self.conf, cache) data = mongodb.DataDriver(self.conf, cache, control) for db in data.message_databases: self.assertThat(db.name, matchers.StartsWith( data.mongodb_conf.database))
def test_write_concern_is_set(self): cache = oslo_cache.get_cache() with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) driver = mongodb.DataDriver(self.conf, cache) wc = driver.connection.write_concern self.assertEqual(wc['w'], 'majority') self.assertEqual(wc['j'], False)
def test_db_instance(self): self.config(unreliable=True) cache = oslo_cache.get_cache() driver = mongodb.DataDriver(self.conf, cache) databases = (driver.message_databases + [driver.queues_database]) for db in databases: self.assertThat(db.name, matchers.StartsWith(driver.mongodb_conf.database))
def test_using_mongos(self): cache = oslo_cache.get_cache(self.conf) with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) with mock.patch('pymongo.MongoClient.write_concern') as wc: write_concern = pymongo.WriteConcern(w=2) wc.__get__ = mock.Mock(return_value=write_concern) mongodb.DataDriver(self.conf, cache, mongodb.ControlDriver(self.conf, cache))
def test_using_replset(self): cache = oslo_cache.get_cache(self.conf) with mock.patch('pymongo.MongoClient.nodes') as nodes: nodes.__get__ = mock.Mock(return_value=['node1', 'node2']) with mock.patch('pymongo.MongoClient.write_concern') as wc: write_concern = pymongo.WriteConcern(w=2) wc.__get__ = mock.Mock(return_value=write_concern) mongodb.DataDriver(self.conf, cache, mongodb.ControlDriver(self.conf, cache))
def test_write_concern_check_works(self): cache = oslo_cache.get_cache() with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) with mock.patch('pymongo.MongoClient.write_concern') as wc: wc.__get__ = mock.Mock(return_value={'w': 1}) self.assertRaises(RuntimeError, mongodb.DataDriver, self.conf, cache) wc.__get__ = mock.Mock(return_value={'w': 2}) mongodb.DataDriver(self.conf, cache)
def test_version_match(self): self.config(unreliable=True) cache = oslo_cache.get_cache() with mock.patch('pymongo.MongoClient.server_info') as info: info.return_value = {'version': '2.1'} self.assertRaises(RuntimeError, mongodb.DataDriver, self.conf, cache) info.return_value = {'version': '2.11'} try: mongodb.DataDriver(self.conf, cache) except RuntimeError: self.fail('version match failed')
def test_write_concern_is_set(self): cache = oslo_cache.get_cache(self.conf) with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) self.config(unreliable=True) driver = mongodb.DataDriver( self.conf, cache, mongodb.ControlDriver(self.conf, cache)) driver.server_version = (2, 6) for db in driver.message_databases: wc = db.write_concern self.assertEqual('majority', wc.document['w']) self.assertFalse(wc.document['j'])
def test_write_concern_check_works(self): cache = oslo_cache.get_cache(self.conf) with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) with mock.patch('pymongo.MongoClient.write_concern') as wc: write_concern = pymongo.WriteConcern(w=1) wc.__get__ = mock.Mock(return_value=write_concern) self.assertRaises(RuntimeError, mongodb.DataDriver, self.conf, cache, mongodb.ControlDriver(self.conf, cache)) write_concern = pymongo.WriteConcern(w=2) wc.__get__ = mock.Mock(return_value=write_concern) mongodb.DataDriver(self.conf, cache, mongodb.ControlDriver(self.conf, cache))
def test_using_mongos(self): cache = oslo_cache.get_cache() with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos: is_mongos.__get__ = mock.Mock(return_value=True) mongodb.DataDriver(self.conf, cache)
def test_using_replset(self): cache = oslo_cache.get_cache() with mock.patch('pymongo.MongoClient.nodes') as nodes: nodes.__get__ = mock.Mock(return_value=['node1', 'node2']) mongodb.DataDriver(self.conf, cache)