-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd7ca94
commit d3e15ac
Showing
4 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package gtids | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGTIDDiff(t *testing.T) { | ||
sourceGTID := ParseGtidSet("00000000-0000-0000-0000-000000000000:1-100,11111111-1111-1111-1111-111111111111:1-100") | ||
|
||
// equal | ||
replicaGTID := ParseGtidSet("00000000-0000-0000-0000-000000000000:1-100,11111111-1111-1111-1111-111111111111:1-100") | ||
diff, err := GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "replica gtid equal source", diff) | ||
|
||
replicaGTID = ParseGtidSet("11111111-1111-1111-1111-111111111111:1-100,00000000-0000-0000-0000-000000000000:1-100") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "replica gtid equal source", diff) | ||
|
||
// source ahead | ||
replicaGTID = ParseGtidSet("00000000-0000-0000-0000-000000000000:1-90,11111111-1111-1111-1111-111111111111:1-100") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "source ahead on: 00000000-0000-0000-0000-000000000000:91-100", diff) | ||
|
||
replicaGTID = ParseGtidSet("00000000-0000-0000-0000-000000000000:1-90,11111111-1111-1111-1111-111111111111:1-90") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "source ahead on: 00000000-0000-0000-0000-000000000000:91-100,11111111-1111-1111-1111-111111111111:91-100", diff) | ||
|
||
// replica ahead | ||
replicaGTID = ParseGtidSet("00000000-0000-0000-0000-000000000000:1-110,11111111-1111-1111-1111-111111111111:1-100") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "replica ahead on: 00000000-0000-0000-0000-000000000000:101-110", diff) | ||
|
||
// split brain | ||
replicaGTID = ParseGtidSet("00000000-0000-0000-0000-000000000000:1-90,11111111-1111-1111-1111-111111111111:1-110") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "split brain! source ahead on: 00000000-0000-0000-0000-000000000000:91-100; replica ahead on: 11111111-1111-1111-1111-111111111111:101-110", diff) | ||
|
||
replicaGTID = ParseGtidSet("00000000-0000-0000-0000-000000000000:1-100,22222222-2222-2222-2222-222222222222:1-110") | ||
diff, err = GTIDDiff(replicaGTID, sourceGTID) | ||
require.NoError(t, err) | ||
require.Equal(t, "split brain! source ahead on: 11111111-1111-1111-1111-111111111111:1-100; replica ahead on: 22222222-2222-2222-2222-222222222222:1-110", diff) | ||
} |