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

Function TestBuildTableRangeIntHandle

pkg/distsql/request_builder_test.go:813–852  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

811}
812
813func TestBuildTableRangeIntHandle(t *testing.T) {
814 type Case struct {
815 ids []int64
816 trs []kv.KeyRange
817 }
818 low := codec.EncodeInt(nil, math.MinInt64)
819 high := kv.Key(codec.EncodeInt(nil, math.MaxInt64)).PrefixNext()
820 cases := []Case{
821 {ids: []int64{1}, trs: []kv.KeyRange{
822 {StartKey: tablecodec.EncodeRowKey(1, low), EndKey: tablecodec.EncodeRowKey(1, high)},
823 }},
824 {ids: []int64{1, 2, 3}, trs: []kv.KeyRange{
825 {StartKey: tablecodec.EncodeRowKey(1, low), EndKey: tablecodec.EncodeRowKey(1, high)},
826 {StartKey: tablecodec.EncodeRowKey(2, low), EndKey: tablecodec.EncodeRowKey(2, high)},
827 {StartKey: tablecodec.EncodeRowKey(3, low), EndKey: tablecodec.EncodeRowKey(3, high)},
828 }},
829 {ids: []int64{1, 3}, trs: []kv.KeyRange{
830 {StartKey: tablecodec.EncodeRowKey(1, low), EndKey: tablecodec.EncodeRowKey(1, high)},
831 {StartKey: tablecodec.EncodeRowKey(3, low), EndKey: tablecodec.EncodeRowKey(3, high)},
832 }},
833 }
834 for _, cs := range cases {
835 t.Log(cs)
836 tbl := &model.TableInfo{Partition: &model.PartitionInfo{Enable: true}}
837 for _, id := range cs.ids {
838 tbl.Partition.Definitions = append(tbl.Partition.Definitions,
839 model.PartitionDefinition{ID: id})
840 }
841 ranges, err := BuildTableRanges(tbl)
842 require.NoError(t, err)
843 require.Equal(t, cs.trs, ranges)
844 }
845
846 tbl := &model.TableInfo{ID: 7}
847 ranges, err := BuildTableRanges(tbl)
848 require.NoError(t, err)
849 require.Equal(t, []kv.KeyRange{
850 {StartKey: tablecodec.EncodeRowKey(7, low), EndKey: tablecodec.EncodeRowKey(7, high)},
851 }, ranges)
852}
853
854func TestBuildTableRangeCommonHandle(t *testing.T) {
855 type Case struct {

Callers

nothing calls this directly

Calls 7

EncodeIntFunction · 0.92
EncodeRowKeyFunction · 0.92
BuildTableRangesFunction · 0.85
PrefixNextMethod · 0.80
KeyMethod · 0.65
LogMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected