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") }
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) }
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"`) }
func init() { common.RegisterStandardFacade("Provisioner", 0, NewProvisionerAPI) }
func init() { common.RegisterStandardFacade("KeyManager", 0, NewKeyManagerAPI) }
func init() { common.RegisterStandardFacade("Agent", 0, NewAPI) }
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) }
func init() { common.RegisterStandardFacade("Deployer", 0, NewDeployerAPI) }
func init() { common.RegisterStandardFacade("Client", 0, NewClient) }
func init() { common.RegisterStandardFacade("UserManager", 0, NewUserManagerAPI) }
func init() { common.RegisterStandardFacade("Logger", 0, NewLoggerAPI) }
func init() { common.RegisterStandardFacade("Rsyslog", 0, NewRsyslogAPI) }
func init() { common.RegisterStandardFacade("CharmRevisionUpdater", 0, NewCharmRevisionUpdaterAPI) }
func init() { common.RegisterStandardFacade("Machiner", 0, NewMachinerAPI) }
func init() { common.RegisterStandardFacade("Firewaller", 0, NewFirewallerAPI) }
func init() { common.RegisterStandardFacade("Upgrader", 0, upgraderFacade) }
func init() { common.RegisterStandardFacade("Uniter", 0, NewUniterAPI) }
func init() { common.RegisterStandardFacade("Environment", 0, NewEnvironmentAPI) }
func init() { common.RegisterStandardFacade("Pinger", 0, NewPinger) }