def __init__(self, host, port, user, passwd, size=None): log.debug("INIT: Initializing pool of size %d, host %s," " port %d, user %s", size, host, port, user) ObjectPool.__init__(self, size=size) self.host = host self.port = port self.user = user self.passwd = passwd
def __init__(self, host, port, user, passwd, size=None): log.debug( "INIT: Initializing pool of size %d, host %s," " port %d, user %s", size, host, port, user) ObjectPool.__init__(self, size=size) self.host = host self.port = port self.user = user self.passwd = passwd
def __init__(self, scheme, netloc, size=None): log.debug("INIT-POOL: Initializing pool of size %d, scheme: %s, " \ "netloc: %s", size, scheme, netloc) ObjectPool.__init__(self, size=size) connection_class = self._scheme_to_class.get(scheme, None) if connection_class is None: m = 'Unsupported scheme: %s' % (scheme,) raise ValueError(m) self.connection_class = connection_class self.scheme = scheme self.netloc = netloc
def test_put_with_factory(self): cleaned_objects = [] pool = ObjectPool(3, create=[2, 1, 0].pop, verify=lambda o: o % 2 == 0, cleanup=cleaned_objects.append, ) self.assertEqual(pool.pool_get(), 0) pool.pool_put(0) self.assertEqual(pool.pool_get(), 0) self.assertRaises(PoolVerificationError, pool.pool_get) self.assertEqual(pool.pool_get(), 2) self.assertEqual(cleaned_objects, [0])
def __init__(self, **kw): ObjectPool.__init__(self, size=kw["synnefo_poolsize"]) kw.pop("synnefo_poolsize") self._connection_args = kw
def test_put_not_implemented(self): """Test pool_put() method not implemented in abstract class""" pool = ObjectPool(100) self.assertRaises(NotImplementedError, pool._pool_cleanup, None)
def test_get_not_implemented(self): """Test pool_get() method not implemented in abstract class""" pool = ObjectPool(100) self.assertRaises(NotImplementedError, pool._pool_create) self.assertRaises(NotImplementedError, pool._pool_verify, None)
def test_create_pool(self): """Test pool creation works""" pool = ObjectPool(100) self.assertEqual(pool.size, 100)
def test_get_with_factory(self): obj_generator = iter(range(10)).next pool = ObjectPool(3, create=obj_generator) self.assertEqual(pool.pool_get(), 0) self.assertEqual(pool.pool_get(), 1) self.assertEqual(pool.pool_get(), 2)
def test_unbounded_pool(self): pool = ObjectPool(size=0, create=[1,2,3].pop) self.assertEqual(pool.pool_get(), 3) self.assertEqual(pool.pool_get(), 2) self.assertEqual(pool.pool_get(), 1)