Search in sources :

Example 1 with MysqlGTIDSet

use of com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet in project canal by alibaba.

the class MysqlGTIDSetTest method testUpdate.

@Test
public void testUpdate() {
    String gtid1 = "726757ad-4455-11e8-ae04-0242ac110002:1-25536412";
    MysqlGTIDSet mysqlGTIDSet1 = MysqlGTIDSet.parse(gtid1);
    String gtid2 = "726757ad-4455-11e8-ae04-0242ac110002:1-20304074";
    MysqlGTIDSet mysqlGTIDSet2 = MysqlGTIDSet.parse(gtid2);
    mysqlGTIDSet1.update(gtid2);
    assertEquals("726757ad-4455-11e8-ae04-0242ac110002:1-25536412", mysqlGTIDSet1.toString());
}
Also used : MysqlGTIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet) Test(org.junit.Test)

Example 2 with MysqlGTIDSet

use of com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet in project canal by alibaba.

the class MysqlGTIDSetTest method buildForTest.

private MysqlGTIDSet buildForTest(List<Material> materials) {
    Map<String, UUIDSet> sets = new HashMap<>();
    for (Material a : materials) {
        UUIDSet.Interval interval = new UUIDSet.Interval();
        interval.start = a.start;
        interval.stop = a.stop;
        List<UUIDSet.Interval> intervals = new ArrayList<>();
        intervals.add(interval);
        if (a.start1 > 0 && a.stop1 > 0) {
            UUIDSet.Interval interval1 = new UUIDSet.Interval();
            interval1.start = a.start1;
            interval1.stop = a.stop1;
            intervals.add(interval1);
        }
        UUIDSet us = new UUIDSet();
        us.SID = UUID.fromString(a.uuid);
        us.intervals = intervals;
        sets.put(a.uuid, us);
    }
    MysqlGTIDSet gs = new MysqlGTIDSet();
    gs.sets = sets;
    return gs;
}
Also used : UUIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.UUIDSet) HashMap(java.util.HashMap) MysqlGTIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet) ArrayList(java.util.ArrayList)

Example 3 with MysqlGTIDSet

use of com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet in project canal by alibaba.

the class MysqlGTIDSetTest method testParse.

@Test
public void testParse() {
    Map<String, MysqlGTIDSet> cases = new HashMap<>(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();
        MysqlGTIDSet actual = MysqlGTIDSet.parse(entry.getKey());
        assertEquals(expected, actual);
    }
}
Also used : HashMap(java.util.HashMap) MysqlGTIDSet(com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

MysqlGTIDSet (com.alibaba.otter.canal.parse.driver.mysql.packets.MysqlGTIDSet)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 UUIDSet (com.alibaba.otter.canal.parse.driver.mysql.packets.UUIDSet)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1