當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。