本文整理汇总了Python中pycassa.ConnectionPool.return_conn方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectionPool.return_conn方法的具体用法?Python ConnectionPool.return_conn怎么用?Python ConnectionPool.return_conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycassa.ConnectionPool
的用法示例。
在下文中一共展示了ConnectionPool.return_conn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_queue_pool
# 需要导入模块: from pycassa import ConnectionPool [as 别名]
# 或者: from pycassa.ConnectionPool import return_conn [as 别名]
def test_queue_pool(self):
listener = _TestListener()
pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
prefill=True, pool_timeout=0.1, timeout=1,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=False)
conns = []
for i in range(10):
conns.append(pool.get())
assert_equal(listener.connect_count, 10)
assert_equal(listener.checkout_count, 10)
# Pool is maxed out now
assert_raises(NoConnectionAvailable, pool.get)
assert_equal(listener.connect_count, 10)
assert_equal(listener.max_count, 1)
for i in range(0, 5):
pool.return_conn(conns[i])
assert_equal(listener.close_count, 0)
assert_equal(listener.checkin_count, 5)
for i in range(5, 10):
pool.return_conn(conns[i])
assert_equal(listener.close_count, 5)
assert_equal(listener.checkin_count, 10)
conns = []
# These connections should come from the pool
for i in range(5):
conns.append(pool.get())
assert_equal(listener.connect_count, 10)
assert_equal(listener.checkout_count, 15)
# But these will need to be made
for i in range(5):
conns.append(pool.get())
assert_equal(listener.connect_count, 15)
assert_equal(listener.checkout_count, 20)
assert_equal(listener.close_count, 5)
for i in range(10):
conns[i].return_to_pool()
assert_equal(listener.checkin_count, 20)
assert_equal(listener.close_count, 10)
assert_raises(InvalidRequestError, conns[0].return_to_pool)
assert_equal(listener.checkin_count, 20)
assert_equal(listener.close_count, 10)
print "in test:", id(conns[-1])
assert_raises(InvalidRequestError, conns[-1].return_to_pool)
assert_equal(listener.checkin_count, 20)
assert_equal(listener.close_count, 10)
pool.dispose()
assert_equal(listener.dispose_count, 1)
示例2: test_queue_pool
# 需要导入模块: from pycassa import ConnectionPool [as 别名]
# 或者: from pycassa.ConnectionPool import return_conn [as 别名]
def test_queue_pool(self):
stats_logger = StatsLoggerWithListStorage()
pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
prefill=True, pool_timeout=0.1, timeout=1,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[stats_logger], use_threadlocal=False)
conns = []
for i in range(10):
conns.append(pool.get())
assert_equal(stats_logger.stats['created']['success'], 10)
assert_equal(stats_logger.stats['checked_out'], 10)
# Pool is maxed out now
assert_raises(NoConnectionAvailable, pool.get)
assert_equal(stats_logger.stats['created']['success'], 10)
assert_equal(stats_logger.stats['at_max'], 1)
for i in range(0, 5):
pool.return_conn(conns[i])
assert_equal(stats_logger.stats['disposed']['success'], 0)
assert_equal(stats_logger.stats['checked_in'], 5)
for i in range(5, 10):
pool.return_conn(conns[i])
assert_equal(stats_logger.stats['disposed']['success'], 5)
assert_equal(stats_logger.stats['checked_in'], 10)
conns = []
# These connections should come from the pool
for i in range(5):
conns.append(pool.get())
assert_equal(stats_logger.stats['created']['success'], 10)
assert_equal(stats_logger.stats['checked_out'], 15)
# But these will need to be made
for i in range(5):
conns.append(pool.get())
assert_equal(stats_logger.stats['created']['success'], 15)
assert_equal(stats_logger.stats['checked_out'], 20)
assert_equal(stats_logger.stats['disposed']['success'], 5)
for i in range(10):
conns[i].return_to_pool()
assert_equal(stats_logger.stats['checked_in'], 20)
assert_equal(stats_logger.stats['disposed']['success'], 10)
assert_raises(InvalidRequestError, conns[0].return_to_pool)
assert_equal(stats_logger.stats['checked_in'], 20)
assert_equal(stats_logger.stats['disposed']['success'], 10)
print("in test:", id(conns[-1]))
conns[-1].return_to_pool()
assert_equal(stats_logger.stats['checked_in'], 20)
assert_equal(stats_logger.stats['disposed']['success'], 10)
pool.dispose()
示例3: test_queue_pool_threadlocal
# 需要导入模块: from pycassa import ConnectionPool [as 别名]
# 或者: from pycassa.ConnectionPool import return_conn [as 别名]
def test_queue_pool_threadlocal(self):
listener = _TestListener()
pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
prefill=True, pool_timeout=0.01, timeout=1,
keyspace='PycassaTestKeyspace', credentials=_credentials,
listeners=[listener], use_threadlocal=True)
conns = []
assert_equal(listener.connect_count, 5)
# These connections should all be the same
for i in range(10):
conns.append(pool.get())
assert_equal(listener.connect_count, 5)
assert_equal(listener.checkout_count, 1)
for i in range(0, 5):
pool.return_conn(conns[i])
assert_equal(listener.checkin_count, 1)
for i in range(5, 10):
pool.return_conn(conns[i])
assert_equal(listener.checkin_count, 1)
conns = []
assert_equal(listener.connect_count, 5)
# A single connection should come from the pool
for i in range(5):
conns.append(pool.get())
assert_equal(listener.connect_count, 5)
assert_equal(listener.checkout_count, 2)
for conn in conns:
pool.return_conn(conn)
conns = []
threads = []
listener.reset()
def checkout_return():
conn = pool.get()
time.sleep(1)
pool.return_conn(conn)
for i in range(5):
threads.append(threading.Thread(target=checkout_return))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.connect_count, 0) # Still 5 connections in pool
assert_equal(listener.checkout_count, 5)
assert_equal(listener.checkin_count, 5)
# These should come from the pool
threads = []
for i in range(5):
threads.append(threading.Thread(target=checkout_return))
threads[-1].start()
for thread in threads:
thread.join()
assert_equal(listener.connect_count, 0)
assert_equal(listener.checkout_count, 10)
assert_equal(listener.checkin_count, 10)
pool.dispose()