本文整理汇总了Python中pymysqlreplication.BinLogStreamReader.fetchone方法的典型用法代码示例。如果您正苦于以下问题:Python BinLogStreamReader.fetchone方法的具体用法?Python BinLogStreamReader.fetchone怎么用?Python BinLogStreamReader.fetchone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymysqlreplication.BinLogStreamReader
的用法示例。
在下文中一共展示了BinLogStreamReader.fetchone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCTLConnectionSettings
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestCTLConnectionSettings(base.PyMySQLReplicationTestCase):
def setUp(self):
super(TestCTLConnectionSettings, self).setUp()
self.stream.close()
ctl_db = copy.copy(self.database)
ctl_db["db"] = None
ctl_db["port"] = 3307
self.ctl_conn_control = pymysql.connect(**ctl_db)
self.ctl_conn_control.cursor().execute("DROP DATABASE IF EXISTS pymysqlreplication_test")
self.ctl_conn_control.cursor().execute("CREATE DATABASE pymysqlreplication_test")
self.ctl_conn_control.close()
ctl_db["db"] = "pymysqlreplication_test"
self.ctl_conn_control = pymysql.connect(**ctl_db)
self.stream = BinLogStreamReader(
self.database,
ctl_connection_settings=ctl_db,
server_id=1024,
only_events=(WriteRowsEvent,),
fail_on_table_metadata_unavailable=True
)
def tearDown(self):
super(TestCTLConnectionSettings, self).tearDown()
self.ctl_conn_control.close()
def test_seperate_ctl_settings_table_metadata_unavailable(self):
self.execute("CREATE TABLE test (id INTEGER(11))")
self.execute("INSERT INTO test VALUES (1)")
self.execute("COMMIT")
had_error = False
try:
event = self.stream.fetchone()
except TableMetadataUnavailableError as e:
had_error = True
assert "test" in e.args[0]
finally:
self.resetBinLog()
assert had_error
def test_seperate_ctl_settings_no_error(self):
self.execute("CREATE TABLE test (id INTEGER(11))")
self.execute("INSERT INTO test VALUES (1)")
self.execute("DROP TABLE test")
self.execute("COMMIT")
self.ctl_conn_control.cursor().execute("CREATE TABLE test (id INTEGER(11))")
self.ctl_conn_control.cursor().execute("INSERT INTO test VALUES (1)")
self.ctl_conn_control.cursor().execute("COMMIT")
try:
self.stream.fetchone()
except Exception as e:
self.fail("raised unexpected exception: {exception}".format(exception=e))
finally:
self.resetBinLog()
示例2: TestGtidBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase):
def test_read_query_event(self):
query = "CREATE TABLE test (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "SELECT @@global.gtid_executed;"
gtid = self.execute(query).fetchone()[0]
self.stream.close()
self.stream = BinLogStreamReader(self.database, server_id=1024, blocking=True, auto_position=gtid)
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
# Insert first event
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(1, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
firstevent = self.stream.fetchone()
self.assertIsInstance(firstevent, GtidEvent)
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
self.assertIsInstance(self.stream.fetchone(), WriteRowsEvent)
self.assertIsInstance(self.stream.fetchone(), XidEvent)
# Insert second event
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(2, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
secondevent = self.stream.fetchone()
self.assertIsInstance(secondevent, GtidEvent)
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
self.assertIsInstance(self.stream.fetchone(), WriteRowsEvent)
self.assertIsInstance(self.stream.fetchone(), XidEvent)
self.assertEqual(secondevent.gno, firstevent.gno + 1)
def test_position_gtid(self):
query = "CREATE TABLE test (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(1, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
query = "CREATE TABLE test2 (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "SELECT @@global.gtid_executed;"
gtid = self.execute(query).fetchone()[0]
self.stream.close()
self.stream = BinLogStreamReader(self.database, server_id=1024, blocking=True, auto_position=gtid)
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
self.assertIsInstance(self.stream.fetchone(), GtidEvent)
event = self.stream.fetchone()
self.assertEqual(
event.query, "CREATE TABLE test2 (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
)
示例3: TestBasicBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestBasicBinLogStreamReader(base.PyMySQLReplicationTestCase):
def ignoredEvents(self):
return [GtidEvent]
def test_read_query_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertEqual(event.position, 4)
self.assertEqual(event.next_binlog, "mysql-bin.000001")
self.assertIsInstance(event, RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_read_query_event_with_unicode(self):
query = u"CREATE TABLE `testÈ` (id INT NOT NULL AUTO_INCREMENT, dataÈ VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertEqual(event.position, 4)
self.assertEqual(event.next_binlog, "mysql-bin.000001")
self.assertIsInstance(event, RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_reading_rotate_event(self):
query = "CREATE TABLE test_2 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.stream.close()
query = "CREATE TABLE test_3 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
# Rotate event
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
def test_connection_stream_lost_event(self):
self.stream.close()
self.stream = BinLogStreamReader(
self.database, server_id=1024, blocking=True, ignored_events=self.ignoredEvents()
)
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query2 = "INSERT INTO test (data) VALUES('a')"
for i in range(0, 10000):
self.execute(query2)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
self.conn_control.kill(self.stream._stream_connection.thread_id())
for i in range(0, 1000):
event = self.stream.fetchone()
self.assertIsNotNone(event)
def test_filtering_events(self):
self.stream.close()
self.stream = BinLogStreamReader(self.database, server_id=1024, only_events=[QueryEvent])
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_write_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "INSERT INTO test (data) VALUES('Hello World')"
self.execute(query)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
# QueryEvent for the Create Table
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
# QueryEvent for the BEGIN
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
event = self.stream.fetchone()
#.........这里部分代码省略.........
示例4: TestMultipleRowBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestMultipleRowBinLogStreamReader(base.PyMySQLReplicationTestCase):
def ignoredEvents(self):
return [GtidEvent]
def test_insert_multiple_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
self.resetBinLog()
query = "INSERT INTO test (data) VALUES('Hello'),('World')"
self.execute(query)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
#QueryEvent for the BEGIN
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
event = self.stream.fetchone()
if self.isMySQL56AndMore():
self.assertEqual(event.event_type, WRITE_ROWS_EVENT_V2)
else:
self.assertEqual(event.event_type, WRITE_ROWS_EVENT_V1)
self.assertIsInstance(event, WriteRowsEvent)
self.assertEqual(len(event.rows), 2)
self.assertEqual(event.rows[0]["values"]["id"], 1)
self.assertEqual(event.rows[0]["values"]["data"], "Hello")
self.assertEqual(event.rows[1]["values"]["id"], 2)
self.assertEqual(event.rows[1]["values"]["data"], "World")
def test_update_multiple_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "INSERT INTO test (data) VALUES('Hello')"
self.execute(query)
query = "INSERT INTO test (data) VALUES('World')"
self.execute(query)
self.resetBinLog()
query = "UPDATE test SET data = 'Toto'"
self.execute(query)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
#QueryEvent for the BEGIN
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
event = self.stream.fetchone()
if self.isMySQL56AndMore():
self.assertEqual(event.event_type, UPDATE_ROWS_EVENT_V2)
else:
self.assertEqual(event.event_type, UPDATE_ROWS_EVENT_V1)
self.assertIsInstance(event, UpdateRowsEvent)
self.assertEqual(len(event.rows), 2)
self.assertEqual(event.rows[0]["before_values"]["id"], 1)
self.assertEqual(event.rows[0]["before_values"]["data"], "Hello")
self.assertEqual(event.rows[0]["after_values"]["id"], 1)
self.assertEqual(event.rows[0]["after_values"]["data"], "Toto")
self.assertEqual(event.rows[1]["before_values"]["id"], 2)
self.assertEqual(event.rows[1]["before_values"]["data"], "World")
self.assertEqual(event.rows[1]["after_values"]["id"], 2)
self.assertEqual(event.rows[1]["after_values"]["data"], "Toto")
def test_delete_multiple_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "INSERT INTO test (data) VALUES('Hello')"
self.execute(query)
query = "INSERT INTO test (data) VALUES('World')"
self.execute(query)
self.resetBinLog()
query = "DELETE FROM test"
self.execute(query)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
#QueryEvent for the BEGIN
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
event = self.stream.fetchone()
if self.isMySQL56AndMore():
self.assertEqual(event.event_type, DELETE_ROWS_EVENT_V2)
else:
self.assertEqual(event.event_type, DELETE_ROWS_EVENT_V1)
self.assertIsInstance(event, DeleteRowsEvent)
#.........这里部分代码省略.........
示例5: TestBasicBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestBasicBinLogStreamReader(base.PyMySQLReplicationTestCase):
def ignoredEvents(self):
return [GtidEvent]
def test_allowed_event_list(self):
self.assertEqual(len(self.stream._allowed_event_list(None, None, False)), 13)
self.assertEqual(len(self.stream._allowed_event_list(None, None, True)), 12)
self.assertEqual(len(self.stream._allowed_event_list(None, [RotateEvent], False)), 12)
self.assertEqual(len(self.stream._allowed_event_list([RotateEvent], None, False)), 1)
def test_read_query_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertEqual(event.position, 4)
self.assertEqual(event.next_binlog, "mysql-bin.000001")
self.assertIsInstance(event, RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_read_query_event_with_unicode(self):
query = u"CREATE TABLE `testÈ` (id INT NOT NULL AUTO_INCREMENT, dataÈ VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertEqual(event.position, 4)
self.assertEqual(event.next_binlog, "mysql-bin.000001")
self.assertIsInstance(event, RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_reading_rotate_event(self):
query = "CREATE TABLE test_2 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.stream.close()
query = "CREATE TABLE test_3 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
# Rotate event
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
""" `test_load_query_event` needs statement-based binlog
def test_load_query_event(self):
# prepare csv
with open("/tmp/test_load_query.csv", "w") as fp:
fp.write("1,aaa\n2,bbb\n3,ccc\n4,ddd\n")
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "LOAD DATA INFILE '/tmp/test_load_query.csv' INTO TABLE test \
FIELDS TERMINATED BY ',' \
ENCLOSED BY '\"' \
LINES TERMINATED BY '\r\n'"
self.execute(query)
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
# create table
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
# begin
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), BeginLoadQueryEvent)
self.assertIsInstance(self.stream.fetchone(), ExecuteLoadQueryEvent)
self.assertIsInstance(self.stream.fetchone(), XidEvent)
"""
def test_connection_stream_lost_event(self):
self.stream.close()
self.stream = BinLogStreamReader(
self.database, server_id=1024, blocking=True,
ignored_events=self.ignoredEvents())
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query2 = "INSERT INTO test (data) VALUES('a')"
for i in range(0, 10000):
self.execute(query2)
self.execute("COMMIT")
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
#.........这里部分代码省略.........
示例6: TestBasicBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestBasicBinLogStreamReader(base.PyMySQLReplicationTestCase):
def test_read_query_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
#RotateEvent
self.stream.fetchone()
#FormatDescription
self.stream.fetchone()
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_connection_lost_event(self):
self.stream.close()
self.stream = BinLogStreamReader(connection_settings = self.database, blocking = True)
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query2 = "INSERT INTO test (data) VALUES('a')";
for i in range(0, 10000):
self.execute(query2)
self.execute("COMMIT")
#RotateEvent
self.stream.fetchone()
#FormatDescription
self.stream.fetchone()
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
self.conn_control.kill(self.stream._stream_connection.thread_id())
for i in range(0, 1000):
event = self.stream.fetchone()
self.assertIsNotNone(event)
def test_filtering_events(self):
self.stream.close()
self.stream = BinLogStreamReader(connection_settings = self.database, only_events = [QueryEvent])
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
event = self.stream.fetchone()
self.assertIsInstance(event, QueryEvent)
self.assertEqual(event.query, query)
def test_write_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "INSERT INTO test (data) VALUES('Hello World')"
self.execute(query)
self.execute("COMMIT")
#RotateEvent
self.stream.fetchone()
#FormatDescription
self.stream.fetchone()
#QueryEvent for the Create Table
self.stream.fetchone()
#QueryEvent for the BEGIN
self.stream.fetchone()
event = self.stream.fetchone()
self.assertIsInstance(event, TableMapEvent)
event = self.stream.fetchone()
self.assertEqual(event.event_type, WRITE_ROWS_EVENT)
self.assertIsInstance(event, WriteRowsEvent)
self.assertEqual(event.rows[0]["values"]["id"], 1)
self.assertEqual(event.rows[0]["values"]["data"], "Hello World")
self.assertEqual(event.schema, "pymysqlreplication_test")
self.assertEqual(event.table, "test")
self.assertEqual(event.columns[1].name, 'data')
def test_delete_row_event(self):
query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "INSERT INTO test (data) VALUES('Hello World')"
self.execute(query)
self.resetBinLog()
query = "DELETE FROM test WHERE id = 1"
self.execute(query)
self.execute("COMMIT")
#RotateEvent
self.stream.fetchone()
#FormatDescription
self.stream.fetchone()
#QueryEvent for the BEGIN
self.stream.fetchone()
#.........这里部分代码省略.........
示例7: TestGtidBinLogStreamReader
# 需要导入模块: from pymysqlreplication import BinLogStreamReader [as 别名]
# 或者: from pymysqlreplication.BinLogStreamReader import fetchone [as 别名]
class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase):
def setUp(self):
super(TestGtidBinLogStreamReader, self).setUp()
if not self.supportsGTID:
raise unittest.SkipTest("database does not support GTID, skipping GTID tests")
def test_read_query_event(self):
query = "CREATE TABLE test (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "SELECT @@global.gtid_executed;"
gtid = self.execute(query).fetchone()[0]
self.stream.close()
self.stream = BinLogStreamReader(
self.database, server_id=1024, blocking=True, auto_position=gtid,
ignored_events=[HeartbeatLogEvent])
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
# Insert first event
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(1, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
firstevent = self.stream.fetchone()
self.assertIsInstance(firstevent, GtidEvent)
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
self.assertIsInstance(self.stream.fetchone(), WriteRowsEvent)
self.assertIsInstance(self.stream.fetchone(), XidEvent)
# Insert second event
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(2, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
secondevent = self.stream.fetchone()
self.assertIsInstance(secondevent, GtidEvent)
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
self.assertIsInstance(self.stream.fetchone(), WriteRowsEvent)
self.assertIsInstance(self.stream.fetchone(), XidEvent)
self.assertEqual(secondevent.gno, firstevent.gno + 1)
def test_position_gtid(self):
query = "CREATE TABLE test (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
query = "BEGIN;"
self.execute(query)
query = "INSERT INTO test (id, data) VALUES(1, 'Hello');"
self.execute(query)
query = "COMMIT;"
self.execute(query)
query = "SELECT @@global.gtid_executed;"
gtid = self.execute(query).fetchone()[0]
query = "CREATE TABLE test2 (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
self.execute(query)
self.stream.close()
self.stream = BinLogStreamReader(
self.database, server_id=1024, blocking=True, auto_position=gtid,
ignored_events=[HeartbeatLogEvent])
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
self.assertIsInstance(self.stream.fetchone(), GtidEvent)
event = self.stream.fetchone()
self.assertEqual(event.query, 'CREATE TABLE test2 (id INT NOT NULL, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))');