From 63a0c3f89cf6f84d20fc0d547a816429f084f2f9 Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Fri, 30 Aug 2019 17:52:06 +0800 Subject: [PATCH] add unit test for rowHashMap. --- executor/hash_table.go | 5 ++++- executor/hash_table_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 executor/hash_table_test.go diff --git a/executor/hash_table.go b/executor/hash_table.go index 5088e5d41ca9f..d2bbc7dd80dae 100644 --- a/executor/hash_table.go +++ b/executor/hash_table.go @@ -161,7 +161,10 @@ type entryStore struct { func (es *entryStore) init() { es.slices = [][]entry{make([]entry, 0, initialEntrySliceLen)} // Reserve the first empty entry, so entryAddr{} can represent nullEntryAddr. - es.put(entry{}) + reserved := es.put(entry{}) + if reserved != nullEntryAddr { + panic("entryStore: first entry is not nullEntryAddr") + } } func (es *entryStore) put(e entry) entryAddr { diff --git a/executor/hash_table_test.go b/executor/hash_table_test.go new file mode 100644 index 0000000000000..e1ef48eb33a08 --- /dev/null +++ b/executor/hash_table_test.go @@ -0,0 +1,37 @@ +package executor + +import ( + . "github.com/pingcap/check" + "github.com/pingcap/tidb/util/chunk" +) + +func (s *pkgTestSuite) TestRowHashMap(c *C) { + m := newRowHashMap() + m.Put(1, chunk.RowPtr{ChkIdx: 1, RowIdx: 1}) + c.Check(m.Get(1), DeepEquals, []chunk.RowPtr{{1, 1}}) + + rawData := map[uint64][]chunk.RowPtr{} + for i := uint64(0); i < 10; i++ { + for j := uint64(0); j < initialEntrySliceLen*i; j++ { + rawData[i] = append(rawData[i], chunk.RowPtr{ChkIdx: uint32(i), RowIdx: uint32(j)}) + } + } + m = newRowHashMap() + // put all rawData into m vertically + for j := uint64(0); j < initialEntrySliceLen*9; j++ { + for i := 9; i >= 0; i-- { + i := uint64(i) + if !(j < initialEntrySliceLen*i) { + break + } + m.Put(i, rawData[i][j]) + } + } + // check + totalCount := 0 + for i := uint64(0); i < 10; i++ { + totalCount += len(rawData[i]) + c.Check(m.Get(i), DeepEquals, rawData[i]) + } + c.Check(m.Len(), Equals, totalCount) +}