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


Python MockClient.kill_host方法代码示例

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


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

示例1: test_client

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_client(self):
        c = MockClient(
            standalones=[],
            members=['a:1', 'b:2', 'c:3'],
            mongoses=[],
            host='a:1,b:2,c:3',
            replicaSet='rs',
            serverSelectionTimeoutMS=100)

        # MongoClient connects to primary by default.
        wait_until(lambda: c.address is not None, 'connect to primary')
        self.assertEqual(c.address, ('a', 1))

        # C is brought up as a standalone.
        c.mock_members.remove('c:3')
        c.mock_standalones.append('c:3')

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

        # Force reconnect.
        c.close()

        with self.assertRaises(AutoReconnect):
            c.db.command('ismaster')

        self.assertEqual(c.address, None)
开发者ID:BiosPsucheZoe,项目名称:mongo-python-driver,代码行数:30,代码来源:test_replica_set_reconfig.py

示例2: test_discover_primary

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    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,代码行数:31,代码来源:test_client.py

示例3: test_acceptable_latency

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_acceptable_latency(self):
        client = MockClient(
            standalones=[],
            members=[],
            mongoses=['a:1', 'b:2', 'c:3'],
            host='a:1,b:2,c:3',
            secondaryAcceptableLatencyMS=7)

        self.assertEqual(7, client.secondary_acceptable_latency_ms)
        # No error
        client.db.collection.find_one()

        client = MockClient(
            standalones=[],
            members=[],
            mongoses=['a:1', 'b:2', 'c:3'],
            host='a:1,b:2,c:3',
            secondaryAcceptableLatencyMS=0)

        self.assertEqual(0, client.secondary_acceptable_latency_ms)
        # No error
        client.db.collection.find_one()
        # Our chosen mongos goes down.
        client.kill_host('%s:%s' % (client.host, client.port))
        try:
            client.db.collection.find_one()
        except:
            pass
        # No error
        client.db.collection.find_one()
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:32,代码来源:test_mongos_ha.py

示例4: test_client

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_client(self):
        c = MockClient(
            standalones=[],
            members=['a:1', 'b:2', 'c:3'],
            mongoses=[],
            host='a:1,b:2,c:3',
            replicaSet='rs')

        # MongoClient connects to primary by default.
        self.assertEqual('a', c.host)
        self.assertEqual(1, c.port)

        # C is brought up as a standalone.
        c.mock_members.remove('c:3')
        c.mock_standalones.append('c:3')

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

        # Force reconnect.
        c.disconnect()

        try:
            c.db.collection.find_one()
        except ConfigurationError, e:
            self.assertTrue('not a member of replica set' in str(e))
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:29,代码来源:test_replica_set_reconfig.py

示例5: _test_network_error

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    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,代码行数:35,代码来源:test_client.py

示例6: test_discover_primary

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    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,代码行数:32,代码来源:test_client.py

示例7: test_failover

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_failover(self):
        nthreads = 1

        # ['1:1', '2:2', '3:3', ...]
        mock_hosts = ['%d:%d' % (i, i) for i in range(50)]
        client = MockClient(
            standalones=[],
            members=[],
            mongoses=mock_hosts,
            host=','.join(mock_hosts))

        self.assertEqual(len(mock_hosts), len(client.nodes))

        # Our chosen mongos goes down.
        client.kill_host('%s:%s' % (client.host, client.port))

        # Trigger failover. AutoReconnect should be raised exactly once.
        errors = []
        passed = []

        def f():
            try:
                client.db.collection.find_one()
            except AutoReconnect:
                errors.append(True)

                # Second attempt succeeds.
                client.db.collection.find_one()

            passed.append(True)

        threads = [threading.Thread(target=f) for _ in range(nthreads)]
        for t in threads:
            t.start()

        for t in threads:
            t.join()

        self.assertEqual(1, len(errors))
        self.assertEqual(nthreads, len(passed))

        # Down host is still in list.
        self.assertEqual(len(mock_hosts), len(client.nodes))
开发者ID:3rf,项目名称:mongo-python-driver,代码行数:45,代码来源:test_mongos_ha.py

示例8: test_backport_localthresholdms_kwarg

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_backport_localthresholdms_kwarg(self):
        # Test that localThresholdMS takes precedence over
        # secondaryAcceptableLatencyMS.
        ctx = catch_warnings()
        try:
            warnings.simplefilter("ignore", DeprecationWarning)
            client = MockClient(
                standalones=[],
                members=[],
                mongoses=['a:1', 'b:2', 'c:3'],
                host='a:1,b:2,c:3',
                localThresholdMS=7,
                secondaryAcceptableLatencyMS=0)

            self.assertEqual(7, client.secondary_acceptable_latency_ms)
            self.assertEqual(7, client.local_threshold_ms)
            # No error
            client.db.collection.find_one()

            client = MockClient(
                standalones=[],
                members=[],
                mongoses=['a:1', 'b:2', 'c:3'],
                host='a:1,b:2,c:3',
                localThresholdMS=0,
                secondaryAcceptableLatencyMS=15)

            self.assertEqual(0, client.secondary_acceptable_latency_ms)
            self.assertEqual(0, client.local_threshold_ms)

            # Test that using localThresholdMS works in the same way as using
            # secondaryAcceptableLatencyMS.
            client.db.collection.find_one()
            # Our chosen mongos goes down.
            client.kill_host('%s:%s' % client.address)
            try:
                client.db.collection.find_one()
            except:
                pass
            # No error
            client.db.collection.find_one()
        finally:
            ctx.exit()
开发者ID:hedgepigdaniel,项目名称:mongo-python-driver,代码行数:45,代码来源:test_mongos_ha.py

示例9: test_reconnect

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_reconnect(self):
        # Verify the node list isn't forgotten during a network failure.
        c = MockClient(
            standalones=[], members=["a:1", "b:2", "c:3"], mongoses=[], host="b:2", replicaSet="rs"  # Pass a secondary.
        )

        wait_until(lambda: len(c.nodes) == 3, "connect")

        # Total failure.
        c.kill_host("a:1")
        c.kill_host("b:2")
        c.kill_host("c:3")

        # MongoClient discovers it's alone.
        self.assertRaises(AutoReconnect, c.db.collection.find_one)

        # But it can reconnect.
        c.revive_host("a:1")
        c._get_topology().select_servers(writable_server_selector)
        self.assertEqual(c.address, ("a", 1))
开发者ID:rychipman,项目名称:mongo-python-driver,代码行数:22,代码来源:test_client.py

示例10: test_discover_primary

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_discover_primary(self):
        c = MockClient(
            standalones=[],
            members=['a:1', 'b:2', 'c:3'],
            mongoses=[],
            host='b:2',  # Pass a secondary.
            replicaSet='rs')

        self.assertEqual(('a', 1), c.address)
        self.assertEqual(3, len(c.nodes))

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

        # Force reconnect.
        c.close()
        c.db.collection.find_one()
        self.assertEqual(('b', 2), c.address)

        # a:1 is still in nodes.
        self.assertEqual(3, len(c.nodes))
开发者ID:hedgepigdaniel,项目名称:mongo-python-driver,代码行数:24,代码来源:test_client.py

示例11: test_reconnect

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_reconnect(self):
        # Verify the node list isn't forgotten during a network failure.
        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')

        # Total failure.
        c.kill_host('a:1')
        c.kill_host('b:2')
        c.kill_host('c:3')

        # MongoClient discovers it's alone.
        self.assertRaises(AutoReconnect, c.db.collection.find_one)

        # But it can reconnect.
        c.revive_host('a:1')
        c._get_topology().select_servers(writable_server_selector)
        self.assertEqual(c.address, ('a', 1))
开发者ID:gregbanks,项目名称:mongo-python-driver,代码行数:25,代码来源:test_client.py

示例12: test_reconnect

# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import kill_host [as 别名]
    def test_reconnect(self):
        # Verify the node list isn't forgotten during a network failure.
        c = MockClient(
            standalones=[],
            members=['a:1', 'b:2', 'c:3'],
            mongoses=[],
            host='b:2',  # Pass a secondary.
            replicaSet='rs')

        # Total failure.
        c.kill_host('a:1')
        c.kill_host('b:2')
        c.kill_host('c:3')

        # MongoClient discovers it's alone.
        self.assertRaises(AutoReconnect, c.db.collection.find_one)

        # But it remembers its node list.
        self.assertEqual(3, len(c.nodes))

        # So it can reconnect.
        c.revive_host('a:1')
        c.db.collection.find_one()
开发者ID:quantopian,项目名称:mongo-python-driver,代码行数:25,代码来源:test_client.py


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