示例#1
0
func (r *rootSuite) TestFindMethodCachesFacades(c *gc.C) {
	srvRoot := apiserver.TestingSrvRoot(nil)
	defer common.Facades.Discard("my-counting-facade", 0)
	defer common.Facades.Discard("my-counting-facade", 1)
	var count int64
	newCounter := func(
		*state.State, *common.Resources, common.Authorizer,
	) (
		*countingType, error,
	) {
		count += 1
		return &countingType{count: count, id: ""}, nil
	}
	common.RegisterStandardFacade("my-counting-facade", 0, newCounter)
	common.RegisterStandardFacade("my-counting-facade", 1, newCounter)
	// The first time we call FindMethod, it should lookup a facade, and
	// request a new object.
	caller, err := srvRoot.FindMethod("my-counting-facade", 0, "Count")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller, "", "1")
	// The second time we ask for a method on the same facade, it should
	// reuse that object, rather than creating another instance
	caller, err = srvRoot.FindMethod("my-counting-facade", 0, "AltCount")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller, "", "ALT-1")
	// But when we ask for a different version, we should get a new
	// instance
	caller, err = srvRoot.FindMethod("my-counting-facade", 1, "Count")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller, "", "2")
	// But it, too, should be cached
	caller, err = srvRoot.FindMethod("my-counting-facade", 1, "AltCount")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller, "", "ALT-2")
}
示例#2
0
func (r *rootSuite) TestFindMethodHandlesInterfaceTypes(c *gc.C) {
	srvRoot := apiserver.TestingSrvRoot(nil)
	defer common.Facades.Discard("my-interface-facade", 0)
	defer common.Facades.Discard("my-interface-facade", 1)
	common.RegisterStandardFacade("my-interface-facade", 0, func(
		*state.State, *common.Resources, common.Authorizer,
	) (
		smallInterface, error,
	) {
		return &firstImpl{}, nil
	})
	common.RegisterStandardFacade("my-interface-facade", 1, func(
		*state.State, *common.Resources, common.Authorizer,
	) (
		smallInterface, error,
	) {
		return &secondImpl{}, nil
	})
	caller, err := srvRoot.FindMethod("my-interface-facade", 0, "OneMethod")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller, "", "first")
	caller2, err := srvRoot.FindMethod("my-interface-facade", 1, "OneMethod")
	c.Assert(err, gc.IsNil)
	assertCallResult(c, caller2, "", "second")
	// We should *not* be able to see AMethod or ZMethod
	caller, err = srvRoot.FindMethod("my-interface-facade", 1, "AMethod")
	c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
	c.Check(err, gc.ErrorMatches,
		`no such request - method my-interface-facade\(1\)\.AMethod is not implemented`)
	c.Check(caller, gc.IsNil)
	caller, err = srvRoot.FindMethod("my-interface-facade", 1, "ZMethod")
	c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
	c.Check(err, gc.ErrorMatches,
		`no such request - method my-interface-facade\(1\)\.ZMethod is not implemented`)
	c.Check(caller, gc.IsNil)
}
示例#3
0
func (r *rootSuite) TestFindMethodUnknownVersion(c *gc.C) {
	srvRoot := apiserver.TestingSrvRoot(nil)
	defer common.Facades.Discard("my-testing-facade", 0)
	myGoodFacade := func(
		*state.State, *common.Resources, common.Authorizer,
	) (
		*testingType, error,
	) {
		return &testingType{}, nil
	}
	common.RegisterStandardFacade("my-testing-facade", 0, myGoodFacade)
	caller, err := srvRoot.FindMethod("my-testing-facade", 1, "Exposed")
	c.Check(caller, gc.IsNil)
	c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
	c.Check(err, gc.ErrorMatches, `unknown version \(1\) of interface "my-testing-facade"`)
}
示例#4
0
func init() {
	common.RegisterStandardFacade("Provisioner", 0, NewProvisionerAPI)
}
示例#5
0
文件: keymanager.go 项目: jiasir/juju
func init() {
	common.RegisterStandardFacade("KeyManager", 0, NewKeyManagerAPI)
}
示例#6
0
文件: agent.go 项目: jiasir/juju
func init() {
	common.RegisterStandardFacade("Agent", 0, NewAPI)
}
示例#7
0
func init() {
	// TODO: When the client can handle new versions, this should really be
	// registered as version 1, since it was not present in the API in Juju
	// 1.18
	common.RegisterStandardFacade("Networker", 0, NewNetworkerAPI)
}
示例#8
0
文件: deployer.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Deployer", 0, NewDeployerAPI)
}
示例#9
0
func init() {
	common.RegisterStandardFacade("Client", 0, NewClient)
}
示例#10
0
func init() {
	common.RegisterStandardFacade("UserManager", 0, NewUserManagerAPI)
}
示例#11
0
文件: logger.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Logger", 0, NewLoggerAPI)
}
示例#12
0
文件: rsyslog.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Rsyslog", 0, NewRsyslogAPI)
}
示例#13
0
文件: updater.go 项目: jiasir/juju
func init() {
	common.RegisterStandardFacade("CharmRevisionUpdater", 0, NewCharmRevisionUpdaterAPI)
}
示例#14
0
文件: machiner.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Machiner", 0, NewMachinerAPI)
}
示例#15
0
func init() {
	common.RegisterStandardFacade("Firewaller", 0, NewFirewallerAPI)
}
示例#16
0
文件: upgrader.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Upgrader", 0, upgraderFacade)
}
示例#17
0
文件: uniter.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Uniter", 0, NewUniterAPI)
}
示例#18
0
func init() {
	common.RegisterStandardFacade("Environment", 0, NewEnvironmentAPI)
}
示例#19
0
文件: pinger.go 项目: klyachin/juju
func init() {
	common.RegisterStandardFacade("Pinger", 0, NewPinger)
}