forked from pingcap/dm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharding_group_test.go
65 lines (52 loc) · 2.36 KB
/
sharding_group_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package syncer
import (
. "github.com/pingcap/check"
"github.com/siddontang/go-mysql/mysql"
"github.com/pingcap/dm/dm/config"
"github.com/pingcap/dm/pkg/binlog"
tcontext "github.com/pingcap/dm/pkg/context"
)
var _ = Suite(&testShardingGroupSuite{})
type testShardingGroupSuite struct {
}
func (t *testShardingGroupSuite) TestLowestFirstPosInGroups(c *C) {
cfg := &config.SubTaskConfig{
SourceID: "mysql-replica-01",
MetaSchema: "test",
Name: "checkpoint_ut",
}
ddls := []string{"DUMMY DDL"}
k := NewShardingGroupKeeper(tcontext.Background(), cfg)
g1 := NewShardingGroup(k.cfg.SourceID, k.shardMetaSchema, k.shardMetaTable, []string{"db1.tbl1", "db1.tbl2"}, nil, false, "")
pos1 := mysql.Position{Name: "mysql-bin.000002", Pos: 123}
endPos1 := mysql.Position{Name: "mysql-bin.000002", Pos: 456}
_, _, _, err := g1.TrySync("db1.tbl1", binlog.Location{Position: pos1}, binlog.Location{Position: endPos1}, ddls)
c.Assert(err, IsNil)
// lowest
g2 := NewShardingGroup(k.cfg.SourceID, k.shardMetaSchema, k.shardMetaTable, []string{"db2.tbl1", "db2.tbl2"}, nil, false, "")
pos2 := mysql.Position{Name: "mysql-bin.000001", Pos: 123}
endPos2 := mysql.Position{Name: "mysql-bin.000001", Pos: 456}
_, _, _, err = g2.TrySync("db2.tbl1", binlog.Location{Position: pos2}, binlog.Location{Position: endPos2}, ddls)
c.Assert(err, IsNil)
g3 := NewShardingGroup(k.cfg.SourceID, k.shardMetaSchema, k.shardMetaTable, []string{"db3.tbl1", "db3.tbl2"}, nil, false, "")
pos3 := mysql.Position{Name: "mysql-bin.000003", Pos: 123}
endPos3 := mysql.Position{Name: "mysql-bin.000003", Pos: 456}
_, _, _, err = g3.TrySync("db3.tbl1", binlog.Location{Position: pos3}, binlog.Location{Position: endPos3}, ddls)
c.Assert(err, IsNil)
k.groups["db1.tbl"] = g1
k.groups["db2.tbl"] = g2
k.groups["db3.tbl"] = g3
c.Assert(k.lowestFirstLocationInGroups().Position, DeepEquals, pos2)
}