当前位置: 首页>>代码示例>>Python>>正文


Python HostConnectionPool._create_new_connection方法代码示例

本文整理汇总了Python中cassandra.pool.HostConnectionPool._create_new_connection方法的典型用法代码示例。如果您正苦于以下问题:Python HostConnectionPool._create_new_connection方法的具体用法?Python HostConnectionPool._create_new_connection怎么用?Python HostConnectionPool._create_new_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cassandra.pool.HostConnectionPool的用法示例。


在下文中一共展示了HostConnectionPool._create_new_connection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_all_connections_trashed

# 需要导入模块: from cassandra.pool import HostConnectionPool [as 别名]
# 或者: from cassandra.pool.HostConnectionPool import _create_new_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)
开发者ID:EverythingMe,项目名称:python-driver,代码行数:43,代码来源:test_host_connection_pool.py


注:本文中的cassandra.pool.HostConnectionPool._create_new_connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。