go.etcd.io/etcd@v3.3.27+incompatible/pkg/mock/mockstorage/storage_recorder.go (about) 1 // Copyright 2015 The etcd Authors 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 mockstorage 16 17 import ( 18 "github.com/coreos/etcd/pkg/testutil" 19 "github.com/coreos/etcd/raft" 20 "github.com/coreos/etcd/raft/raftpb" 21 ) 22 23 type storageRecorder struct { 24 testutil.Recorder 25 dbPath string // must have '/' suffix if set 26 } 27 28 func NewStorageRecorder(db string) *storageRecorder { 29 return &storageRecorder{&testutil.RecorderBuffered{}, db} 30 } 31 32 func NewStorageRecorderStream(db string) *storageRecorder { 33 return &storageRecorder{testutil.NewRecorderStream(), db} 34 } 35 36 func (p *storageRecorder) Save(st raftpb.HardState, ents []raftpb.Entry) error { 37 p.Record(testutil.Action{Name: "Save"}) 38 return nil 39 } 40 41 func (p *storageRecorder) SaveSnap(st raftpb.Snapshot) error { 42 if !raft.IsEmptySnap(st) { 43 p.Record(testutil.Action{Name: "SaveSnap"}) 44 } 45 return nil 46 } 47 48 func (p *storageRecorder) Release(st raftpb.Snapshot) error { 49 if !raft.IsEmptySnap(st) { 50 p.Record(testutil.Action{Name: "Release"}) 51 } 52 return nil 53 } 54 55 func (p *storageRecorder) Sync() error { 56 p.Record(testutil.Action{Name: "Sync"}) 57 return nil 58 } 59 60 func (p *storageRecorder) Close() error { return nil }