github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/aggregator/integration/clock.go (about) 1 //go:build integration 2 // +build integration 3 4 // Copyright (c) 2021 Uber Technologies, Inc. 5 // 6 // Permission is hereby granted, free of charge, to any person obtaining a copy 7 // of this software and associated documentation files (the "Software"), to deal 8 // in the Software without restriction, including without limitation the rights 9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 // copies of the Software, and to permit persons to whom the Software is 11 // furnished to do so, subject to the following conditions: 12 // 13 // The above copyright notice and this permission notice shall be included in 14 // all copies or substantial portions of the Software. 15 // 16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 // THE SOFTWARE. 23 24 package integration 25 26 import ( 27 "sync" 28 "time" 29 30 "github.com/m3db/m3/src/x/clock" 31 ) 32 33 type testClock struct { 34 sync.RWMutex 35 36 now time.Time 37 } 38 39 func newTestClock(now time.Time) *testClock { 40 return &testClock{ 41 now: now, 42 } 43 } 44 45 func (c *testClock) Now() time.Time { 46 c.RLock() 47 defer c.RUnlock() 48 return c.now 49 } 50 51 func (c *testClock) SetNow(now time.Time) { 52 c.Lock() 53 defer c.Unlock() 54 c.now = now 55 } 56 57 func (c *testClock) Options() clock.Options { 58 return clock.NewOptions().SetNowFn(c.Now) 59 }