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


Golang Skew.Earliest方法代码示例

本文整理汇总了Golang中github.com/juju/juju/state/lease.Skew.Earliest方法的典型用法代码示例。如果您正苦于以下问题:Golang Skew.Earliest方法的具体用法?Golang Skew.Earliest怎么用?Golang Skew.Earliest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/juju/juju/state/lease.Skew的用法示例。


在下文中一共展示了Skew.Earliest方法的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.Earliest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。