コード例 #1
0
ファイル: test_impl_mongodb.py プロジェクト: ollie314/zaqar
    def test_version_match(self):
        self.config(unreliable=True)
        cache = oslo_cache.get_cache(self.conf)

        with mock.patch('pymongo.MongoClient.server_info') as info:
            info.return_value = {'version': '2.1'}
            self.assertRaises(RuntimeError, mongodb.DataDriver, self.conf,
                              cache, mongodb.ControlDriver(self.conf, cache))

            info.return_value = {'version': '2.11'}

            try:
                mongodb.DataDriver(self.conf, cache,
                                   mongodb.ControlDriver(self.conf, cache))
            except RuntimeError:
                self.fail('version match failed')
コード例 #2
0
    def test_is_alive(self):
        oslo_cache.register_config(self.conf)
        cache = oslo_cache.get_cache(self.conf)
        swift_driver = driver.DataDriver(
            self.conf, cache, mongodb.ControlDriver(self.conf, cache))

        self.assertTrue(swift_driver.is_alive())
コード例 #3
0
    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))
コード例 #4
0
    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))
コード例 #5
0
    def test_replicaset_or_mongos_needed(self):
        cache = oslo_cache.get_cache(self.conf)

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=[])
            with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
                is_mongos.__get__ = mock.Mock(return_value=False)
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache,
                                  mongodb.ControlDriver(self.conf, cache))
コード例 #6
0
    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))
コード例 #7
0
    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))
コード例 #8
0
ファイル: test_impl_mongodb.py プロジェクト: ollie314/zaqar
    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'])