Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed Jan 27, 2024
1 parent 9902733 commit b17fb95
Showing 1 changed file with 41 additions and 99 deletions.
140 changes: 41 additions & 99 deletions cdc/sink/dmlsink/txn/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestPrepareDML(t *testing.T) {
},
{
Name: "a3",
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag,
Value: 2,
},
}, tableInfo),
Expand Down Expand Up @@ -1557,7 +1558,7 @@ func TestPrepareBatchDMLs(t *testing.T) {
func TestGroupRowsByType(t *testing.T) {
ctx := context.Background()
ms := newMySQLBackendWithoutDB(ctx)
tableInfoWithUniqueKey := model.BuildTableInfo("common_1", "uk_without_pk", []*model.Column{nil, {
tableInfoWithoutPK := model.BuildTableInfo("common_1", "uk_without_pk", []*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag | model.UniqueKeyFlag,
Expand All @@ -1566,15 +1567,6 @@ func TestGroupRowsByType(t *testing.T) {
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag | model.UniqueKeyFlag,
}}, [][]int{{1, 2}})
tableInfoWithoutUniqueKey := model.BuildTableInfo("common_1", "uk_without_pk", []*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag,
}}, [][]int{{1, 2}})
testCases := []struct {
name string
input []*model.RowChangedEvent
Expand All @@ -1586,74 +1578,50 @@ func TestGroupRowsByType(t *testing.T) {
{
StartTs: 418658114257813514,
CommitTs: 418658114257813515,
TableInfo: tableInfoWithUniqueKey,
TableInfo: tableInfoWithoutPK,
PreColumns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 1,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 1,
}}, tableInfoWithUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813514,
CommitTs: 418658114257813515,
TableInfo: tableInfoWithUniqueKey,
TableInfo: tableInfoWithoutPK,
PreColumns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813514,
CommitTs: 418658114257813515,
TableInfo: tableInfoWithUniqueKey,
TableInfo: tableInfoWithoutPK,
PreColumns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813514,
CommitTs: 418658114257813515,
TableInfo: tableInfoWithUniqueKey,
TableInfo: tableInfoWithoutPK,
PreColumns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithUniqueKey),
}}, tableInfoWithoutPK),
},
},
maxTxnRow: 2,
Expand All @@ -1664,101 +1632,76 @@ func TestGroupRowsByType(t *testing.T) {
{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag | model.HandleKeyFlag,
Value: 1,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 1,
}}, tableInfoWithoutUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithoutUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithoutUniqueKey),
}}, tableInfoWithoutPK),
},
{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a1",
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Flag: model.BinaryFlag | model.MultipleKeyFlag |
model.HandleKeyFlag | model.UniqueKeyFlag,
Name: "a3",
Value: 2,
}}, tableInfoWithoutUniqueKey),
}}, tableInfoWithoutPK),
},

{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Type: mysql.TypeLong,
Value: 2,
}, {
Name: "a3",
Type: mysql.TypeLong,
Value: 2,
}}, tableInfoWithoutUniqueKey),
}}, tableInfoWithoutPK),
},

{
StartTs: 418658114257813516,
CommitTs: 418658114257813517,
TableInfo: tableInfoWithoutUniqueKey,
TableInfo: tableInfoWithoutPK,
Columns: model.Columns2ColumnDatas([]*model.Column{nil, {
Name: "a1",
Value: 2,
}, {
Name: "a3",
Value: 2,
}}, tableInfoWithUniqueKey),
}}, tableInfoWithoutPK),
},
},
maxTxnRow: 4,
Expand All @@ -1767,11 +1710,10 @@ func TestGroupRowsByType(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
event := &dmlsink.TxnCallbackableEvent{
Event: &model.SingleTableTxn{Rows: testCases[0].input},
}
colums := tc.input[0].Columns
if len(colums) == 0 {
colums = tc.input[0].PreColumns
Event: &model.SingleTableTxn{
TableInfo: testCases[0].input[0].TableInfo,
Rows: testCases[0].input,
},
}
ms.cfg.MaxTxnRow = tc.maxTxnRow
inserts, updates, deletes := ms.groupRowsByType(event, event.Event.TableInfo, false)
Expand Down

0 comments on commit b17fb95

Please sign in to comment.