Skip to content

Commit

Permalink
add unit test for rowHashMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway committed Aug 30, 2019
1 parent 8387cb3 commit 63a0c3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion executor/hash_table.go
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions 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)
}

0 comments on commit 63a0c3f

Please sign in to comment.