MCPcopy
hub / github.com/pingcap/tidb / TestBatchSplit

Function TestBatchSplit

br/pkg/restore/split/client_test.go:21–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestBatchSplit(t *testing.T) {
22 backup := maxBatchSplitSize
23 maxBatchSplitSize = 7
24 t.Cleanup(func() {
25 maxBatchSplitSize = backup
26 })
27
28 mockPDClient := NewMockPDClientForSplit()
29 keys := [][]byte{[]byte(""), []byte("")}
30 setRegions := mockPDClient.SetRegions(keys)
31 require.Len(t, setRegions, 1)
32 splitRegion := &RegionInfo{Region: setRegions[0]}
33 mockClient := &pdClient{
34 client: mockPDClient,
35 splitBatchKeyCnt: 100,
36 isRawKv: true, // make tests more readable
37 }
38 ctx := context.Background()
39
40 splitKeys := [][]byte{
41 []byte("ba"), []byte("bb"), []byte("bc"),
42 []byte("bd"), []byte("be"), []byte("bf"),
43 []byte("bg"), []byte("bh"),
44 }
45 expectedBatchSplitCnt := 3
46
47 _, err := mockClient.SplitWaitAndScatter(ctx, splitRegion, splitKeys)
48 require.NoError(t, err)
49
50 // check split ranges
51 regions, err := PaginateScanRegion(ctx, mockClient, []byte{'b'}, []byte{'c'}, 5)
52 require.NoError(t, err)
53 expected := [][]byte{[]byte("")}
54 expected = append(expected, splitKeys...)
55 expected = append(expected, []byte(""))
56 checkRegionsBoundaries(t, regions, expected)
57
58 require.EqualValues(t, expectedBatchSplitCnt, mockPDClient.splitRegions.count)
59 require.EqualValues(t, len(splitKeys), mockPDClient.scatterRegions.regionCount)
60}
61
62func TestSplitScatter(t *testing.T) {
63 backup := maxBatchSplitSize

Callers

nothing calls this directly

Calls 7

SetRegionsMethod · 0.95
SplitWaitAndScatterMethod · 0.95
NewMockPDClientForSplitFunction · 0.85
PaginateScanRegionFunction · 0.85
checkRegionsBoundariesFunction · 0.85
CleanupMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected