github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/closedts/container/noop.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package container 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts" 17 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/ctpb" 18 "github.com/cockroachdb/cockroach/pkg/roachpb" 19 "github.com/cockroachdb/cockroach/pkg/settings/cluster" 20 "github.com/cockroachdb/cockroach/pkg/util/hlc" 21 "github.com/cockroachdb/cockroach/pkg/util/stop" 22 "github.com/cockroachdb/errors" 23 ) 24 25 type noopEverything struct{} 26 27 // NoopContainer returns a Container for which all parts of the subsystem are 28 // mocked out. This is for usage in testing where there just needs to be a 29 // structure that stays out of the way. 30 // 31 // The returned container will behave correctly. It will never allow any time- 32 // stamps to be closed out, so it never makes any promises; it doesn't use any 33 // locking and it does not consume any (nontrivial) resources. 34 func NoopContainer() *Container { 35 return &Container{ 36 Config: Config{ 37 Settings: cluster.MakeTestingClusterSettings(), 38 Stopper: stop.NewStopper(), 39 Clock: func(roachpb.NodeID) (hlc.Timestamp, ctpb.Epoch, error) { 40 return hlc.Timestamp{}, 0, errors.New("closed timestamps disabled for testing") 41 }, 42 Refresh: func(...roachpb.RangeID) {}, 43 Dialer: noopEverything{}, 44 }, 45 Tracker: noopEverything{}, 46 Storage: noopEverything{}, 47 Provider: noopEverything{}, 48 Server: noopEverything{}, 49 Clients: noopEverything{}, 50 noop: true, 51 } 52 } 53 54 func (noopEverything) Get(client ctpb.InboundClient) error { 55 return errors.New("closed timestamps disabled") 56 } 57 func (noopEverything) Close( 58 next hlc.Timestamp, expCurEpoch ctpb.Epoch, 59 ) (hlc.Timestamp, map[roachpb.RangeID]ctpb.LAI, bool) { 60 return hlc.Timestamp{}, nil, false 61 } 62 func (noopEverything) Track(ctx context.Context) (hlc.Timestamp, closedts.ReleaseFunc) { 63 return hlc.Timestamp{}, func(context.Context, ctpb.Epoch, roachpb.RangeID, ctpb.LAI) {} 64 } 65 func (noopEverything) VisitAscending(roachpb.NodeID, func(ctpb.Entry) (done bool)) {} 66 func (noopEverything) VisitDescending(roachpb.NodeID, func(ctpb.Entry) (done bool)) {} 67 func (noopEverything) Add(roachpb.NodeID, ctpb.Entry) {} 68 func (noopEverything) Clear() {} 69 func (noopEverything) Notify(roachpb.NodeID) chan<- ctpb.Entry { 70 return nil // will explode when used, but nobody would use this 71 } 72 func (noopEverything) Subscribe(context.Context, chan<- ctpb.Entry) {} 73 func (noopEverything) Start() {} 74 func (noopEverything) MaxClosed( 75 roachpb.NodeID, roachpb.RangeID, ctpb.Epoch, ctpb.LAI, 76 ) hlc.Timestamp { 77 return hlc.Timestamp{} 78 } 79 func (noopEverything) Request(roachpb.NodeID, roachpb.RangeID) {} 80 func (noopEverything) EnsureClient(roachpb.NodeID) {} 81 func (noopEverything) Dial(context.Context, roachpb.NodeID) (ctpb.Client, error) { 82 return nil, errors.New("closed timestamps disabled") 83 } 84 func (noopEverything) Ready(roachpb.NodeID) bool { return false }