本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.Timestamp.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Timestamp.Equal方法的具体用法?Golang Timestamp.Equal怎么用?Golang Timestamp.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/roachpb.Timestamp
的用法示例。
在下文中一共展示了Timestamp.Equal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestClock
// TestClock performs a complete test of all basic phenomena,
// including backward jumps in local physical time and clock offset.
func TestClock(t *testing.T) {
m := NewManualClock(0)
c := NewClock(m.UnixNano)
c.SetMaxOffset(1000)
expectedHistory := []struct {
// The physical time that this event should take place at.
wallClock int64
event Event
// If this is a receive event, this holds the "input" timestamp.
input *roachpb.Timestamp
// The expected timestamp generated from the input.
expected roachpb.Timestamp
}{
// A few valid steps to warm up.
{5, SEND, nil, roachpb.Timestamp{WallTime: 5, Logical: 0}},
{6, SEND, nil, roachpb.Timestamp{WallTime: 6, Logical: 0}},
{10, RECV, &roachpb.Timestamp{WallTime: 10, Logical: 5}, roachpb.Timestamp{WallTime: 10, Logical: 6}},
// Our clock mysteriously jumps back.
{7, SEND, nil, roachpb.Timestamp{WallTime: 10, Logical: 7}},
// Wall clocks coincide, but the local logical clock wins.
{8, RECV, &roachpb.Timestamp{WallTime: 10, Logical: 4}, roachpb.Timestamp{WallTime: 10, Logical: 8}},
// Wall clocks coincide, but the remote logical clock wins.
{10, RECV, &roachpb.Timestamp{WallTime: 10, Logical: 99}, roachpb.Timestamp{WallTime: 10, Logical: 100}},
// The physical clock has caught up and takes over.
{11, RECV, &roachpb.Timestamp{WallTime: 10, Logical: 31}, roachpb.Timestamp{WallTime: 11, Logical: 0}},
{11, SEND, nil, roachpb.Timestamp{WallTime: 11, Logical: 1}},
}
var current roachpb.Timestamp
for i, step := range expectedHistory {
m.Set(step.wallClock)
switch step.event {
case SEND:
current = c.Now()
case RECV:
fallthrough
default:
previous := c.Timestamp()
current = c.Update(*step.input)
if current.Equal(previous) {
t.Errorf("%d: clock not updated", i)
}
}
if !current.Equal(step.expected) {
t.Fatalf("HLC error: %d expected %v, got %v", i, step.expected, current)
}
}
c.Now()
}