github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logstore/driver/logservicedriver/driver_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 logservicedriver 16 17 import ( 18 // "sync" 19 "testing" 20 // "github.com/lni/vfs" 21 // "github.com/matrixorigin/matrixone/pkg/logservice" 22 // "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/driver/entry" 23 // "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils" 24 // "github.com/panjf2000/ants/v2" 25 // // "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/entry" 26 // "github.com/stretchr/testify/assert" 27 ) 28 29 // func initTest(t *testing.T) (*logservice.Service, *logservice.ClientConfig) { 30 // fs := vfs.NewStrictMem() 31 // service, ccfg, err := logservice.NewTestService(fs) 32 // assert.NoError(t, err) 33 // return service, &ccfg 34 // } 35 36 // func restartDriver(t *testing.T, d *LogServiceDriver) *LogServiceDriver { 37 // assert.NoError(t, d.Close()) 38 // t.Log("Addr:") 39 // // preAddr:=d.addr 40 // for lsn, intervals := range d.addr { 41 // t.Logf("%d %v", lsn, intervals) 42 // } 43 // // preLsns:=d.validLsn 44 // t.Logf("Valid lsn: %v", d.validLsn) 45 // t.Logf("Driver Lsn %d, Syncing %d, Synced %d", d.driverLsn, d.syncing, d.synced) 46 // t.Logf("Truncated %d", d.truncating) 47 // t.Logf("LSTruncated %d", d.truncatedLogserviceLsn) 48 // d = NewLogServiceDriver(d.config) 49 // tempLsn := uint64(0) 50 // err := d.Replay(func(e *entry.Entry) { 51 // if e.Lsn <= tempLsn { 52 // panic("logic err") 53 // } 54 // tempLsn = e.Lsn 55 // }) 56 // assert.NoError(t, err) 57 // t.Log("Addr:") 58 // for lsn, intervals := range d.addr { 59 // t.Logf("%d %v", lsn, intervals) 60 // } 61 // // assert.Equal(t,len(preAddr),len(d.addr)) 62 // // for lsn,intervals := range preAddr{ 63 // // replayedInterval,ok:=d.addr[lsn] 64 // // assert.True(t,ok) 65 // // assert.Equal(t,intervals.Intervals[0].Start,replayedInterval.Intervals[0].Start) 66 // // assert.Equal(t,intervals.Intervals[0].End,replayedInterval.Intervals[0].End) 67 // // } 68 // t.Logf("Valid lsn: %v", d.validLsn) 69 // // assert.Equal(t,preLsns.GetCardinality(),d.validLsn.GetCardinality()) 70 // t.Logf("Driver Lsn %d, Syncing %d, Synced %d", d.driverLsn, d.syncing, d.synced) 71 // t.Logf("Truncated %d", d.truncating) 72 // t.Logf("LSTruncated %d", d.truncatedLogserviceLsn) 73 // return d 74 // } 75 76 func TestAppendRead(t *testing.T) { 77 // service, ccfg := initTest(t) 78 // defer service.Close() 79 80 // cfg := NewTestConfig(ccfg) 81 // driver := NewLogServiceDriver(cfg) 82 83 // entryCount := 100 84 // wg := &sync.WaitGroup{} 85 // worker, _ := ants.NewPool(10) 86 // entries := make([]*entry.Entry, entryCount) 87 // appendfn := func(i int) func() { 88 // return func() { 89 // e := entry.MockEntry() 90 // driver.Append(e) 91 // entries[i] = e 92 // wg.Done() 93 // } 94 // } 95 96 // reanfn := func(i int) func() { 97 // return func() { 98 // e := entries[i] 99 // e.WaitDone() 100 // e2, err := driver.Read(e.Lsn) 101 // assert.NoError(t, err) 102 // assert.Equal(t, e2.Lsn, e.Lsn) 103 // _, lsn1 := e.Entry.GetLsn() 104 // _, lsn2 := e2.Entry.GetLsn() 105 // assert.Equal(t, lsn1, lsn2) 106 // wg.Done() 107 // e2.Entry.Free() 108 // } 109 // } 110 111 // for i := 0; i < entryCount; i++ { 112 // wg.Add(1) 113 // worker.Submit(appendfn(i)) 114 // } 115 // wg.Wait() 116 117 // for i := 0; i < entryCount; i++ { 118 // wg.Add(1) 119 // worker.Submit(reanfn(i)) 120 // } 121 // wg.Wait() 122 123 // driver = restartDriver(t, driver) 124 125 // for i := 0; i < entryCount; i++ { 126 // wg.Add(1) 127 // worker.Submit(reanfn(i)) 128 // } 129 // wg.Wait() 130 131 // for _, e := range entries { 132 // e.Entry.Free() 133 // } 134 135 // driver.Close() 136 } 137 138 func TestTruncate(t *testing.T) { 139 // service, ccfg := initTest(t) 140 // defer service.Close() 141 142 // cfg := NewTestConfig(ccfg) 143 // driver := NewLogServiceDriver(cfg) 144 145 // entryCount := 10 146 // entries := make([]*entry.Entry, entryCount) 147 // wg := &sync.WaitGroup{} 148 // worker, _ := ants.NewPool(20) 149 // truncatefn := func(i int, dr *LogServiceDriver) func() { 150 // return func() { 151 // e := entries[i] 152 // assert.NoError(t, e.WaitDone()) 153 // assert.NoError(t, dr.Truncate(e.Lsn)) 154 // testutils.WaitExpect(4000, func() bool { 155 // trucated, err := dr.GetTruncated() 156 // assert.NoError(t, err) 157 // return trucated >= e.Lsn 158 // }) 159 // truncated, err := dr.GetTruncated() 160 // assert.NoError(t, err) 161 // assert.GreaterOrEqual(t, truncated, e.Lsn) 162 // wg.Done() 163 // } 164 // } 165 // appendfn := func(i int, dr *LogServiceDriver) func() { 166 // return func() { 167 // e := entry.MockEntry() 168 // dr.Append(e) 169 // entries[i] = e 170 // worker.Submit(truncatefn(i, dr)) 171 // } 172 // } 173 174 // for i := 0; i < entryCount; i++ { 175 // wg.Add(1) 176 // worker.Submit(appendfn(i, driver)) 177 // } 178 179 // wg.Wait() 180 181 // // driver = restartDriver(t, driver) 182 183 // // for i := 0; i < entryCount; i++ { 184 // // wg.Add(1) 185 // // worker.Submit(appendfn(i, driver)) 186 // // } 187 188 // assert.NoError(t, driver.Close()) 189 }