當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Skew.Latest方法代碼示例

本文整理匯總了Golang中github.com/juju/juju/state/lease.Skew.Latest方法的典型用法代碼示例。如果您正苦於以下問題:Golang Skew.Latest方法的具體用法?Golang Skew.Latest怎麽用?Golang Skew.Latest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/juju/state/lease.Skew的用法示例。


在下文中一共展示了Skew.Latest方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestBracketedWrite

func (s *SkewSuite) TestBracketedWrite(c *gc.C) {
	now := coretesting.ZeroTime()
	c.Logf("now: %s", now)
	oneSecondAgo := now.Add(-time.Second)
	twoSecondsAgo := now.Add(-2 * time.Second)
	threeSecondsAgo := now.Add(-3 * time.Second)
	fiveSecondsAgo := now.Add(-5 * time.Second)
	oneSecondLater := now.Add(time.Second)

	// Where T is the current local time:
	// between T-5 and T-1, we read T-2 from the remote clock.
	skew := lease.Skew{
		LastWrite: twoSecondsAgo,
		Beginning: fiveSecondsAgo,
		End:       oneSecondAgo,
	}

	// If the remote wrote a long time ago -- say, 20 minutes ago it thought
	// it was two seconds before now -- its clock could be arbitrarily far
	// ahead of ours. But we know that when we started reading, 5 seconds ago,
	// it might not have seen a time later than 2 seconds in the past; so
	// right now, five seconds after that, it might not have seen a time later
	// than three seconds in the future.
	c.Check(skew.Earliest(now), gc.DeepEquals, threeSecondsAgo)

	// If the remote wrote at the very last moment -- exactly one second ago,
	// it thought it was 2 seconds in the past -- it could have a clock one
	// second behind ours. If so, the *latest* time at which it might still
	// have thought it was before now is one second in the future.
	c.Check(skew.Latest(now), gc.DeepEquals, oneSecondLater)
}
開發者ID:bac,項目名稱:juju,代碼行數:31,代碼來源:skew_test.go

示例2: TestApparentFutureWrite

func (s *SkewSuite) TestApparentFutureWrite(c *gc.C) {
	now := coretesting.ZeroTime()
	c.Logf("now: %s", now)
	oneSecondAgo := now.Add(-time.Second)
	threeSecondsAgo := now.Add(-3 * time.Second)
	tenSecondsAgo := now.Add(-10 * time.Second)
	twelveSecondsAgo := now.Add(-12 * time.Second)
	nineSecondsLater := now.Add(9 * time.Second)

	// Where T is the current local time:
	// between T-3 and T-1, we read T+9 from the remote clock.
	skew := lease.Skew{
		LastWrite: nineSecondsLater,
		Beginning: threeSecondsAgo,
		End:       oneSecondAgo,
	}

	// If the remote wrote a long time ago -- say, 20 minutes ago it thought
	// it was nine seconds after now -- its clock could be arbitrarily far
	// ahead of ours. But we know that when we started reading, 3 seconds ago,
	// it might not have seen a time later than 9 seconds in the future; so
	// right now, three seconds after that, it might not have seen a time later
	// than twelve seconds in the future.
	c.Check(skew.Earliest(now), gc.DeepEquals, twelveSecondsAgo)

	// If the remote wrote at the very last moment -- exactly one second ago,
	// it thought it was 9 seconds in the future -- it could have a clock a
	// full 10 seconds ahead of ours. If so, the *latest* time at which it
	// might still have thought it was before now is ten seconds in the past.
	c.Check(skew.Latest(now), gc.DeepEquals, tenSecondsAgo)
}
開發者ID:bac,項目名稱:juju,代碼行數:31,代碼來源:skew_test.go

示例3: TestApparentPastWrite

func (s *SkewSuite) TestApparentPastWrite(c *gc.C) {
	now := coretesting.ZeroTime()
	c.Logf("now: %s", now)
	oneSecondAgo := now.Add(-time.Second)
	threeSecondsAgo := now.Add(-3 * time.Second)
	nineSecondsAgo := now.Add(-9 * time.Second)
	sixSecondsLater := now.Add(6 * time.Second)
	eightSecondsLater := now.Add(8 * time.Second)

	// Where T is the current local time:
	// between T-3 and T-1, we read T-9 from the remote clock.
	skew := lease.Skew{
		LastWrite: nineSecondsAgo,
		Beginning: threeSecondsAgo,
		End:       oneSecondAgo,
	}

	// If the remote wrote a long time ago -- say, 20 minutes ago it thought it
	// was 9 seconds ago -- its clock could be arbitrarily far ahead of ours.
	// But we know that when we started reading, 3 seconds ago, it might not
	// have seen a time later than 9 seconds ago; so right now, three seconds
	// after that, it might not have seen a time later than 6 seconds ago.
	c.Check(skew.Earliest(now), gc.DeepEquals, sixSecondsLater)

	// If the remote wrote at the very last moment -- exactly one second ago,
	// it thought it was nine seconds ago -- it could have a clock a full 8
	// seconds behind ours. If so, the *latest* time at which it *might* still
	// think it's before now is 8 seconds in the future.
	c.Check(skew.Latest(now), gc.DeepEquals, eightSecondsLater)
}
開發者ID:bac,項目名稱:juju,代碼行數:30,代碼來源:skew_test.go

示例4: TestZero

func (s *SkewSuite) TestZero(c *gc.C) {
	now := coretesting.ZeroTime()

	// The zero Skew should act as unskewed.
	skew := lease.Skew{}

	c.Check(skew.Earliest(now), gc.Equals, now)
	c.Check(skew.Latest(now), gc.Equals, now)
}
開發者ID:bac,項目名稱:juju,代碼行數:9,代碼來源:skew_test.go

示例5: TestMixedTimezones

func (s *SkewSuite) TestMixedTimezones(c *gc.C) {
	here := time.FixedZone("here", -3600)
	there := time.FixedZone("there", -7200)
	elsewhere := time.FixedZone("elsewhere", -10800)

	// This is a straight copy of TestBracketedWrite, with strange timezones
	// inserted to check that they don't affect the results at all.
	now := coretesting.ZeroTime()
	c.Logf("now: %s", now)
	oneSecondAgo := now.Add(-time.Second)
	twoSecondsAgo := now.Add(-2 * time.Second)
	threeSecondsAgo := now.Add(-3 * time.Second)
	fiveSecondsAgo := now.Add(-5 * time.Second)
	oneSecondLater := now.Add(time.Second)

	// Where T is the current local time:
	// between T-5 and T-1, we read T-2 from the remote clock.
	skew := lease.Skew{
		LastWrite: twoSecondsAgo.In(here),
		Beginning: fiveSecondsAgo.In(there),
		End:       oneSecondAgo.In(elsewhere),
	}

	// If the remote wrote a long time ago -- say, 20 minutes ago it thought
	// it was two seconds before now -- its clock could be arbitrarily far
	// ahead of ours. But we know that when we started reading, 5 seconds ago,
	// it might not have seen a time later than 2 seconds in the past; so
	// right now, five seconds after that, it might not have seen a time later
	// than three seconds in the future.
	c.Check(skew.Earliest(now), gc.DeepEquals, threeSecondsAgo.In(there))

	// If the remote wrote at the very last moment -- exactly one second ago,
	// it thought it was 2 seconds in the past -- it could have a clock one
	// second behind ours. If so, the *latest* time at which it might still
	// have thought it was before now is one second in the future.
	c.Check(skew.Latest(now), gc.DeepEquals, oneSecondLater.In(elsewhere))
}
開發者ID:bac,項目名稱:juju,代碼行數:37,代碼來源:skew_test.go


注:本文中的github.com/juju/juju/state/lease.Skew.Latest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。