github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/db/util_test.go (about) 1 // Copyright 2022 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 db 16 17 import ( 18 "testing" 19 "time" 20 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/model" 26 "github.com/stretchr/testify/assert" 27 ) 28 29 type testRows struct { 30 id int 31 } 32 33 func (r *testRows) Length() int { return 1 } 34 func (r *testRows) Window(_, _ int) *testRows { return nil } 35 36 func createBlockFn[R any](_ R) *model.TimedSliceBlock[R] { 37 ts := types.BuildTS(time.Now().UTC().UnixNano(), 0) 38 return model.NewTimedSliceBlock[R](ts) 39 } 40 41 func TestAOT1(t *testing.T) { 42 aot := model.NewAOT( 43 10, 44 createBlockFn[*testRows], 45 func(a, b *model.TimedSliceBlock[*testRows]) bool { 46 return a.BornTS.Less(b.BornTS) 47 }) 48 for i := 0; i < 30; i++ { 49 rows := &testRows{id: i} 50 err := aot.Append(rows) 51 assert.NoError(t, err) 52 } 53 t.Log(aot.BlockCount()) 54 } 55 56 func TestAOT2(t *testing.T) { 57 schema := catalog.MockSchemaAll(14, 3) 58 factory := func(_ *containers.Batch) *model.BatchBlock { 59 id := common.NextGlobalSeqNum() 60 return model.NewBatchBlock( 61 id, 62 schema.Attrs(), 63 schema.Types(), 64 schema.Nullables(), 65 containers.Options{}) 66 } 67 aot := model.NewAOT( 68 10, 69 factory, 70 func(a, b *model.BatchBlock) bool { 71 return a.ID < b.ID 72 }) 73 defer aot.Close() 74 75 bat := catalog.MockBatch(schema, 42) 76 defer bat.Close() 77 78 assert.NoError(t, aot.Append(bat)) 79 t.Log(aot.BlockCount()) 80 assert.Equal(t, 5, aot.BlockCount()) 81 }