当前位置: 首页>>代码示例>>Golang>>正文


Golang Timestamp.Equal方法代码示例

本文整理汇总了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()
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:51,代码来源:hlc_test.go


注:本文中的github.com/cockroachdb/cockroach/roachpb.Timestamp.Equal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。