github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logstore/entry/entry_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 entry
    16  
    17  // import (
    18  // 	"bytes"
    19  // 	"testing"
    20  // 	"time"
    21  
    22  // 	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    23  // 	"github.com/stretchr/testify/assert"
    24  // )
    25  
    26  // func TestBase(t *testing.T) {
    27  // 	now := time.Now()
    28  // 	var buffer bytes.Buffer
    29  // 	buffer.WriteString("helloworld")
    30  // 	buffer.WriteString("helloworld")
    31  // 	buffer.WriteString("helloworld")
    32  // 	buf := buffer.Bytes()
    33  // 	for i := 0; i < 100000; i++ {
    34  // 		e := GetBase()
    35  // 		e.SetType(ETFlush)
    36  // 		n := common.LogAllocator.Alloc(30)
    37  // 		copy(n.GetBuf(), buf)
    38  // 		err := e.UnmarshalFromNode(n, true)
    39  // 		assert.Nil(t, err)
    40  // 		e.Free()
    41  // 	}
    42  // 	t.Logf("takes %s", time.Since(now))
    43  // 	t.Log(common.LogAllocator.String())
    44  // }
    45  
    46  // func TestInfoMarshal1(t *testing.T) {
    47  // 	info := &Info{
    48  // 		Group: GTCKp,
    49  // 		TxnId: 35,
    50  // 		Checkpoints: []CkpRanges{
    51  // 			{
    52  // 				Group: GTNoop,
    53  // 				Ranges: &common.ClosedIntervals{
    54  // 					Intervals: []*common.ClosedInterval{{Start: 1, End: 5}, {Start: 7, End: 7}}}},
    55  // 			{
    56  // 				Group: GTUncommit,
    57  // 				Ranges: &common.ClosedIntervals{
    58  // 					Intervals: []*common.ClosedInterval{{Start: 3, End: 5}, {Start: 6, End: 7}}},
    59  // 				Command: map[uint64]CommandInfo{3: {
    60  // 					CommandIds: []uint32{2, 4, 1},
    61  // 					Size:       5,
    62  // 				}},
    63  // 			}},
    64  // 		Uncommits: 5,
    65  // 		GroupLSN:  1,
    66  // 	}
    67  // 	buf := info.Marshal()
    68  // 	info2 := Unmarshal(buf)
    69  // 	checkInfoEqual(t, info, info2)
    70  // }
    71  // func TestInfoMarshal2(t *testing.T) {
    72  // 	info := &Info{}
    73  // 	buf := info.Marshal()
    74  // 	info2 := Unmarshal(buf)
    75  // 	checkInfoEqual(t, info, info2)
    76  // }
    77  
    78  // func TestInfoMarshal3(t *testing.T) {
    79  // 	info := &Info{
    80  // 		Group: GTCKp,
    81  // 		TxnId: 35,
    82  // 		Checkpoints: []CkpRanges{
    83  // 			{
    84  // 				Group: GTNoop,
    85  // 				Ranges: &common.ClosedIntervals{
    86  // 					Intervals: []*common.ClosedInterval{{Start: 1, End: 5}, {Start: 7, End: 7}}}},
    87  // 			{
    88  // 				Group: GTUncommit}},
    89  // 		// Ranges: &common.ClosedIntervals{}}},
    90  // 		Uncommits: 5,
    91  // 		GroupLSN:  1,
    92  // 	}
    93  // 	buf := info.Marshal()
    94  // 	info2 := Unmarshal(buf)
    95  // 	checkInfoEqual(t, info, info2)
    96  // }
    97  
    98  // func checkInfoEqual(t *testing.T, info, info2 *Info) {
    99  // 	assert.Equal(t, info.Group, info2.Group)
   100  // 	assert.Equal(t, info.TxnId, info2.TxnId)
   101  // 	assert.Equal(t, len(info.Checkpoints), len(info2.Checkpoints))
   102  // 	for i, ckps1 := range info.Checkpoints {
   103  // 		ckps2 := info2.Checkpoints[i]
   104  // 		assert.Equal(t, ckps1.Group, ckps2.Group)
   105  // 		if ckps1.Ranges == nil {
   106  // 			assert.Equal(t, len(ckps2.Ranges.Intervals), 0)
   107  // 		} else {
   108  // 			assert.Equal(t, len(ckps1.Ranges.Intervals), len(ckps2.Ranges.Intervals))
   109  // 			for j, interval1 := range ckps1.Ranges.Intervals {
   110  // 				interval2 := ckps2.Ranges.Intervals[j]
   111  // 				assert.Equal(t, interval1.Start, interval2.Start)
   112  // 				assert.Equal(t, interval1.End, interval2.End)
   113  // 			}
   114  // 		}
   115  // 		assert.Equal(t, len(ckps1.Command), len(ckps2.Command))
   116  // 		for lsn, cmdInfo := range ckps1.Command {
   117  // 			cmdInfo2 := ckps2.Command[lsn]
   118  // 			assert.Equal(t, len(cmdInfo.CommandIds), len(cmdInfo2.CommandIds))
   119  // 			for k, cmdid := range cmdInfo.CommandIds {
   120  // 				assert.Equal(t, cmdid, cmdInfo2.CommandIds[k])
   121  // 			}
   122  // 			assert.Equal(t, cmdInfo.Size, cmdInfo2.Size)
   123  // 		}
   124  // 	}
   125  // 	assert.Equal(t, info.Uncommits, info2.Uncommits)
   126  // 	assert.Equal(t, info.GroupLSN, info2.GroupLSN)
   127  // }