|
@@ -1,17 +1,23 @@
|
|
|
package com.alibaba.otter.canal.parse.driver.mysql;
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.UUIDSet;
|
|
|
-import org.junit.Test;
|
|
|
-import static org.junit.Assert.*;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
|
|
|
/**
|
|
|
- * Created by hiwjd on 2018/4/25.
|
|
|
- * hiwjd0@gmail.com
|
|
|
+ * Created by hiwjd on 2018/4/25. hiwjd0@gmail.com
|
|
|
*/
|
|
|
public class MysqlGTIDSetTest {
|
|
|
|
|
@@ -20,14 +26,12 @@ public class MysqlGTIDSetTest {
|
|
|
GTIDSet gtidSet = MysqlGTIDSet.parse("726757ad-4455-11e8-ae04-0242ac110002:1");
|
|
|
byte[] bytes = gtidSet.encode();
|
|
|
|
|
|
- byte[] expected = {
|
|
|
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x67, 0x57, (byte)0xad,
|
|
|
- 0x44, 0x55, 0x11, (byte)0xe8, (byte)0xae, 0x04, 0x02, 0x42, (byte)0xac, 0x11, 0x00, 0x02,
|
|
|
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
- };
|
|
|
+ byte[] expected = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x67, 0x57, (byte) 0xad, 0x44, 0x55,
|
|
|
+ 0x11, (byte) 0xe8, (byte) 0xae, 0x04, 0x02, 0x42, (byte) 0xac, 0x11, 0x00, 0x02, 0x01, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
- for (int i=0; i<bytes.length; i++) {
|
|
|
+ for (int i = 0; i < bytes.length; i++) {
|
|
|
assertEquals(expected[i], bytes[i]);
|
|
|
}
|
|
|
}
|
|
@@ -35,31 +39,17 @@ public class MysqlGTIDSetTest {
|
|
|
@Test
|
|
|
public void testParse() {
|
|
|
Map<String, MysqlGTIDSet> cases = new HashMap<String, MysqlGTIDSet>(5);
|
|
|
- cases.put(
|
|
|
- "726757ad-4455-11e8-ae04-0242ac110002:1",
|
|
|
- buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 2))
|
|
|
- );
|
|
|
- cases.put(
|
|
|
- "726757ad-4455-11e8-ae04-0242ac110002:1-3",
|
|
|
- buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4))
|
|
|
- );
|
|
|
- cases.put(
|
|
|
- "726757ad-4455-11e8-ae04-0242ac110002:1-3:4",
|
|
|
- buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 5))
|
|
|
- );
|
|
|
- cases.put(
|
|
|
- "726757ad-4455-11e8-ae04-0242ac110002:1-3:7-9",
|
|
|
- buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4, 7, 10))
|
|
|
- );
|
|
|
- cases.put(
|
|
|
- "726757ad-4455-11e8-ae04-0242ac110002:1-3,726757ad-4455-11e8-ae04-0242ac110003:4",
|
|
|
- buildForTest(
|
|
|
- Arrays.asList(
|
|
|
- new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4),
|
|
|
- new Material("726757ad-4455-11e8-ae04-0242ac110003", 4, 5)
|
|
|
- )
|
|
|
- )
|
|
|
- );
|
|
|
+ cases.put("726757ad-4455-11e8-ae04-0242ac110002:1",
|
|
|
+ buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 2)));
|
|
|
+ cases.put("726757ad-4455-11e8-ae04-0242ac110002:1-3",
|
|
|
+ buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4)));
|
|
|
+ cases.put("726757ad-4455-11e8-ae04-0242ac110002:1-3:4",
|
|
|
+ buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 5)));
|
|
|
+ cases.put("726757ad-4455-11e8-ae04-0242ac110002:1-3:7-9",
|
|
|
+ buildForTest(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4, 7, 10)));
|
|
|
+ cases.put("726757ad-4455-11e8-ae04-0242ac110002:1-3,726757ad-4455-11e8-ae04-0242ac110003:4",
|
|
|
+ buildForTest(Arrays.asList(new Material("726757ad-4455-11e8-ae04-0242ac110002", 1, 4),
|
|
|
+ new Material("726757ad-4455-11e8-ae04-0242ac110003", 4, 5))));
|
|
|
|
|
|
for (Map.Entry<String, MysqlGTIDSet> entry : cases.entrySet()) {
|
|
|
MysqlGTIDSet expected = entry.getValue();
|
|
@@ -71,7 +61,7 @@ public class MysqlGTIDSetTest {
|
|
|
|
|
|
private static class Material {
|
|
|
|
|
|
- public Material(String uuid, long start, long stop) {
|
|
|
+ public Material(String uuid, long start, long stop){
|
|
|
this.uuid = uuid;
|
|
|
this.start = start;
|
|
|
this.stop = stop;
|
|
@@ -79,7 +69,7 @@ public class MysqlGTIDSetTest {
|
|
|
this.stop1 = 0;
|
|
|
}
|
|
|
|
|
|
- public Material(String uuid, long start, long stop, long start1, long stop1) {
|
|
|
+ public Material(String uuid, long start, long stop, long start1, long stop1){
|
|
|
this.uuid = uuid;
|
|
|
this.start = start;
|
|
|
this.stop = stop;
|
|
@@ -88,10 +78,10 @@ public class MysqlGTIDSetTest {
|
|
|
}
|
|
|
|
|
|
public String uuid;
|
|
|
- public long start;
|
|
|
- public long stop;
|
|
|
- public long start1;
|
|
|
- public long stop1;
|
|
|
+ public long start;
|
|
|
+ public long stop;
|
|
|
+ public long start1;
|
|
|
+ public long stop1;
|
|
|
}
|
|
|
|
|
|
private MysqlGTIDSet buildForTest(Material material) {
|