tm

package
v0.0.0-...-d504ea7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns time in UnixNanos
	Now() int64
	// Uptime returns the time since the clock was initialized.
	Uptime() int64
}

Clock is used by Kronos for getting current time

func NewMonotonicClock

func NewMonotonicClock() Clock

NewMonotonicClock returns an instance of MonotonicClock

func NewMonotonicClockWithOffset

func NewMonotonicClockWithOffset(offset int64, uptimeOffset int64) Clock

NewMonotonicClockWithOffset returns an instance of MonotonicClock offset is added to startTime when computing Now()

type DriftingClock

type DriftingClock struct {
	// contains filtered or unexported fields
}

DriftingClock is an implementation of Clock which can be used to simulate drifts and jumps in clocks

func NewDriftingClock

func NewDriftingClock(driftFactor float64, offset time.Duration) *DriftingClock

NewDriftingClock returns an instance of DriftingClock

func (*DriftingClock) Now

func (t *DriftingClock) Now() int64

Now returns the time at the given moment assuming drift and offset as described by clockConfig. Returned time should be offset + lastDriftedTime + (currentActualTime - lastActualTime)*driftFactor = lastDriftedTime + (currentActualTime - lastActualTime) + (currentActualTime - lastActualTime) * (driftFactor - 1) + offset The drift part is broken to reduce errors due to precision of driftFactor.

func (*DriftingClock) UpdateDriftConfig

func (t *DriftingClock) UpdateDriftConfig(dtc *kronospb.DriftTimeConfig)

UpdateDriftConfig changes the driftFactor according to dtc and jumps the clock by the the offset in dtc.

func (*DriftingClock) Uptime

func (t *DriftingClock) Uptime() int64

type ManualClock

type ManualClock struct {
	// contains filtered or unexported fields
}

ManualClock is used in tests to mock time

func NewManualClock

func NewManualClock() *ManualClock

NewManualClock returns an instance of ManualClock

func (*ManualClock) AdvanceTime

func (c *ManualClock) AdvanceTime(t time.Duration)

AdvanceTime progesses time by the given duration

func (*ManualClock) Now

func (c *ManualClock) Now() int64

Now returns the manually set time

func (*ManualClock) SetTime

func (c *ManualClock) SetTime(t int64)

SetTime sets the time of the ManualClock

func (*ManualClock) SetUptime

func (c *ManualClock) SetUptime(t int64)

SetUptime sets the time of the ManualClock

func (*ManualClock) Uptime

func (c *ManualClock) Uptime() int64

Now returns the manually set time

type MonotonicClock

type MonotonicClock struct {
	// contains filtered or unexported fields
}

MonotonicClock is an implementation of Clock which is immune to clock jumps

func (*MonotonicClock) Now

func (c *MonotonicClock) Now() int64

Now takes adds the elapsed time from a fixed point of reference to generate a new time

func (*MonotonicClock) Uptime

func (c *MonotonicClock) Uptime() int64

type UpdateDriftClockServer

type UpdateDriftClockServer struct {
	Clock *DriftingClock
}

UpdateDriftClockServer server is used to handle grpc calls to change the drift config of drifting clock

func NewUpdateDriftClockServer

func NewUpdateDriftClockServer(startConfig *kronospb.DriftTimeConfig) *UpdateDriftClockServer

NewUpdateDriftClockServer returns an instance of UpdateDriftClockServer

func (*UpdateDriftClockServer) UpdateDriftConfig

func (ds *UpdateDriftClockServer) UpdateDriftConfig(
	ctx context.Context, dtc *kronospb.DriftTimeConfig,
) (*kronospb.DriftTimeResponse, error)

UpdateDriftConfig is the method to update the DriftConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL