forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor_pkg_test.go
63 lines (53 loc) · 1.8 KB
/
executor_pkg_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
// Copyright 2016 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 executor
import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/tablecodec"
)
var _ = Suite(&testExecSuite{})
type testExecSuite struct {
}
type handleRange struct {
start int64
end int64
}
func getExpectedRanges(tid int64, hrs []*handleRange) []kv.KeyRange {
krs := make([]kv.KeyRange, 0, len(hrs))
for _, hr := range hrs {
startKey := tablecodec.EncodeRowKeyWithHandle(tid, hr.start)
endKey := tablecodec.EncodeRowKeyWithHandle(tid, hr.end)
krs = append(krs, kv.KeyRange{StartKey: startKey, EndKey: endKey})
}
return krs
}
func (s *testExecSuite) TestMergeHandles(c *C) {
handles := []int64{0, 2, 3, 4, 5, 10, 11, 100}
// Build expected key ranges.
hrs := make([]*handleRange, 0, len(handles))
hrs = append(hrs, &handleRange{start: 0, end: 1})
hrs = append(hrs, &handleRange{start: 2, end: 6})
hrs = append(hrs, &handleRange{start: 10, end: 12})
hrs = append(hrs, &handleRange{start: 100, end: 101})
expectedKrs := getExpectedRanges(1, hrs)
// Build key ranges.
krs := tableHandlesToKVRanges(1, handles)
// Compare key ranges and expected key ranges.
c.Assert(len(krs), Equals, len(expectedKrs))
for i, kr := range krs {
ekr := expectedKrs[i]
c.Assert(kr.StartKey, DeepEquals, ekr.StartKey)
c.Assert(kr.EndKey, DeepEquals, ekr.EndKey)
}
}