github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/chunk/pool_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package chunk 15 16 import ( 17 "testing" 18 19 "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 21 "github.com/whtcorpsinc/milevadb/types" 22 ) 23 24 var _ = check.Suite(&poolTestSuite{}) 25 26 type poolTestSuite struct{} 27 28 func (s *poolTestSuite) TestNewPool(c *check.C) { 29 pool := NewPool(1024) 30 c.Assert(pool.initCap, check.Equals, 1024) 31 c.Assert(pool.varLenDefCausPool, check.NotNil) 32 c.Assert(pool.fixLenDefCausPool4, check.NotNil) 33 c.Assert(pool.fixLenDefCausPool8, check.NotNil) 34 c.Assert(pool.fixLenDefCausPool16, check.NotNil) 35 c.Assert(pool.fixLenDefCausPool40, check.NotNil) 36 } 37 38 func (s *poolTestSuite) TestPoolGetChunk(c *check.C) { 39 initCap := 1024 40 pool := NewPool(initCap) 41 42 fieldTypes := []*types.FieldType{ 43 {Tp: allegrosql.TypeVarchar}, 44 {Tp: allegrosql.TypeJSON}, 45 {Tp: allegrosql.TypeFloat}, 46 {Tp: allegrosql.TypeNewDecimal}, 47 {Tp: allegrosql.TypeDouble}, 48 {Tp: allegrosql.TypeLonglong}, 49 //{Tp: allegrosql.TypeTimestamp}, 50 //{Tp: allegrosql.TypeDatetime}, 51 } 52 53 chk := pool.GetChunk(fieldTypes) 54 c.Assert(chk, check.NotNil) 55 c.Assert(chk.NumDefCauss(), check.Equals, len(fieldTypes)) 56 c.Assert(chk.defCausumns[0].elemBuf, check.IsNil) 57 c.Assert(chk.defCausumns[1].elemBuf, check.IsNil) 58 c.Assert(len(chk.defCausumns[2].elemBuf), check.Equals, getFixedLen(fieldTypes[2])) 59 c.Assert(len(chk.defCausumns[3].elemBuf), check.Equals, getFixedLen(fieldTypes[3])) 60 c.Assert(len(chk.defCausumns[4].elemBuf), check.Equals, getFixedLen(fieldTypes[4])) 61 c.Assert(len(chk.defCausumns[5].elemBuf), check.Equals, getFixedLen(fieldTypes[5])) 62 //c.Assert(len(chk.defCausumns[6].elemBuf), check.Equals, getFixedLen(fieldTypes[6])) 63 //c.Assert(len(chk.defCausumns[7].elemBuf), check.Equals, getFixedLen(fieldTypes[7])) 64 65 c.Assert(cap(chk.defCausumns[2].data), check.Equals, initCap*getFixedLen(fieldTypes[2])) 66 c.Assert(cap(chk.defCausumns[3].data), check.Equals, initCap*getFixedLen(fieldTypes[3])) 67 c.Assert(cap(chk.defCausumns[4].data), check.Equals, initCap*getFixedLen(fieldTypes[4])) 68 c.Assert(cap(chk.defCausumns[5].data), check.Equals, initCap*getFixedLen(fieldTypes[5])) 69 //c.Assert(cap(chk.defCausumns[6].data), check.Equals, initCap*getFixedLen(fieldTypes[6])) 70 //c.Assert(cap(chk.defCausumns[7].data), check.Equals, initCap*getFixedLen(fieldTypes[7])) 71 } 72 73 func (s *poolTestSuite) TestPoolPutChunk(c *check.C) { 74 initCap := 1024 75 pool := NewPool(initCap) 76 77 fieldTypes := []*types.FieldType{ 78 {Tp: allegrosql.TypeVarchar}, 79 {Tp: allegrosql.TypeJSON}, 80 {Tp: allegrosql.TypeFloat}, 81 {Tp: allegrosql.TypeNewDecimal}, 82 {Tp: allegrosql.TypeDouble}, 83 {Tp: allegrosql.TypeLonglong}, 84 {Tp: allegrosql.TypeTimestamp}, 85 {Tp: allegrosql.TypeDatetime}, 86 } 87 88 chk := pool.GetChunk(fieldTypes) 89 pool.PutChunk(fieldTypes, chk) 90 c.Assert(len(chk.defCausumns), check.Equals, 0) 91 } 92 93 func BenchmarkPoolChunkOperation(b *testing.B) { 94 pool := NewPool(1024) 95 96 fieldTypes := []*types.FieldType{ 97 {Tp: allegrosql.TypeVarchar}, 98 {Tp: allegrosql.TypeJSON}, 99 {Tp: allegrosql.TypeFloat}, 100 {Tp: allegrosql.TypeNewDecimal}, 101 {Tp: allegrosql.TypeDouble}, 102 {Tp: allegrosql.TypeLonglong}, 103 {Tp: allegrosql.TypeTimestamp}, 104 {Tp: allegrosql.TypeDatetime}, 105 } 106 107 b.ResetTimer() 108 b.RunParallel(func(pb *testing.PB) { 109 for pb.Next() { 110 pool.PutChunk(fieldTypes, pool.GetChunk(fieldTypes)) 111 } 112 }) 113 }