github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/updates/command_test.go (about) 1 // Copyright 2021 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 updates 16 17 import ( 18 "bytes" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnbase" 26 "github.com/stretchr/testify/assert" 27 ) 28 29 func TestCompactBlockCmd(t *testing.T) { 30 defer testutils.AfterTest(t)() 31 schema := catalog.MockSchema(1, 0) 32 c := catalog.MockCatalog(nil) 33 defer c.Close() 34 35 db, _ := c.CreateDBEntry("db", "", nil) 36 table, _ := db.CreateTableEntry(schema, nil, nil) 37 seg, _ := table.CreateSegment(nil, catalog.ES_Appendable, nil) 38 blk, _ := seg.CreateBlock(nil, catalog.ES_Appendable, nil) 39 40 controller := NewMVCCHandle(blk) 41 42 ts := types.NextGlobalTsForTest() 43 //node := MockAppendNode(341, 0, 2515, controller) 44 node := MockAppendNode(ts, 0, 2515, controller) 45 cmd := NewAppendCmd(1, node) 46 47 var w bytes.Buffer 48 _, err := cmd.WriteTo(&w) 49 assert.Nil(t, err) 50 51 buf := w.Bytes() 52 r := bytes.NewBuffer(buf) 53 54 cmd2, _, err := txnbase.BuildCommandFrom(r) 55 assert.Nil(t, err) 56 checkAppendCmdIsEqual(t, cmd, cmd2.(*UpdateCmd)) 57 } 58 59 func checkAppendCmdIsEqual(t *testing.T, cmd1, cmd2 *UpdateCmd) { 60 assert.Equal(t, txnbase.CmdAppend, cmd1.GetType()) 61 assert.Equal(t, txnbase.CmdAppend, cmd2.GetType()) 62 assert.Equal(t, cmd1.append.maxRow, cmd2.append.maxRow) 63 }