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


Python MongoClient._get_topology方法代码示例

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


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

示例1: test_max_idle_time_reaper

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_max_idle_time_reaper(self):
        with client_knobs(kill_cursor_frequency=0.1):
            # Assert reaper doesn't remove sockets when maxIdleTimeMS not set
            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            time.sleep(1)
            self.assertEqual(1, len(server._pool.sockets))
            self.assertTrue(sock_info in server._pool.sockets)

            # Assert reaper removes idle socket and replaces it with a new one
            client = MongoClient(host, port, maxIdleTimeMS=.5, minPoolSize=1)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            time.sleep(2)
            self.assertEqual(1, len(server._pool.sockets))
            self.assertFalse(sock_info in server._pool.sockets)

            # Assert reaper has removed idle socket and NOT replaced it
            client = MongoClient(host, port, maxIdleTimeMS=.5)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}):
                pass
            time.sleep(1)
            self.assertEqual(0, len(server._pool.sockets))
开发者ID:gregbanks,项目名称:mongo-python-driver,代码行数:29,代码来源:test_client.py

示例2: test_max_idle_time_checkout

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_max_idle_time_checkout(self):
        # Use high frequency to test _get_socket_no_auth.
        with client_knobs(kill_cursor_frequency=99999999):
            client = MongoClient(host, port, maxIdleTimeMS=.5)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            self.assertEqual(1, len(server._pool.sockets))
            time.sleep(1) #  Sleep so that the socket becomes stale.

            with server._pool.get_socket({}) as new_sock_info:
                self.assertNotEqual(sock_info, new_sock_info)
            self.assertEqual(1, len(server._pool.sockets))
            self.assertFalse(sock_info in server._pool.sockets)
            self.assertTrue(new_sock_info in server._pool.sockets)

            # Test that sockets are reused if maxIdleTimeMS is not set.
            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            self.assertEqual(1, len(server._pool.sockets))
            time.sleep(1)
            with server._pool.get_socket({}) as new_sock_info:
                self.assertEqual(sock_info, new_sock_info)
            self.assertEqual(1, len(server._pool.sockets))
开发者ID:HermogenesBatista,项目名称:mongo-python-driver,代码行数:28,代码来源:test_client.py

示例3: test_max_idle_time_reaper

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_max_idle_time_reaper(self):
        with client_knobs(kill_cursor_frequency=0.1):
            # Assert reaper doesn't remove sockets when maxIdleTimeMS not set
            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            self.assertEqual(1, len(server._pool.sockets))
            self.assertTrue(sock_info in server._pool.sockets)

            # Assert reaper removes idle socket and replaces it with a new one
            client = MongoClient(host, port, maxIdleTimeMS=.5, minPoolSize=1)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            self.assertEqual(1, len(server._pool.sockets))
            wait_until(lambda: sock_info not in server._pool.sockets,
                       "reaper removes stale socket eventually")
            wait_until(lambda: 1 == len(server._pool.sockets),
                       "reaper replaces stale socket with new one")

            # Assert reaper has removed idle socket and NOT replaced it
            client = MongoClient(host, port, maxIdleTimeMS=.5)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}):
                pass
            wait_until(
                lambda: 0 == len(server._pool.sockets),
                "stale socket reaped and new one NOT added to the pool")
开发者ID:HermogenesBatista,项目名称:mongo-python-driver,代码行数:31,代码来源:test_client.py

示例4: test_min_pool_size

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_min_pool_size(self):
        with client_knobs(kill_cursor_frequency=.1):
            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            self.assertEqual(0, len(server._pool.sockets))

            # Assert that pool started up at minPoolSize
            client = MongoClient(host, port, minPoolSize=10)
            server = client._get_topology().select_server(any_server_selector)
            wait_until(lambda: 10 == len(server._pool.sockets),
                       "pool initialized with 10 sockets")

            # Assert that if a socket is closed, a new one takes its place
            with server._pool.get_socket({}) as sock_info:
                sock_info.close()
            wait_until(lambda: 10 == len(server._pool.sockets),
                       "a closed socket gets replaced from the pool")
            self.assertFalse(sock_info in server._pool.sockets)
开发者ID:HermogenesBatista,项目名称:mongo-python-driver,代码行数:20,代码来源:test_client.py

示例5: test_min_pool_size

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_min_pool_size(self):
        with client_knobs(kill_cursor_frequency=.1):
            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            time.sleep(1)
            self.assertEqual(0, len(server._pool.sockets))

            # Assert that pool started up at minPoolSize
            client = MongoClient(host, port, minPoolSize=10)
            server = client._get_topology().select_server(any_server_selector)
            time.sleep(1)
            self.assertEqual(10, len(server._pool.sockets))

            # Assert that if a socket is closed, a new one takes its place
            with server._pool.get_socket({}) as sock_info:
                sock_info.close()
            time.sleep(1)
            self.assertEqual(10, len(server._pool.sockets))
            self.assertFalse(sock_info in server._pool.sockets)
开发者ID:gregbanks,项目名称:mongo-python-driver,代码行数:21,代码来源:test_client.py

示例6: test_max_idle_time_checkout

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import _get_topology [as 别名]
    def test_max_idle_time_checkout(self):
        with client_knobs(kill_cursor_frequency=99999999):
            client = MongoClient(host, port, maxIdleTimeMS=.5)
            time.sleep(1)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            time.sleep(1)
            with server._pool.get_socket({}) as new_sock_info:
                self.assertNotEqual(sock_info, new_sock_info)
            self.assertEqual(1, len(server._pool.sockets))
            self.assertFalse(sock_info in server._pool.sockets)
            self.assertTrue(new_sock_info in server._pool.sockets)

            client = MongoClient(host, port)
            server = client._get_topology().select_server(any_server_selector)
            with server._pool.get_socket({}) as sock_info:
                pass
            time.sleep(1)
            with server._pool.get_socket({}) as new_sock_info:
                self.assertEqual(sock_info, new_sock_info)
            self.assertEqual(1, len(server._pool.sockets))
开发者ID:gregbanks,项目名称:mongo-python-driver,代码行数:24,代码来源:test_client.py


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