def __init__(self, connection='amqp:///', name=None, logger=None, limit=None): """Initialization of Client instance :param connection: connection for broker :type connection: str, None, kombu.connections.Connection, dict """ self.connection = self._get_connection(connection) self.exchanges = {} if name is None: try: name = '<client: {}>'.format(self.connection.as_uri()) except: # pragma: no cover # Errors with filesystem transport name = '<client: {}>'.format(self.connection.transport_cls) if logger is None: logger = get_logger(__name__) self.logger = InstanceLogger(self, logger) self.name = name self.logger.debug('%s built', self.name) if limit is None: # Set limit as global kombu limit. limit = pools.get_limit() self.limit = limit self.connections = pools.Connections(self.limit)
def test_Connections(self): conn = Connection('memory://') p = pools.connections[conn] assert p assert isinstance(p, ConnectionPool) assert p.connection is conn assert p.limit == pools.get_limit()
def test_set_limit(self): pools.reset() pools.set_limit(34576) limit = pools.get_limit() self.assertEqual(limit, 34576) pools.connections[Connection('memory://')] pools.set_limit(limit + 1) self.assertEqual(pools.get_limit(), limit + 1) limit = pools.get_limit() with self.assertRaises(RuntimeError): pools.set_limit(limit - 1) pools.set_limit(limit - 1, force=True) self.assertEqual(pools.get_limit(), limit - 1) pools.set_limit(pools.get_limit())
def test_Connections(self): conn = Connection('memory://') p = pools.connections[conn] self.assertTrue(p) self.assertIsInstance(p, ConnectionPool) self.assertIs(p.connection, conn) self.assertEqual(p.limit, pools.get_limit())
def test_Producers(self): conn = Connection('memory://') p = pools.producers[conn] self.assertTrue(p) self.assertIsInstance(p, pools.ProducerPool) self.assertIs(p.connections, pools.connections[conn]) self.assertEqual(p.limit, p.connections.limit) self.assertEqual(p.limit, pools.get_limit())
def test_Producers(self): conn = Connection('memory://') p = pools.producers[conn] assert p assert isinstance(p, pools.ProducerPool) assert p.connections is pools.connections[conn] assert p.limit == p.connections.limit assert p.limit == pools.get_limit()
def test_set_limit(self): pools.reset() pools.set_limit(34576) limit = pools.get_limit() assert limit == 34576 conn = Connection('memory://') pool = pools.connections[conn] with pool.acquire(): pools.set_limit(limit + 1) assert pools.get_limit() == limit + 1 limit = pools.get_limit() with pytest.raises(RuntimeError): pools.set_limit(limit - 1) pools.set_limit(limit - 1, force=True) assert pools.get_limit() == limit - 1 pools.set_limit(pools.get_limit())
def test_getitem_using_global_limit(self): pools._used[0] = False g = self.MyGroup(limit=pools.use_global_limit) res = g["foo"] self.assertTupleEqual(res, ("foo", pools.get_limit())) self.assertTrue(pools._used[0])
def test_getitem_using_global_limit(self): g = self.MyGroup(limit=pools.use_global_limit) res = g['foo'] assert res == ('foo', pools.get_limit())
def test_getitem_using_global_limit(self): g = self.MyGroup(limit=pools.use_global_limit) res = g['foo'] self.assertTupleEqual(res, ('foo', pools.get_limit()))
def test_getitem_using_global_limit(self): pools._used[0] = False g = self.MyGroup(limit=pools.use_global_limit) res = g['foo'] self.assertTupleEqual(res, ('foo', pools.get_limit())) self.assertTrue(pools._used[0])