github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/disttae/reader_test.go (about) 1 // Copyright 2023 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package disttae 16 17 import ( 18 "context" 19 "math/rand" 20 "testing" 21 22 "github.com/matrixorigin/matrixone/pkg/objectio" 23 "github.com/matrixorigin/matrixone/pkg/perfcounter" 24 "github.com/stretchr/testify/require" 25 ) 26 27 func TestGatherStats(t *testing.T) { 28 r := new(blockReader) 29 ctx, cancel := context.WithCancel(context.Background()) 30 defer cancel() 31 32 r.ctx = ctx 33 r.ctx, _, _ = r.prepareGatherStats() 34 35 hitNum, readNum := rand.Int63(), rand.Int63() 36 perfcounter.Update(r.ctx, func(c *perfcounter.CounterSet) { 37 c.FileService.Cache.Read.Add(readNum) 38 c.FileService.Cache.Hit.Add(hitNum) 39 c.FileService.Cache.Memory.Read.Add(readNum) 40 c.FileService.Cache.Memory.Hit.Add(hitNum) 41 }, nil) 42 43 r.gatherStats(0, 0) 44 45 hit, total := objectio.BlkReadStats.BlkCacheHitStats.Export() 46 if hitNum < readNum { 47 require.Equal(t, hit, int64(0)) 48 require.Equal(t, total, int64(1)) 49 } else { 50 require.Equal(t, hit, int64(1)) 51 require.Equal(t, total, int64(1)) 52 } 53 54 hit, total = objectio.BlkReadStats.EntryCacheHitStats.Export() 55 require.Equal(t, hit, hitNum) 56 require.Equal(t, total, readNum) 57 }