本文整理汇总了Python中test.pymongo_mocks.MockClient.mock_primary方法的典型用法代码示例。如果您正苦于以下问题:Python MockClient.mock_primary方法的具体用法?Python MockClient.mock_primary怎么用?Python MockClient.mock_primary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.pymongo_mocks.MockClient
的用法示例。
在下文中一共展示了MockClient.mock_primary方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_discover_primary
# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import mock_primary [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))
示例2: test_discover_primary
# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import mock_primary [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))
示例3: test_max_write_batch_size
# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import mock_primary [as 别名]
def test_max_write_batch_size(self):
c = MockClient(
standalones=[],
members=['a:1', 'b:2'],
mongoses=[],
host='a:1',
replicaSet='rs',
connect=False)
c.set_max_write_batch_size('a:1', 1)
c.set_max_write_batch_size('b:2', 2)
# Uses primary's max batch size.
self.assertEqual(c.max_write_batch_size, 1)
# b becomes primary.
c.mock_primary = 'b:2'
wait_until(lambda: c.max_write_batch_size == 2,
'update max_write_batch_size')
示例4: test_discover_primary
# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import mock_primary [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))
示例5: test_max_wire_version
# 需要导入模块: from test.pymongo_mocks import MockClient [as 别名]
# 或者: from test.pymongo_mocks.MockClient import mock_primary [as 别名]
def test_max_wire_version(self):
c = MockClient(
standalones=[],
members=['a:1', 'b:2', 'c:3'],
mongoses=[],
host='b:2', # Pass a secondary.
replicaSet='rs',
_connect=False)
c.set_max_write_batch_size('a:1', 1)
c.set_max_write_batch_size('b:2', 2)
# Starts with default max batch size.
self.assertEqual(1000, c.max_write_batch_size)
c.db.collection.find_one() # Connect.
# Uses primary's max batch size.
self.assertEqual(c.max_write_batch_size, 1)
# b becomes primary.
c.mock_primary = 'b:2'
c.close()
self.assertEqual(1000, c.max_write_batch_size)
c.db.collection.find_one() # Connect.
self.assertEqual(c.max_write_batch_size, 2)