Esempio n. 1
0
    def test_db_instance(self):
        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))
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def test_version_match(self):
        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')
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)