(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestGetSplitKeyPerRegion(t *testing.T) { |
| 334 | // test case moved from BR |
| 335 | sortedKeys := [][]byte{ |
| 336 | []byte("b"), |
| 337 | []byte("d"), |
| 338 | []byte("g"), |
| 339 | []byte("j"), |
| 340 | []byte("l"), |
| 341 | []byte("m"), |
| 342 | } |
| 343 | sortedRegions := []*RegionInfo{ |
| 344 | { |
| 345 | Region: &metapb.Region{ |
| 346 | Id: 1, |
| 347 | StartKey: []byte("a"), |
| 348 | EndKey: []byte("g"), |
| 349 | }, |
| 350 | }, |
| 351 | { |
| 352 | Region: &metapb.Region{ |
| 353 | Id: 2, |
| 354 | StartKey: []byte("g"), |
| 355 | EndKey: []byte("k"), |
| 356 | }, |
| 357 | }, |
| 358 | { |
| 359 | Region: &metapb.Region{ |
| 360 | Id: 3, |
| 361 | StartKey: []byte("k"), |
| 362 | EndKey: []byte("m"), |
| 363 | }, |
| 364 | }, |
| 365 | } |
| 366 | result := getSplitKeysOfRegions(sortedKeys, sortedRegions, false) |
| 367 | require.Equal(t, 3, len(result)) |
| 368 | require.Equal(t, [][]byte{[]byte("b"), []byte("d")}, result[sortedRegions[0]]) |
| 369 | require.Equal(t, [][]byte{[]byte("g"), []byte("j")}, result[sortedRegions[1]]) |
| 370 | require.Equal(t, [][]byte{[]byte("l")}, result[sortedRegions[2]]) |
| 371 | |
| 372 | // test case moved from lightning |
| 373 | tableID := int64(1) |
| 374 | keys := []int64{1, 10, 100, 1000, 10000, -1} |
| 375 | sortedRegions = make([]*RegionInfo, 0, len(keys)) |
| 376 | start := tablecodec.EncodeRowKeyWithHandle(tableID, kv.IntHandle(0)) |
| 377 | regionStart := codec.EncodeBytes([]byte{}, start) |
| 378 | for i, end := range keys { |
| 379 | var regionEndKey []byte |
| 380 | if end >= 0 { |
| 381 | endKey := tablecodec.EncodeRowKeyWithHandle(tableID, kv.IntHandle(end)) |
| 382 | regionEndKey = codec.EncodeBytes([]byte{}, endKey) |
| 383 | } |
| 384 | region := &RegionInfo{ |
| 385 | Region: &metapb.Region{ |
| 386 | Id: uint64(i), |
| 387 | StartKey: regionStart, |
| 388 | EndKey: regionEndKey, |
| 389 | }, |
| 390 | } |
nothing calls this directly
no test coverage detected