|
6 | 6 | package mysql
|
7 | 7 |
|
8 | 8 | import (
|
| 9 | + "math" |
9 | 10 | "testing"
|
10 | 11 |
|
11 | 12 | "github.com/openark/golib/log"
|
@@ -52,3 +53,46 @@ func TestBinlogCoordinatesAsKey(t *testing.T) {
|
52 | 53 |
|
53 | 54 | test.S(t).ExpectEquals(len(m), 3)
|
54 | 55 | }
|
| 56 | + |
| 57 | +func TestIsLogPosOverflowBeyond4Bytes(t *testing.T) { |
| 58 | + { |
| 59 | + var preCoordinates *BinlogCoordinates |
| 60 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 10321, EventSize: 1100} |
| 61 | + test.S(t).ExpectFalse(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 62 | + } |
| 63 | + { |
| 64 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: 1100, EventSize: 1100} |
| 65 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1100)), EventSize: 1100} |
| 66 | + test.S(t).ExpectFalse(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 67 | + } |
| 68 | + { |
| 69 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00016", LogPos: 1100, EventSize: 1100} |
| 70 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1100)), EventSize: 1100} |
| 71 | + test.S(t).ExpectFalse(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 72 | + } |
| 73 | + { |
| 74 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: math.MaxUint32 - 1001, EventSize: 1000} |
| 75 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1000)), EventSize: 1000} |
| 76 | + test.S(t).ExpectFalse(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 77 | + } |
| 78 | + { |
| 79 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: math.MaxUint32 - 1000, EventSize: 1000} |
| 80 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1000)), EventSize: 1000} |
| 81 | + test.S(t).ExpectFalse(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 82 | + } |
| 83 | + { |
| 84 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: math.MaxUint32 - 999, EventSize: 1000} |
| 85 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1000)), EventSize: 1000} |
| 86 | + test.S(t).ExpectTrue(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 87 | + } |
| 88 | + { |
| 89 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(math.MaxUint32 - 500)), EventSize: 1000} |
| 90 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1000)), EventSize: 1000} |
| 91 | + test.S(t).ExpectTrue(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 92 | + } |
| 93 | + { |
| 94 | + preCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: math.MaxUint32, EventSize: 1000} |
| 95 | + curCoordinates := &BinlogCoordinates{LogFile: "mysql-bin.00017", LogPos: int64(uint32(preCoordinates.LogPos + 1000)), EventSize: 1000} |
| 96 | + test.S(t).ExpectTrue(curCoordinates.IsLogPosOverflowBeyond4Bytes(preCoordinates)) |
| 97 | + } |
| 98 | +} |
0 commit comments