本文整理汇总了Python中mongo_connector.connector.Connector.write_oplog_progress方法的典型用法代码示例。如果您正苦于以下问题:Python Connector.write_oplog_progress方法的具体用法?Python Connector.write_oplog_progress怎么用?Python Connector.write_oplog_progress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_connector.connector.Connector
的用法示例。
在下文中一共展示了Connector.write_oplog_progress方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_write_oplog_progress(self):
"""Test write_oplog_progress under several circumstances
"""
os.system('touch %s' % (TEMP_CONFIG))
config_file_path = TEMP_CONFIG
conn = Connector(MAIN_ADDRESS, config_file_path, None, ['test.test'],
'_id', None, None)
#test that None is returned if there is no config file specified.
self.assertEqual(conn.write_oplog_progress(), None)
conn.oplog_progress.get_dict()[1] = Timestamp(12, 34)
#pretend to insert a thread/timestamp pair
conn.write_oplog_progress()
data = json.load(open(config_file_path, 'r'))
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(12, 34))
#ensure the temp file was deleted
self.assertFalse(os.path.exists(config_file_path + '~'))
#ensure that updates work properly
conn.oplog_progress.get_dict()[1] = Timestamp(44, 22)
conn.write_oplog_progress()
config_file = open(config_file_path, 'r')
data = json.load(config_file)
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(44, 22))
os.system('rm ' + config_file_path)
config_file.close()
示例2: test_read_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_read_oplog_progress(self):
"""Test read_oplog_progress
"""
conn = Connector(
address='%s:%d' % (mongo_host, self.primary_p),
oplog_checkpoint=None,
target_url=None,
ns_set=['test.test'],
u_key='_id',
auth_key=None
)
#testing with no file
self.assertEqual(conn.read_oplog_progress(), None)
try:
os.unlink("temp_config.txt")
except OSError:
pass
open("temp_config.txt", "w").close()
conn.oplog_checkpoint = "temp_config.txt"
#testing with empty file
self.assertEqual(conn.read_oplog_progress(), None)
oplog_dict = conn.oplog_progress.get_dict()
#add a value to the file, delete the dict, and then read in the value
oplog_dict['oplog1'] = Timestamp(12, 34)
conn.write_oplog_progress()
del oplog_dict['oplog1']
self.assertEqual(len(oplog_dict), 0)
conn.read_oplog_progress()
oplog_dict = conn.oplog_progress.get_dict()
self.assertTrue('oplog1' in oplog_dict.keys())
self.assertTrue(oplog_dict['oplog1'], Timestamp(12, 34))
oplog_dict['oplog1'] = Timestamp(55, 11)
#see if oplog progress dict is properly updated
conn.read_oplog_progress()
self.assertTrue(oplog_dict['oplog1'], Timestamp(55, 11))
os.unlink("temp_config.txt")
示例3: test_read_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_read_oplog_progress(self):
"""Test read_oplog_progress
"""
conn = Connector(
mongo_address=self.repl_set.uri,
oplog_checkpoint=None,
ns_set=['test.test'],
**connector_opts
)
#testing with no file
self.assertEqual(conn.read_oplog_progress(), None)
try:
os.unlink("temp_oplog.timestamp")
except OSError:
pass
open("temp_oplog.timestamp", "w").close()
conn.oplog_checkpoint = "temp_oplog.timestamp"
#testing with empty file
self.assertEqual(conn.read_oplog_progress(), None)
oplog_dict = conn.oplog_progress.get_dict()
#add a value to the file, delete the dict, and then read in the value
oplog_dict['oplog1'] = Timestamp(12, 34)
conn.write_oplog_progress()
del oplog_dict['oplog1']
self.assertEqual(len(oplog_dict), 0)
conn.read_oplog_progress()
oplog_dict = conn.oplog_progress.get_dict()
self.assertTrue('oplog1' in oplog_dict.keys())
self.assertTrue(oplog_dict['oplog1'], Timestamp(12, 34))
oplog_dict['oplog1'] = Timestamp(55, 11)
#see if oplog progress dict is properly updated
conn.read_oplog_progress()
self.assertTrue(oplog_dict['oplog1'], Timestamp(55, 11))
os.unlink("temp_oplog.timestamp")
示例4: test_read_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_read_oplog_progress(self):
"""Test read_oplog_progress
"""
conn = Connector(
address=MAIN_ADDRESS,
oplog_checkpoint=None,
target_url=None,
ns_set=['test.test'],
u_key='_id',
auth_key=None
)
#testing with no file
self.assertEqual(conn.read_oplog_progress(), None)
os.system('touch %s' % (TEMP_CONFIG))
conn.oplog_checkpoint = TEMP_CONFIG
#testing with empty file
self.assertEqual(conn.read_oplog_progress(), None)
oplog_dict = conn.oplog_progress.get_dict()
#add a value to the file, delete the dict, and then read in the value
oplog_dict['oplog1'] = Timestamp(12, 34)
conn.write_oplog_progress()
del oplog_dict['oplog1']
self.assertEqual(len(oplog_dict), 0)
conn.read_oplog_progress()
self.assertTrue('oplog1' in oplog_dict.keys())
self.assertTrue(oplog_dict['oplog1'], Timestamp(12, 34))
oplog_dict['oplog1'] = Timestamp(55, 11)
#see if oplog progress dict is properly updated
conn.read_oplog_progress()
self.assertTrue(oplog_dict['oplog1'], Timestamp(55, 11))
os.system('rm ' + TEMP_CONFIG)
示例5: test_write_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_write_oplog_progress(self):
"""Test write_oplog_progress under several circumstances
"""
try:
os.unlink("temp_config.txt")
except OSError:
pass
open("temp_config.txt", "w").close()
conn = Connector(
address='%s:%d' % (mongo_host, self.primary_p),
oplog_checkpoint="temp_config.txt",
target_url=None,
ns_set=['test.test'],
u_key='_id',
auth_key=None
)
#test that None is returned if there is no config file specified.
self.assertEqual(conn.write_oplog_progress(), None)
conn.oplog_progress.get_dict()[1] = Timestamp(12, 34)
#pretend to insert a thread/timestamp pair
conn.write_oplog_progress()
data = json.load(open("temp_config.txt", 'r'))
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(12, 34))
#ensure the temp file was deleted
self.assertFalse(os.path.exists("temp_config.txt" + '~'))
#ensure that updates work properly
conn.oplog_progress.get_dict()[1] = Timestamp(44, 22)
conn.write_oplog_progress()
config_file = open("temp_config.txt", 'r')
data = json.load(config_file)
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(44, 22))
config_file.close()
os.unlink("temp_config.txt")
示例6: test_write_oplog_progress
# 需要导入模块: from mongo_connector.connector import Connector [as 别名]
# 或者: from mongo_connector.connector.Connector import write_oplog_progress [as 别名]
def test_write_oplog_progress(self):
"""Test write_oplog_progress under several circumstances
"""
try:
os.unlink("temp_oplog.timestamp")
except OSError:
pass
open("temp_oplog.timestamp", "w").close()
conn = Connector(
mongo_address=self.repl_set.uri,
oplog_checkpoint="temp_oplog.timestamp",
**connector_opts
)
# test that None is returned if there is no config file specified.
self.assertEqual(conn.write_oplog_progress(), None)
conn.oplog_progress.get_dict()[1] = Timestamp(12, 34)
# pretend to insert a thread/timestamp pair
conn.write_oplog_progress()
data = json.load(open("temp_oplog.timestamp", "r"))
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(12, 34))
# ensure the temp file was deleted
self.assertFalse(os.path.exists("temp_oplog.timestamp" + "~"))
# ensure that updates work properly
conn.oplog_progress.get_dict()[1] = Timestamp(44, 22)
conn.write_oplog_progress()
config_file = open("temp_oplog.timestamp", "r")
data = json.load(config_file)
self.assertEqual(1, int(data[0]))
self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(44, 22))
config_file.close()
os.unlink("temp_oplog.timestamp")