~jameinel/juju-core/rpc-versions

« back to all changes in this revision

Viewing changes to rpc/rpc_test.go

  • Committer: John Arbash Meinel
  • Date: 2014-05-13 07:58:18 UTC
  • Revision ID: john@arbash-meinel.com-20140513075818-9ih8uoohmfjbdkcn
Start trying to implement a custom MethodCaller. But really, we still want 'Id' to be looked up early rather than late. :(

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
        Call1r1e(s stringVal) (stringVal, error)
115
115
}
116
116
 
 
117
type InterfaceMethods2 interface {
 
118
        Call0r1e() (stringVal, error)
 
119
}
 
120
 
117
121
type ChangeAPIMethods struct {
118
122
        r *Root
119
123
}
257
261
        return stringVal{"new method result"}
258
262
}
259
263
 
 
264
type CallV0 struct {
 
265
}
 
266
 
 
267
func (c *CallV0) Request(s stringVal) (stringVal, err) {
 
268
        return stringVal{s.Val + " v1 response"}
 
269
}
 
270
 
 
271
type CallV1 struct {
 
272
}
 
273
 
 
274
func (c *CallV1) Request(i intVal) (stringVal, err) {
 
275
        return stringVal{fmt.Sprintf("v2 response from %d", i.I)}
 
276
}
 
277
 
 
278
type CustomCaller struct {
 
279
}
 
280
 
 
281
func (c CustomCaller) MethodCaller(rootName string, version int, methodName string) (
 
282
        rpcreflect.MethodCaller, error) {
 
283
        if rootName != "InterfaceMethods" {
 
284
                return rpcreflect.MethodCaller{}, &rpcreflect.CallNotImplementedError{
 
285
                        RootMethod: rootName,
 
286
                }
 
287
        }
 
288
        var value rpcreflect.Value
 
289
        switch version {
 
290
        case 0:
 
291
                objtype := rpcreflect.ObjType(reflect.TypeOf((*InterfaceMethods)(nil)).Elem())
 
292
                m, err := r.SimpleMethods(id)
 
293
        case 1:
 
294
        default:
 
295
                return rpcreflect.MethodCaller{}, &rpcreflect.CallNotImplementedError{
 
296
                        RootMethod: rootName,
 
297
                        Version:    version,
 
298
                }
 
299
        }
 
300
}
 
301
 
260
302
func (*rpcSuite) TestRPC(c *gc.C) {
261
303
        root := &Root{
262
304
                simple: make(map[string]*SimpleMethods),