|
11 | 11 |
|
12 | 12 | from pymysqlreplication.tests import base
|
13 | 13 | from pymysqlreplication import BinLogStreamReader
|
14 |
| -from pymysqlreplication.gtid import GtidSet |
| 14 | +from pymysqlreplication.gtid import GtidSet, Gtid |
15 | 15 | from pymysqlreplication.event import *
|
16 | 16 | from pymysqlreplication.exceptions import TableMetadataUnavailableError
|
17 | 17 | from pymysqlreplication.constants.BINLOG import *
|
@@ -902,6 +902,63 @@ def test_gtidset_representation_payload(self):
|
902 | 902 |
|
903 | 903 | self.assertEqual(str(myset), str(parsedset))
|
904 | 904 |
|
| 905 | +class GtidTests(unittest.TestCase): |
| 906 | + def test_ordering(self): |
| 907 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 908 | + other = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:5-10") |
| 909 | + assert gtid.__lt__(other) |
| 910 | + assert gtid.__le__(other) |
| 911 | + assert other.__gt__(gtid) |
| 912 | + assert other.__ge__(gtid) |
| 913 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 914 | + other = Gtid("deadbeef-20d3-11e5-a393-4a63946f7eac:5-10") |
| 915 | + assert gtid.__lt__(other) |
| 916 | + assert gtid.__le__(other) |
| 917 | + assert other.__gt__(gtid) |
| 918 | + assert other.__ge__(gtid) |
| 919 | + |
| 920 | + def test_encode_decode(self): |
| 921 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 922 | + payload = gtid.encode() |
| 923 | + decoded = Gtid.decode(io.BytesIO(payload)) |
| 924 | + assert str(gtid) == str(decoded) |
| 925 | + |
| 926 | + def test_add_interval(self): |
| 927 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:5-56") |
| 928 | + end = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:57-58") |
| 929 | + assert (gtid + end).intervals == [(5, 59)] |
| 930 | + |
| 931 | + start = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-2") |
| 932 | + assert (gtid + start).intervals == [(1, 3), (5, 57)] |
| 933 | + |
| 934 | + sparse = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-4:7-10") |
| 935 | + within = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:5-6") |
| 936 | + assert (sparse + within).intervals == [(1, 11)] |
| 937 | + |
| 938 | + def test_interval_non_merging(self): |
| 939 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 940 | + other = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:58-59") |
| 941 | + gtid = gtid + other |
| 942 | + self.assertEqual(str(gtid), "57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56:58-59") |
| 943 | + |
| 944 | + def test_merging(self): |
| 945 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 946 | + other = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:57-59") |
| 947 | + gtid = gtid + other |
| 948 | + self.assertEqual(str(gtid), "57b70f4e-20d3-11e5-a393-4a63946f7eac:1-59") |
| 949 | + |
| 950 | + def test_sub_interval(self): |
| 951 | + gtid = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-56") |
| 952 | + start = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:1-5") |
| 953 | + assert (gtid - start).intervals == [(6, 57)] |
| 954 | + |
| 955 | + end = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:55-56") |
| 956 | + assert (gtid - end).intervals == [(1, 55)] |
| 957 | + |
| 958 | + within = Gtid("57b70f4e-20d3-11e5-a393-4a63946f7eac:25-26") |
| 959 | + assert (gtid - within).intervals == [(1, 25), (27, 57)] |
| 960 | + |
| 961 | + |
905 | 962 | if __name__ == "__main__":
|
906 | 963 | import unittest
|
907 | 964 | unittest.main()
|
0 commit comments