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


Golang context.NewRelationCache函数代码示例

本文整理汇总了Golang中github.com/juju/juju/worker/uniter/runner/context.NewRelationCache函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRelationCache函数的具体用法?Golang NewRelationCache怎么用?Golang NewRelationCache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewRelationCache函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMemberCaching

func (s *ContextRelationSuite) TestMemberCaching(c *gc.C) {
	unit, err := s.svc.AddUnit()
	c.Assert(err, jc.ErrorIsNil)
	ru, err := s.rel.Unit(unit)
	c.Assert(err, jc.ErrorIsNil)
	err = ru.EnterScope(map[string]interface{}{"blib": "blob"})
	c.Assert(err, jc.ErrorIsNil)
	settings, err := ru.Settings()
	c.Assert(err, jc.ErrorIsNil)
	settings.Set("ping", "pong")
	_, err = settings.Write()
	c.Assert(err, jc.ErrorIsNil)

	cache := context.NewRelationCache(s.apiRelUnit.ReadSettings, []string{"u/1"})
	ctx := context.NewContextRelation(s.apiRelUnit, cache)

	// Check that uncached settings are read from state.
	m, err := ctx.ReadSettings("u/1")
	c.Assert(err, jc.ErrorIsNil)
	expectMap := settings.Map()
	expectSettings := convertMap(expectMap)
	c.Assert(m, gc.DeepEquals, expectSettings)

	// Check that changes to state do not affect the cached settings.
	settings.Set("ping", "pow")
	_, err = settings.Write()
	c.Assert(err, jc.ErrorIsNil)
	m, err = ctx.ReadSettings("u/1")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(m, gc.DeepEquals, expectSettings)
}
开发者ID:imoapps,项目名称:juju,代码行数:31,代码来源:relation_test.go

示例2: getHookContext

func (s *HookContextSuite) getHookContext(c *gc.C, uuid string, relid int,
	remote string, proxies proxy.Settings) *context.HookContext {
	if relid != -1 {
		_, found := s.apiRelunits[relid]
		c.Assert(found, jc.IsTrue)
	}
	facade, err := s.st.Uniter()
	c.Assert(err, jc.ErrorIsNil)

	relctxs := map[int]*context.ContextRelation{}
	for relId, relUnit := range s.apiRelunits {
		cache := context.NewRelationCache(relUnit.ReadSettings, nil)
		relctxs[relId] = context.NewContextRelation(relUnit, cache)
	}

	env, err := s.State.Environment()
	c.Assert(err, jc.ErrorIsNil)

	context, err := context.NewHookContext(s.apiUnit, facade, "TestCtx", uuid,
		env.Name(), relid, remote, relctxs, apiAddrs,
		proxies, false, nil, nil, s.machine.Tag().(names.MachineTag),
		runnertesting.NewRealPaths(c))
	c.Assert(err, jc.ErrorIsNil)
	return context
}
开发者ID:kakamessi99,项目名称:juju,代码行数:25,代码来源:util_test.go

示例3: TestRemoveMemberChangesMembership

func (s *RelationCacheSuite) TestRemoveMemberChangesMembership(c *gc.C) {
	cache := context.NewRelationCache(s.ReadSettings, []string{"x/2"})
	cache.RemoveMember("x/1")
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"x/2"})
	cache.RemoveMember("x/2")
	c.Assert(cache.MemberNames(), gc.HasLen, 0)
	c.Assert(s.calls, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:cache_test.go

示例4: TestInvalidateMemberChangesMembership

func (s *RelationCacheSuite) TestInvalidateMemberChangesMembership(c *gc.C) {
	cache := context.NewRelationCache(s.ReadSettings, nil)
	cache.InvalidateMember("foo/1")
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"foo/1"})
	cache.InvalidateMember("foo/2")
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"foo/1", "foo/2"})
	cache.InvalidateMember("foo/2")
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"foo/1", "foo/2"})
	c.Assert(s.calls, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:cache_test.go

示例5: TestSettingsPropagatesError

func (s *RelationCacheSuite) TestSettingsPropagatesError(c *gc.C) {
	s.results = []settingsResult{{
		nil, errors.New("blam"),
	}}
	cache := context.NewRelationCache(s.ReadSettings, nil)

	settings, err := cache.Settings("whatever")
	c.Assert(settings, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "blam")
	c.Assert(s.calls, jc.DeepEquals, []string{"whatever"})
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:cache_test.go

示例6: TestSettingsCachesMemberSettings

func (s *RelationCacheSuite) TestSettingsCachesMemberSettings(c *gc.C) {
	s.results = []settingsResult{{
		params.Settings{"foo": "bar"}, nil,
	}}
	cache := context.NewRelationCache(s.ReadSettings, []string{"x/2"})

	for i := 0; i < 2; i++ {
		settings, err := cache.Settings("x/2")
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(settings, jc.DeepEquals, params.Settings{"foo": "bar"})
		c.Assert(s.calls, jc.DeepEquals, []string{"x/2"})
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:cache_test.go

示例7: TestPrunePreservesMemberSettings

func (s *RelationCacheSuite) TestPrunePreservesMemberSettings(c *gc.C) {
	s.results = []settingsResult{{
		params.Settings{"foo": "bar"}, nil,
	}}
	cache := context.NewRelationCache(s.ReadSettings, []string{"foo/2"})

	settings, err := cache.Settings("foo/2")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(settings, jc.DeepEquals, params.Settings{"foo": "bar"})
	c.Assert(s.calls, jc.DeepEquals, []string{"foo/2"})

	cache.Prune([]string{"foo/2"})
	settings, err = cache.Settings("foo/2")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(settings, jc.DeepEquals, params.Settings{"foo": "bar"})
	c.Assert(s.calls, jc.DeepEquals, []string{"foo/2"})
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:cache_test.go

示例8: TestPruneUncachesOtherSettings

func (s *RelationCacheSuite) TestPruneUncachesOtherSettings(c *gc.C) {
	s.results = []settingsResult{{
		params.Settings{"foo": "bar"}, nil,
	}, {
		params.Settings{"baz": "qux"}, nil,
	}}
	cache := context.NewRelationCache(s.ReadSettings, nil)

	settings, err := cache.Settings("x/2")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(settings, jc.DeepEquals, params.Settings{"foo": "bar"})
	c.Assert(s.calls, jc.DeepEquals, []string{"x/2"})

	cache.Prune(nil)
	settings, err = cache.Settings("x/2")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(settings, jc.DeepEquals, params.Settings{"baz": "qux"})
	c.Assert(s.calls, jc.DeepEquals, []string{"x/2", "x/2"})
}
开发者ID:imoapps,项目名称:juju,代码行数:19,代码来源:cache_test.go

示例9: getMeteredHookContext

func (s *HookContextSuite) getMeteredHookContext(c *gc.C, uuid string, relid int,
	remote string, proxies proxy.Settings, canAddMetrics bool, metrics *charm.Metrics, paths runnertesting.RealPaths) *context.HookContext {
	if relid != -1 {
		_, found := s.apiRelunits[relid]
		c.Assert(found, jc.IsTrue)
	}
	facade, err := s.st.Uniter()
	c.Assert(err, jc.ErrorIsNil)

	relctxs := map[int]*context.ContextRelation{}
	for relId, relUnit := range s.apiRelunits {
		cache := context.NewRelationCache(relUnit.ReadSettings, nil)
		relctxs[relId] = context.NewContextRelation(relUnit, cache)
	}

	context, err := context.NewHookContext(s.meteredApiUnit, facade, "TestCtx", uuid,
		"test-env-name", relid, remote, relctxs, apiAddrs,
		proxies, canAddMetrics, metrics, nil, s.machine.Tag().(names.MachineTag),
		paths)
	c.Assert(err, jc.ErrorIsNil)
	return context
}
开发者ID:kakamessi99,项目名称:juju,代码行数:22,代码来源:util_test.go

示例10: TestPruneChangesMembership

func (s *RelationCacheSuite) TestPruneChangesMembership(c *gc.C) {
	cache := context.NewRelationCache(s.ReadSettings, []string{"u/1", "u/2", "u/3"})
	cache.Prune([]string{"u/3", "u/4", "u/5"})
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"u/3", "u/4", "u/5"})
	c.Assert(s.calls, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:6,代码来源:cache_test.go

示例11: TestCreateWithMembers

func (s *RelationCacheSuite) TestCreateWithMembers(c *gc.C) {
	cache := context.NewRelationCache(s.ReadSettings, []string{"u/3", "u/2", "u/1"})
	c.Assert(cache.MemberNames(), jc.DeepEquals, []string{"u/1", "u/2", "u/3"})
	c.Assert(s.calls, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:5,代码来源:cache_test.go

示例12: TestCreateEmpty

func (s *RelationCacheSuite) TestCreateEmpty(c *gc.C) {
	cache := context.NewRelationCache(s.ReadSettings, nil)
	c.Assert(cache.MemberNames(), gc.HasLen, 0)
	c.Assert(s.calls, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:5,代码来源:cache_test.go


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