Exemple #1
0
        public void Test_ParseEmptyString_ReturnsEmptyGtidSet()
        {
            var gtidSet = GtidSet.Parse("");

            Assert.Equal(0, gtidSet.UuidSets.Values.Count);
            Assert.Equal("", gtidSet.ToString());
        }
Exemple #2
0
        public void Test_AddGtidInGap_IntervalsJoined()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:3-4:6-7");

            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 5));

            Assert.Equal($"{ServerUuid1}:3-7", gtidSet.ToString());
        }
Exemple #3
0
        public void Test_СontinuousIntervals_Collapsed()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:1-191:192-199");
            var uuidSet = gtidSet.UuidSets[Uuid.Parse(ServerUuid1)];

            Assert.Equal(1, uuidSet.Intervals.Count);
            Assert.Equal(new Interval(1, 199), uuidSet.Intervals[0]);
            Assert.Equal($"{ServerUuid1}:1-199", gtidSet.ToString());
        }
Exemple #4
0
        public void Test_SimpleGtidSet_HasSingleInterval()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:1-191");
            var uuidSet = gtidSet.UuidSets[Uuid.Parse(ServerUuid1)];

            Assert.Equal(1, uuidSet.Intervals.Count);
            Assert.Equal(new Interval(1, 191), uuidSet.Intervals[0]);
            Assert.Equal($"{ServerUuid1}:1-191", gtidSet.ToString());
        }
Exemple #5
0
 public void Test_RawGtidSets_EqualsCorrectly()
 {
     Assert.Equal(GtidSet.Parse(""), GtidSet.Parse(""));
     Assert.Equal(GtidSet.Parse($"{ServerUuid1}:1-191"), GtidSet.Parse($"{ServerUuid1}:1-191"));
     Assert.Equal(GtidSet.Parse($"{ServerUuid1}:1-191:192-199"), GtidSet.Parse($"{ServerUuid1}:1-191:192-199"));
     Assert.Equal(GtidSet.Parse($"{ServerUuid1}:1-191:192-199"), GtidSet.Parse($"{ServerUuid1}:1-199"));
     Assert.Equal(GtidSet.Parse($"{ServerUuid1}:1-191:193-199"), GtidSet.Parse($"{ServerUuid1}:1-191:193-199"));
     Assert.NotEqual(GtidSet.Parse($"{ServerUuid1}:1-191:193-199"), GtidSet.Parse($"{ServerUuid1}:1-199"));
 }
Exemple #6
0
        static async Task Main(string[] args)
        {
            var client = new BinlogClient(options =>
            {
                options.Port              = 3306;
                options.UseSsl            = false;
                options.Username          = "******";
                options.Password          = "******";
                options.HeartbeatInterval = TimeSpan.FromSeconds(30);
                options.Blocking          = true;

                // Start replication from MariaDB GTID
                options.Binlog = BinlogOptions.FromGtid(GtidList.Parse("0-1-270"));

                // Start replication from MySQL GTID
                var gtidSet    = "d4c17f0c-4f11-11ea-93e3-325d3e1cd1c8:1-107, f442510a-2881-11ea-b1dd-27916133dbb2:1-7";
                options.Binlog = BinlogOptions.FromGtid(GtidSet.Parse(gtidSet));

                // Start replication from the position
                options.Binlog = BinlogOptions.FromPosition("mysql-bin.000008", 195);

                // Start replication from last master position.
                // Useful when you are only interested in new changes.
                options.Binlog = BinlogOptions.FromEnd();

                // Start replication from first event of first available master binlog.
                // Note that binlog files by default have expiration time and deleted.
                options.Binlog = BinlogOptions.FromStart();
            });

            await client.ReplicateAsync(async (binlogEvent) =>
            {
                var state = client.State;

                if (binlogEvent is TableMapEvent tableMap)
                {
                    await HandleTableMapEvent(tableMap);
                }
                else if (binlogEvent is WriteRowsEvent writeRows)
                {
                    await HandleWriteRowsEvent(writeRows);
                }
                else if (binlogEvent is UpdateRowsEvent updateRows)
                {
                    await HandleUpdateRowsEvent(updateRows);
                }
                else if (binlogEvent is DeleteRowsEvent deleteRows)
                {
                    await HandleDeleteRowsEvent(deleteRows);
                }
                else
                {
                    await PrintEventAsync(binlogEvent);
                }
            });
        }
Exemple #7
0
        public void Test_MultipleIntervals_NotCollapsed()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:1-191:193-199:1000-1033");
            var uuidSet = gtidSet.UuidSets[Uuid.Parse(ServerUuid1)];

            Assert.Equal(3, uuidSet.Intervals.Count);
            Assert.Equal(new Interval(1, 191), uuidSet.Intervals[0]);
            Assert.Equal(new Interval(193, 199), uuidSet.Intervals[1]);
            Assert.Equal(new Interval(1000, 1033), uuidSet.Intervals[2]);
            Assert.Equal($"{ServerUuid1}:1-191:193-199:1000-1033", gtidSet.ToString());
        }
Exemple #8
0
        public void Test_MultipleIntervals_SomeCollapsed()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:1-191:192-199:1000-1033:1035-1036:1038-1039");
            var uuidSet = gtidSet.UuidSets[Uuid.Parse(ServerUuid1)];

            Assert.Equal(4, uuidSet.Intervals.Count);
            Assert.Equal(new Interval(1, 199), uuidSet.Intervals[0]);
            Assert.Equal(new Interval(1000, 1033), uuidSet.Intervals[1]);
            Assert.Equal(new Interval(1035, 1036), uuidSet.Intervals[2]);
            Assert.Equal(new Interval(1038, 1039), uuidSet.Intervals[3]);
            Assert.Equal($"{ServerUuid1}:1-199:1000-1033:1035-1036:1038-1039", gtidSet.ToString());
        }
Exemple #9
0
        public void Test_AddGtids_GtidsMerged()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:3-5");

            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 2));
            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 4));
            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 5));
            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 7));
            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid2), 9));
            gtidSet.AddGtid(new Gtid(Uuid.Parse(ServerUuid1), 0));

            Assert.Equal($"{ServerUuid1}:0:2-5:7,{ServerUuid2}:9", gtidSet.ToString());
        }
Exemple #10
0
        public void Test_MultiServerSetup_HasSingleIntervalsTrimsSpaces()
        {
            var gtidSet = GtidSet.Parse($"{ServerUuid1}:1-3:11:47-49, {ServerUuid2}:1-19:55:56-100");

            Assert.Equal(2, gtidSet.UuidSets.Values.Count);
            var uuidSet1 = gtidSet.UuidSets[Uuid.Parse(ServerUuid1)];
            var uuidSet2 = gtidSet.UuidSets[Uuid.Parse(ServerUuid2)];

            Assert.Equal(3, uuidSet1.Intervals.Count);
            Assert.Equal(new Interval(1, 3), uuidSet1.Intervals[0]);
            Assert.Equal(new Interval(11, 11), uuidSet1.Intervals[1]);
            Assert.Equal(new Interval(47, 49), uuidSet1.Intervals[2]);

            Assert.Equal(2, uuidSet2.Intervals.Count);
            Assert.Equal(new Interval(1, 19), uuidSet2.Intervals[0]);
            Assert.Equal(new Interval(55, 100), uuidSet2.Intervals[1]);

            Assert.Equal($"{ServerUuid1}:1-3:11:47-49,{ServerUuid2}:1-19:55-100", gtidSet.ToString());
        }
Exemple #11
0
 public void Test_ParseNullString_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => GtidSet.Parse(null).ToString());
 }