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


Python test.client_knobs函数代码示例

本文整理汇总了Python中test.client_knobs函数的典型用法代码示例。如果您正苦于以下问题:Python client_knobs函数的具体用法?Python client_knobs怎么用?Python client_knobs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _test_network_error

    def _test_network_error(self, operation_callback):
        # Verify only the disconnected server is reset by a network failure.

        # Disable background refresh.
        with client_knobs(heartbeat_frequency=999999):
            c = MockClient(
                standalones=[], members=["a:1", "b:2"], mongoses=[], host="a:1", replicaSet="rs", connect=False
            )

            # Set host-specific information so we can test whether it is reset.
            c.set_wire_version_range("a:1", 0, 1)
            c.set_wire_version_range("b:2", 0, 2)
            c._get_topology().select_servers(writable_server_selector)
            wait_until(lambda: len(c.nodes) == 2, "connect")

            c.kill_host("a:1")

            # MongoClient is disconnected from the primary.
            self.assertRaises(AutoReconnect, operation_callback, c)

            # The primary's description is reset.
            server_a = c._get_topology().get_server_by_address(("a", 1))
            sd_a = server_a.description
            self.assertEqual(SERVER_TYPE.Unknown, sd_a.server_type)
            self.assertEqual(0, sd_a.min_wire_version)
            self.assertEqual(0, sd_a.max_wire_version)

            # ...but not the secondary's.
            server_b = c._get_topology().get_server_by_address(("b", 2))
            sd_b = server_b.description
            self.assertEqual(SERVER_TYPE.RSSecondary, sd_b.server_type)
            self.assertEqual(0, sd_b.min_wire_version)
            self.assertEqual(2, sd_b.max_wire_version)
开发者ID:rychipman,项目名称:mongo-python-driver,代码行数:33,代码来源:test_client.py

示例2: test_kill_cursors

 def test_kill_cursors(self):
     with client_knobs(kill_cursor_frequency=0.01):
         self.client.pymongo_test.test.drop()
         self.client.pymongo_test.test.insert_many([{} for _ in range(10)])
         cursor = self.client.pymongo_test.test.find().batch_size(5)
         next(cursor)
         cursor_id = cursor.cursor_id
         self.listener.results = {}
         cursor.close()
         time.sleep(2)
         results = self.listener.results
         started = results.get('started')
         succeeded = results.get('succeeded')
         self.assertIsNone(results.get('failed'))
         self.assertTrue(
             isinstance(started, monitoring.CommandStartedEvent))
         # There could be more than one cursor_id here depending on
         # when the thread last ran.
         self.assertIn(cursor_id, started.command['cursors'])
         self.assertEqual('killCursors', started.command_name)
         self.assertEqual(cursor.address, started.connection_id)
         self.assertEqual('pymongo_test', started.database_name)
         self.assertTrue(isinstance(started.request_id, int))
         self.assertTrue(
             isinstance(succeeded, monitoring.CommandSucceededEvent))
         self.assertTrue(isinstance(succeeded.duration_micros, int))
         self.assertEqual('killCursors', succeeded.command_name)
         self.assertTrue(isinstance(succeeded.request_id, int))
         self.assertEqual(cursor.address, succeeded.connection_id)
         # There could be more than one cursor_id here depending on
         # when the thread last ran.
         self.assertIn(cursor_id, succeeded.reply['cursorsUnknown'])
开发者ID:ccarafa,项目名称:mongo-python-driver,代码行数:32,代码来源:test_monitoring.py

示例3: create_mock_monitor

    def create_mock_monitor(self, responses, uri, expected_results):
        with client_knobs(heartbeat_frequency=0.1, events_queue_frequency=0.1):
            class MockMonitor(Monitor):
                def _check_with_socket(self, sock_info):
                    if isinstance(responses[1], Exception):
                        raise responses[1]
                    return IsMaster(responses[1]), 99

            m = single_client(h=uri,
                              event_listeners=(self.all_listener,),
                              _monitor_class=MockMonitor,
                              _pool_class=MockPool
                              )

            expected_len = len(expected_results)
            wait_until(lambda: len(self.all_listener.results) == expected_len,
                       "publish all events", timeout=15)

        try:
            for i in range(len(expected_results)):
                result = self.all_listener.results[i] if len(
                    self.all_listener.results) > i else None
                self.assertEqual(expected_results[i],
                                 result.__class__.__name__)
                self.assertEqual(result.connection_id,
                                 responses[0])
                if expected_results[i] != 'ServerHeartbeatStartedEvent':
                    if isinstance(result.reply, IsMaster):
                        self.assertEqual(result.duration, 99)
                        self.assertEqual(result.reply._doc, responses[1])
                    else:
                        self.assertEqual(result.reply, responses[1])

        finally:
            m.close()
开发者ID:HermogenesBatista,项目名称:mongo-python-driver,代码行数:35,代码来源:test_heartbeat_monitoring.py

示例4: test_discover_primary

    def test_discover_primary(self):
        # Disable background refresh.
        with client_knobs(heartbeat_frequency=999999):
            c = MockClient(
                standalones=[],
                members=["a:1", "b:2", "c:3"],
                mongoses=[],
                host="b:2",  # Pass a secondary.
                replicaSet="rs",
            )

            wait_until(lambda: len(c.nodes) == 3, "connect")
            self.assertEqual(c.address, ("a", 1))

            # Fail over.
            c.kill_host("a:1")
            c.mock_primary = "b:2"

            c.close()
            self.assertEqual(0, len(c.nodes))

            t = c._get_topology()
            t.select_servers(writable_server_selector)  # Reconnect.
            self.assertEqual(c.address, ("b", 2))

            # a:1 not longer in nodes.
            self.assertLess(len(c.nodes), 3)

            # c:3 is rediscovered.
            t.select_server_by_address(("c", 3))
开发者ID:rychipman,项目名称:mongo-python-driver,代码行数:30,代码来源:test_client.py

示例5: test_timeout_does_not_mark_member_down

    def test_timeout_does_not_mark_member_down(self):
        # If a query times out, the client shouldn't mark the member "down".

        # Disable background refresh.
        with client_knobs(heartbeat_frequency=999999):
            c = rs_client(socketTimeoutMS=3000, w=self.w)
            collection = c.pymongo_test.test
            collection.insert_one({})

            # Query the primary.
            self.assertRaises(
                NetworkTimeout,
                collection.find_one,
                {'$where': delay(5)})

            self.assertTrue(c.primary)
            collection.find_one()  # No error.

            coll = collection.with_options(
                read_preference=ReadPreference.SECONDARY)

            # Query the secondary.
            self.assertRaises(
                NetworkTimeout,
                coll.find_one,
                {'$where': delay(5)})

            self.assertTrue(c.secondaries)

            # No error.
            coll.find_one()
开发者ID:BiosPsucheZoe,项目名称:mongo-python-driver,代码行数:31,代码来源:test_replica_set_client.py

示例6: test_max_idle_time_checkout

    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,代码行数:26,代码来源:test_client.py

示例7: test_discover_primary

    def test_discover_primary(self):
        # Disable background refresh.
        with client_knobs(heartbeat_frequency=999999):
            c = MockClient(
                standalones=[],
                members=['a:1', 'b:2', 'c:3'],
                mongoses=[],
                host='b:2',  # Pass a secondary.
                replicaSet='rs')

            wait_until(lambda: len(c.nodes) == 3, 'connect')
            self.assertEqual(c.address, ('a', 1))

            # Fail over.
            c.kill_host('a:1')
            c.mock_primary = 'b:2'

            c.close()
            self.assertEqual(0, len(c.nodes))

            t = c._get_topology()
            t.select_servers(writable_server_selector)  # Reconnect.
            self.assertEqual(c.address, ('b', 2))

            # a:1 not longer in nodes.
            self.assertLess(len(c.nodes), 3)

            # c:3 is rediscovered.
            t.select_server_by_address(('c', 3))
开发者ID:gregbanks,项目名称:mongo-python-driver,代码行数:29,代码来源:test_client.py

示例8: test_max_idle_time_reaper

    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,代码行数:27,代码来源:test_client.py

示例9: setUpClass

    def setUpClass(cls):
        super(SpecRunner, cls).setUpClass()
        cls.mongos_clients = []

        # Speed up the tests by decreasing the heartbeat frequency.
        cls.knobs = client_knobs(min_heartbeat_interval=0.1)
        cls.knobs.enable()
开发者ID:jaraco,项目名称:mongo-python-driver,代码行数:7,代码来源:utils_spec_runner.py

示例10: test_max_idle_time_reaper

    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,代码行数:29,代码来源:test_client.py

示例11: setUpClass

 def setUpClass(cls):
     super(TransactionsBase, cls).setUpClass()
     # Speed up tests by reducing SDAM waiting time after a network error.
     cls.knobs = client_knobs(min_heartbeat_interval=0.1)
     cls.knobs.enable()
     cls.mongos_clients = []
     if client_context.supports_transactions():
         for address in client_context.mongoses:
             cls.mongos_clients.append(single_client('%s:%s' % address))
开发者ID:ShaneHarvey,项目名称:mongo-python-driver,代码行数:9,代码来源:test_transactions.py

示例12: setUpClass

 def setUpClass(cls):
     super(TestRetryableWrites, cls).setUpClass()
     # Speed up the tests by decreasing the heartbeat frequency.
     cls.knobs = client_knobs(heartbeat_frequency=0.1,
                              min_heartbeat_interval=0.1)
     cls.knobs.enable()
     cls.listener = OvertCommandListener()
     cls.client = rs_or_single_client(
         retryWrites=True, event_listeners=[cls.listener])
     cls.db = cls.client.pymongo_test
开发者ID:behackett,项目名称:mongo-python-driver,代码行数:10,代码来源:test_retryable_writes.py

示例13: setUp

    def setUp(self):
        if self.enable_heartbeat:
            heartbeat_frequency = self.heartbeat_frequency
        else:
            # Disable periodic monitoring.
            heartbeat_frequency = 1e6

        self.knobs = client_knobs(heartbeat_frequency=heartbeat_frequency)

        self.knobs.enable()
开发者ID:BiosPsucheZoe,项目名称:mongo-python-driver,代码行数:10,代码来源:test_ha.py

示例14: test_kill_cursors_with_server_unavailable

    def test_kill_cursors_with_server_unavailable(self):
        with client_knobs(kill_cursor_frequency=9999999):
            client = MongoClient("doesnt exist", connect=False, serverSelectionTimeoutMS=0)

            # Wait for the first tick of the periodic kill-cursors to pass.
            time.sleep(1)

            # Enqueue a kill-cursors message.
            client.close_cursor(1234, ("doesnt-exist", 27017))

            with warnings.catch_warnings(record=True) as user_warnings:
                client._process_kill_cursors_queue()

            self.assertIn("couldn't close cursor on ('doesnt-exist', 27017)", str(user_warnings[0].message))
开发者ID:rychipman,项目名称:mongo-python-driver,代码行数:14,代码来源:test_client.py

示例15: test_min_pool_size

    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,代码行数:18,代码来源:test_client.py


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