def __init__(self, config): self.queue_cycle = cycle_by_name('round_robin')() self.queue_config = config self._set_initial_state() self.level_lookup_table = {} for level, queues in config.items(): for q in queues: self.level_lookup_table[q] = level
def test_sorted_cycle(): it = cycle_by_name('sorted')(['B', 'C', 'A']) assert it.consume(3) == ['A', 'B', 'C'] it.rotate('B') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('A') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('A') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('C') assert it.consume(3) == ['A', 'B', 'C']
def test_priority_cycle(): it = cycle_by_name('priority')(['A', 'B', 'C']) assert it.consume(3) == ['A', 'B', 'C'] it.rotate('B') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('A') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('A') assert it.consume(3) == ['A', 'B', 'C'] it.rotate('C') assert it.consume(3) == ['A', 'B', 'C']
def test_round_robin_cycle(): it = cycle_by_name('round_robin')(['A', 'B', 'C']) assert it.consume(3) == ['A', 'B', 'C'] it.rotate('B') assert it.consume(3) == ['A', 'C', 'B'] it.rotate('A') assert it.consume(3) == ['C', 'B', 'A'] it.rotate('A') assert it.consume(3) == ['C', 'B', 'A'] it.rotate('C') assert it.consume(3) == ['B', 'A', 'C']
def test_priority_cycle(self): it = cycle_by_name('priority')(['A', 'B', 'C']) self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('B') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('A') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('A') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('C') self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
def test_round_robin_cycle(self): it = cycle_by_name('round_robin')(['A', 'B', 'C']) self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('B') self.assertListEqual(it.consume(3), ['A', 'C', 'B']) it.rotate('A') self.assertListEqual(it.consume(3), ['C', 'B', 'A']) it.rotate('A') self.assertListEqual(it.consume(3), ['C', 'B', 'A']) it.rotate('C') self.assertListEqual(it.consume(3), ['B', 'A', 'C'])
def test_sorted_cycle(self): it = cycle_by_name('sorted')(['B', 'C', 'A']) self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('B') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('A') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('A') self.assertListEqual(it.consume(3), ['A', 'B', 'C']) it.rotate('C') self.assertListEqual(it.consume(3), ['A', 'B', 'C'])
def __init__(self, *args, **kwargs): super_ = super(Channel, self) super_.__init__(*args, **kwargs) if not self.ack_emulation: # disable visibility timeout self.QoS = virtual.QoS self._queue_cycle = cycle_by_name(self.queue_order_strategy)() self.Client = self._get_client() self.ResponseError = self._get_response_error() self.active_fanout_queues = set() self.auto_delete_queues = set() self._fanout_to_queue = {} self.handlers = {'BRPOP': self._brpop_read, 'LISTEN': self._receive} if self.fanout_prefix: if isinstance(self.fanout_prefix, string_t): self.keyprefix_fanout = self.fanout_prefix else: # previous versions did not set a fanout, so cannot enable # by default. self.keyprefix_fanout = '' # Evaluate connection. try: self.client.info() except Exception: self._disconnect_pools() raise self.connection.cycle.add(self) # add to channel poller. # copy errors, in case channel closed but threads still # are still waiting for data. self.connection_errors = self.connection.connection_errors if register_after_fork is not None: register_after_fork(self, _after_fork_cleanup_channel)
def __init__(self): self.cycle = cycle_by_name('round_robin')()