本文整理汇总了Golang中github.com/juju/juju/state/lease.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNewClient_WorksDespite_CreateClockRace
func (s *ClientSimpleRaceSuite) TestNewClient_WorksDespite_CreateClockRace(c *gc.C) {
config := func(id string) lease.ClientConfig {
return lease.ClientConfig{
Id: id,
Namespace: "ns",
Collection: "leases",
Mongo: NewMongo(s.db),
Clock: lease.SystemClock{},
}
}
sutConfig := config("sut")
sutRunner := sutConfig.Mongo.(*Mongo).runner
// Set up a hook to create the clock doc (and write some important data to
// it) by creating another client before the SUT gets a chance.
defer txntesting.SetBeforeHooks(c, sutRunner, func() {
client, err := lease.NewClient(config("blocker"))
c.Check(err, jc.ErrorIsNil)
err = client.ClaimLease("somewhere", lease.Request{"someone", time.Minute})
c.Check(err, jc.ErrorIsNil)
})()
// Create a client against an apparently-empty namespace.
client, err := lease.NewClient(sutConfig)
c.Check(err, jc.ErrorIsNil)
// Despite the scramble, it's generated with recent lease data and no error.
leases := client.Leases()
info, found := leases["somewhere"]
c.Check(found, jc.IsTrue)
c.Check(info.Holder, gc.Equals, "someone")
}
示例2: TestNewClientInvalidClockDoc
func (s *ClientPersistenceSuite) TestNewClientInvalidClockDoc(c *gc.C) {
config := lease.ClientConfig{
Id: "client",
Namespace: "namespace",
Collection: "collection",
Mongo: NewMongo(s.db),
Clock: lease.SystemClock{},
}
dbKey := "clock#namespace#"
err := s.db.C("collection").Insert(bson.M{"_id": dbKey})
c.Assert(err, jc.ErrorIsNil)
client, err := lease.NewClient(config)
c.Check(client, gc.IsNil)
c.Check(err, gc.ErrorMatches, `corrupt clock document: invalid type ""`)
}
示例3: TestNewClientInvalidLeaseDoc
func (s *ClientPersistenceSuite) TestNewClientInvalidLeaseDoc(c *gc.C) {
config := lease.ClientConfig{
Id: "client",
Namespace: "namespace",
Collection: "collection",
Mongo: NewMongo(s.db),
Clock: lease.SystemClock{},
}
err := s.db.C("collection").Insert(bson.M{
"_id": "snagglepuss",
"type": "lease",
"namespace": "namespace",
})
c.Assert(err, jc.ErrorIsNil)
client, err := lease.NewClient(config)
c.Check(client, gc.IsNil)
c.Check(err, gc.ErrorMatches, `corrupt lease document "snagglepuss": inconsistent _id`)
}
示例4: NewFixture
func NewFixture(c *gc.C, database *mgo.Database, params FixtureParams) *Fixture {
mongo := NewMongo(database)
clockStart := params.ClockStart
if clockStart.IsZero() {
clockStart = defaultClockStart
}
clock := NewClock(clockStart, params.ClockStep)
config := lease.ClientConfig{
Id: or(params.Id, "default-client"),
Namespace: or(params.Namespace, "default-namespace"),
Collection: or(params.Collection, "default-collection"),
Mongo: mongo,
Clock: clock,
}
client, err := lease.NewClient(config)
c.Assert(err, jc.ErrorIsNil)
return &Fixture{
Client: client,
Config: config,
Runner: mongo.runner,
Clock: clock,
Zero: clockStart,
}
}
示例5: TestNewClientClock
func (s *ClientValidationSuite) TestNewClientClock(c *gc.C) {
fix := s.EasyFixture(c)
fix.Config.Clock = nil
_, err := lease.NewClient(fix.Config)
c.Check(err, gc.ErrorMatches, "missing clock")
}
示例6: TestNewClientCollection
func (s *ClientValidationSuite) TestNewClientCollection(c *gc.C) {
fix := s.EasyFixture(c)
fix.Config.Collection = "$bad"
_, err := lease.NewClient(fix.Config)
c.Check(err, gc.ErrorMatches, "invalid collection: string contains forbidden characters")
}