|
1 |
| -# -*- coding: utf-8 -*- |
2 |
| - |
3 | 1 | import copy
|
4 | 2 | import platform
|
5 |
| -import sys |
6 | 3 | import json
|
7 |
| - |
8 | 4 | from pymysqlreplication import BinLogStreamReader
|
9 |
| - |
10 |
| -if sys.version_info < (2, 7): |
11 |
| - import unittest2 as unittest |
12 |
| -else: |
13 |
| - import unittest |
| 5 | +import unittest |
14 | 6 |
|
15 | 7 | from decimal import Decimal
|
16 | 8 |
|
17 | 9 | from pymysqlreplication.tests import base
|
18 | 10 | from pymysqlreplication.constants.BINLOG import *
|
19 | 11 | from pymysqlreplication.row_event import *
|
20 | 12 | from pymysqlreplication.event import *
|
21 |
| -from pymysqlreplication._compat import text_type |
22 | 13 |
|
23 |
| - |
24 |
| -__all__ = ["TestDataType"] |
| 14 | +__all__ = ["TestDataType", "TestDataTypeVersion8"] |
25 | 15 |
|
26 | 16 |
|
27 | 17 | def to_binary_dict(d):
|
28 | 18 | def encode_value(v):
|
29 |
| - if isinstance(v, text_type): |
| 19 | + if isinstance(v, str): |
30 | 20 | return v.encode()
|
31 | 21 | if isinstance(v, list):
|
32 | 22 | return [encode_value(x) for x in v]
|
@@ -954,5 +944,49 @@ def test_varbinary(self):
|
954 | 944 | self.assertEqual(event.rows[0]["values"]["b"], b"\xff\x01\x00\x00")
|
955 | 945 |
|
956 | 946 |
|
| 947 | +class TestDataTypeVersion8(base.PyMySQLReplicationVersion8TestCase): |
| 948 | + def ignoredEvents(self): |
| 949 | + return [GtidEvent, PreviousGtidsEvent] |
| 950 | + |
| 951 | + def create_and_insert_value(self, create_query, insert_query): |
| 952 | + self.execute(create_query) |
| 953 | + self.execute(insert_query) |
| 954 | + self.execute("COMMIT") |
| 955 | + |
| 956 | + self.assertIsInstance(self.stream.fetchone(), RotateEvent) |
| 957 | + self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent) |
| 958 | + # QueryEvent for the Create Table |
| 959 | + self.assertIsInstance(self.stream.fetchone(), QueryEvent) |
| 960 | + |
| 961 | + # QueryEvent for the BEGIN |
| 962 | + self.assertIsInstance(self.stream.fetchone(), QueryEvent) |
| 963 | + |
| 964 | + self.assertIsInstance(self.stream.fetchone(), TableMapEvent) |
| 965 | + |
| 966 | + event = self.stream.fetchone() |
| 967 | + if self.isMySQL56AndMore(): |
| 968 | + self.assertEqual(event.event_type, WRITE_ROWS_EVENT_V2) |
| 969 | + else: |
| 970 | + self.assertEqual(event.event_type, WRITE_ROWS_EVENT_V1) |
| 971 | + self.assertIsInstance(event, WriteRowsEvent) |
| 972 | + return event |
| 973 | + |
| 974 | + def test_partition_id(self): |
| 975 | + if not self.isMySQL80AndMore(): |
| 976 | + self.skipTest("Not supported in this version of MySQL") |
| 977 | + create_query = "CREATE TABLE test (id INTEGER) \ |
| 978 | + PARTITION BY RANGE (id) ( \ |
| 979 | + PARTITION p0 VALUES LESS THAN (1), \ |
| 980 | + PARTITION p1 VALUES LESS THAN (2), \ |
| 981 | + PARTITION p2 VALUES LESS THAN (3), \ |
| 982 | + PARTITION p3 VALUES LESS THAN (4), \ |
| 983 | + PARTITION p4 VALUES LESS THAN (5) \ |
| 984 | + )" |
| 985 | + insert_query = "INSERT INTO test (id) VALUES(3)" |
| 986 | + event = self.create_and_insert_value(create_query, insert_query) |
| 987 | + self.assertEqual(event.extra_data_type, 1) |
| 988 | + self.assertEqual(event.partition_id, 3) |
| 989 | + |
| 990 | + |
957 | 991 | if __name__ == "__main__":
|
958 | 992 | unittest.main()
|
0 commit comments