github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/db/test/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 test 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(id, schema.Attrs(), schema.Types(), containers.Options{}) 61 } 62 aot := model.NewAOT( 63 10, 64 factory, 65 func(a, b *model.BatchBlock) bool { 66 return a.ID < b.ID 67 }) 68 defer aot.Close() 69 70 bat := catalog.MockBatch(schema, 42) 71 defer bat.Close() 72 73 assert.NoError(t, aot.Append(bat)) 74 t.Log(aot.BlockCount()) 75 assert.Equal(t, 5, aot.BlockCount()) 76 rows := 0 77 fn := func(block *model.BatchBlock) bool { 78 rows += block.Length() 79 return true 80 } 81 aot.Scan(fn) 82 assert.Equal(t, 42, rows) 83 }