本文整理汇总了Python中cassandra.pool.HostConnectionPool.return_connection方法的典型用法代码示例。如果您正苦于以下问题:Python HostConnectionPool.return_connection方法的具体用法?Python HostConnectionPool.return_connection怎么用?Python HostConnectionPool.return_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.pool.HostConnectionPool
的用法示例。
在下文中一共展示了HostConnectionPool.return_connection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_borrow_and_return
# 需要导入模块: from cassandra.pool import HostConnectionPool [as 别名]
# 或者: from cassandra.pool.HostConnectionPool import return_connection [as 别名]
def test_borrow_and_return(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
c = pool.borrow_connection(timeout=0.01)
self.assertIs(c, conn)
self.assertEqual(1, conn.in_flight)
conn.set_keyspace_blocking.assert_called_once_with('foobarkeyspace')
pool.return_connection(conn)
self.assertEqual(0, conn.in_flight)
self.assertNotIn(conn, pool._trash)
示例2: test_return_closed_connection
# 需要导入模块: from cassandra.pool import HostConnectionPool [as 别名]
# 或者: from cassandra.pool.HostConnectionPool import return_connection [as 别名]
def test_return_closed_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=True)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
conn.is_closed = True
session.cluster.signal_connection_failure.return_value = False
pool.return_connection(conn)
# a new creation should be scheduled
session.submit.assert_called_once()
self.assertFalse(pool.is_shutdown)
示例3: test_successful_wait_for_connection
# 需要导入模块: from cassandra.pool import HostConnectionPool [as 别名]
# 或者: from cassandra.pool.HostConnectionPool import return_connection [as 别名]
def test_successful_wait_for_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
self.assertEqual(1, conn.in_flight)
def get_second_conn():
c = pool.borrow_connection(1.0)
self.assertIs(conn, c)
pool.return_connection(c)
t = Thread(target=get_second_conn)
t.start()
pool.return_connection(conn)
t.join()
self.assertEqual(0, conn.in_flight)