本文整理汇总了Golang中github.com/juju/txn/testing.SetRetryHooks函数的典型用法代码示例。如果您正苦于以下问题:Golang SetRetryHooks函数的具体用法?Golang SetRetryHooks怎么用?Golang SetRetryHooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetRetryHooks函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRetryHooks
func (s *txnSuite) TestRetryHooks(c *gc.C) {
s.insertDoc(c, "1", "Foo")
defer txntesting.SetRetryHooks(c, s.txnRunner, func() {
s.setDocName(c, "1", "Bar")
}, func() {
s.setDocName(c, "1", "Foo")
}).Check()
maxAttempt := 0
buildTxn := func(attempt int) ([]txn.Op, error) {
maxAttempt = attempt
ops := []txn.Op{{
C: s.collection.Name,
Id: "1",
Assert: bson.D{{"name", "Foo"}},
Update: bson.D{{"$set", bson.D{{"name", "FooBar"}}}},
}}
return ops, nil
}
err := s.txnRunner.Run(buildTxn)
c.Assert(err, gc.IsNil)
c.Assert(maxAttempt, gc.Equals, 2)
var found simpleDoc
err = s.collection.FindId("1").One(&found)
c.Assert(err, gc.IsNil)
doc := simpleDoc{"1", "FooBar"}
c.Assert(found, gc.DeepEquals, doc)
}
开发者ID:juju,项目名称:txn,代码行数:28,代码来源:txn_test.go
示例2: TestExtendLease_WorksDespite_ExpireThenReclaimSameHolder
func (s *ClientTrickyRaceSuite) TestExtendLease_WorksDespite_ExpireThenReclaimSameHolder(c *gc.C) {
// Set up hooks to expire and reclaim the lease before the extend gets a
// chance; and to verify that the second attempt successfully extends.
defer txntesting.SetRetryHooks(c, s.sut.Runner, func() {
s.blocker.Clock.Advance(90 * time.Second)
err := s.blocker.Client.ExpireLease("name")
c.Check(err, jc.ErrorIsNil)
err = s.blocker.Client.ClaimLease("name", lease.Request{"holder", time.Minute})
c.Check(err, jc.ErrorIsNil)
}, func() {
err := s.blocker.Client.Refresh()
c.Check(err, jc.ErrorIsNil)
c.Check("name", s.blocker.Expiry(), s.blocker.Zero.Add(5*time.Minute))
})()
// Try to extend; check it worked.
err := s.sut.Client.ExtendLease("name", lease.Request{"holder", 5 * time.Minute})
c.Check(err, jc.ErrorIsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:20,代码来源:client_race_test.go
示例3: TestExtendLease_WorksDespite_ShorterExtendLease
func (s *ClientTrickyRaceSuite) TestExtendLease_WorksDespite_ShorterExtendLease(c *gc.C) {
shorterRequest := 90 * time.Second
longerRequest := 120 * time.Second
// Set up hooks to extend the lease by a little, before the SUT's extend
// gets a chance; and then to verify state after it's applied its retry.
defer txntesting.SetRetryHooks(c, s.sut.Runner, func() {
err := s.blocker.Client.ExtendLease("name", lease.Request{"holder", shorterRequest})
c.Check(err, jc.ErrorIsNil)
}, func() {
err := s.blocker.Client.Refresh()
c.Check(err, jc.ErrorIsNil)
c.Check("name", s.blocker.Expiry(), s.blocker.Zero.Add(longerRequest))
})()
// Extend the lease.
err := s.sut.Client.ExtendLease("name", lease.Request{"holder", longerRequest})
c.Check(err, jc.ErrorIsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:20,代码来源:client_race_test.go
示例4: SetRetryHooks
func SetRetryHooks(c *gc.C, st *State, block, check func()) txntesting.TransactionChecker {
return txntesting.SetRetryHooks(c, newRunnerForHooks(st), block, check)
}
开发者ID:makyo,项目名称:juju,代码行数:3,代码来源:export_test.go
示例5: SetRetryHooks
func SetRetryHooks(c *gc.C, st *State, block, check func()) txntesting.TransactionChecker {
runner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: st.db})
st.transactionRunner = runner
return txntesting.SetRetryHooks(c, runner, block, check)
}
开发者ID:zhouqt,项目名称:juju,代码行数:5,代码来源:export_test.go
示例6: SetRetryHooks
func SetRetryHooks(c *gc.C, st *State, block, check func()) txntesting.TransactionChecker {
return txntesting.SetRetryHooks(c, st.transactionRunner, block, check)
}
开发者ID:klyachin,项目名称:juju,代码行数:3,代码来源:export_test.go
注:本文中的github.com/juju/txn/testing.SetRetryHooks函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论