本文整理汇总了Python中cassandra.pool.HostConnectionPool._maybe_trash_connection方法的典型用法代码示例。如果您正苦于以下问题:Python HostConnectionPool._maybe_trash_connection方法的具体用法?Python HostConnectionPool._maybe_trash_connection怎么用?Python HostConnectionPool._maybe_trash_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.pool.HostConnectionPool
的用法示例。
在下文中一共展示了HostConnectionPool._maybe_trash_connection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_all_connections_trashed
# 需要导入模块: from cassandra.pool import HostConnectionPool [as 别名]
# 或者: from cassandra.pool.HostConnectionPool import _maybe_trash_connection [as 别名]
def test_all_connections_trashed(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
session.cluster.get_core_connections_per_host.return_value = 1
# manipulate the core connection setting so that we can
# trash the only connection
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.get_core_connections_per_host.return_value = 0
pool._maybe_trash_connection(conn)
session.cluster.get_core_connections_per_host.return_value = 1
submit_called = Event()
def fire_event(*args, **kwargs):
submit_called.set()
session.submit.side_effect = fire_event
def get_conn():
conn.reset_mock()
c = pool.borrow_connection(1.0)
self.assertIs(conn, c)
self.assertEqual(1, conn.in_flight)
conn.set_keyspace_blocking.assert_called_once_with('foobarkeyspace')
pool.return_connection(c)
t = Thread(target=get_conn)
t.start()
submit_called.wait()
self.assertEqual(1, pool._scheduled_for_creation)
session.submit.assert_called_once_with(pool._create_new_connection)
# now run the create_new_connection call
pool._create_new_connection()
t.join()
self.assertEqual(0, conn.in_flight)