本文整理匯總了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()
}