zaqar/tests/unit/queues/storage/test_shard_queues.py
Zhihao Yuan 25b5794bab feat(shard): queue listing from multiple sources
Sharding need special storage driver wrapper for queue-related
operations. The listing queue algorithm merges the listing result
from multiple storage connections, and return them in sorted order.

This patch also fixes non-configurable default limits in sharding.

Change-Id: If9bd80459bd1a0dc92ea68c42bc28c0f6dde2a65
Partitally-implements: blueprint storage-sharding
2013-11-25 15:59:27 -05:00

94 lines
3.1 KiB
Python

# Copyright (c) 2013 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import uuid
from oslo.config import cfg
from marconi.queues.storage import sharding
from marconi.queues.storage import utils
from marconi import tests as testing
from marconi.tests import base
class TestShardQueues(base.TestBase):
@testing.requires_mongodb
def setUp(self):
super(TestShardQueues, self).setUp()
conf = self.load_conf('wsgi_mongodb_sharded.conf')
conf.register_opts([cfg.StrOpt('storage')],
group='queues:drivers')
control = utils.load_storage_driver(conf, control_mode=True)
self.shards_ctrl = control.shards_controller
self.controller = sharding.DataDriver(conf, control).queue_controller
# fake two shards
for _ in xrange(2):
self.shards_ctrl.create(str(uuid.uuid1()), 100, 'sqlite://memory')
def tearDown(self):
self.shards_ctrl.drop_all()
super(TestShardQueues, self).tearDown()
def test_listing(self):
project = "I.G"
interaction = self.controller.list(project=project,
detailed=False)
queues = list(next(interaction))
self.assertEqual(len(queues), 0)
for n in xrange(10):
name = 'queue_%d' % n
self.controller.create(name, project=project)
self.controller.set_metadata(name,
metadata=random.getrandbits(12),
project=project)
interaction = self.controller.list(project=project,
detailed=True,
limit=7)
queues.extend(next(interaction))
marker = next(interaction)
self.assertEqual(len(queues), 7)
interaction = self.controller.list(project=project,
detailed=True,
limit=7,
marker=marker)
queues.extend(next(interaction))
self.assertEqual(len(queues), 10)
# ordered by name as a whole
self.assertTrue(all(queues[i]['name'] <= queues[i + 1]['name']
for i in xrange(len(queues) - 1)))
for n in xrange(10):
self.controller.delete('queue_%d' % n, project=project)
interaction = self.controller.list(project=project,
detailed=False)
queues = list(next(interaction))
self.assertEqual(len(queues), 0)