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


Golang lease.NewClient函数代码示例

本文整理汇总了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")
}
开发者ID:Pankov404,项目名称:juju,代码行数:32,代码来源:client_race_test.go

示例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 ""`)
}
开发者ID:Pankov404,项目名称:juju,代码行数:16,代码来源:client_persistence_test.go

示例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`)
}
开发者ID:Pankov404,项目名称:juju,代码行数:19,代码来源:client_persistence_test.go

示例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,
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:24,代码来源:fixture_test.go

示例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")
}
开发者ID:exekias,项目名称:juju,代码行数:6,代码来源:client_validation_test.go

示例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")
}
开发者ID:exekias,项目名称:juju,代码行数:6,代码来源:client_validation_test.go


注:本文中的github.com/juju/juju/state/lease.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。