New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: introduce ClientConn and ServerConn interfaces #4905
rpc: introduce ClientConn and ServerConn interfaces #4905
Conversation
The underlying rpc.Conn is bidirectional, but in our use case we always send requests from the client to the server which responds. Hide rpc.NewConn and replace it with a pair of NewClientConn and NewServerConn methods to deliniate the method sets of both types so they can be mocked.
ClientConn.Start is always called on return from rpc.NewClientConn, so just make NewClientConn call Start before returning. This simplifies the rpc client API.
@@ -234,7 +235,7 @@ func (a *CallbackMethods) Factorial(x int64val) (int64val, error) { | |||
return int64val{1}, nil | |||
} | |||
var r int64val | |||
err := a.root.conn.Call(rpc.Request{"CallbackMethods", 0, "", "Factorial"}, int64val{x.I - 1}, &r) | |||
err := a.root.conn.(rpc.ClientConn).Call(rpc.Request{"CallbackMethods", 0, "", "Factorial"}, int64val{x.I - 1}, &r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please make this two lines?
client := a.root.conn.(rpc.ClientConn)
err := client.Call(...)
The diff was much larger than necessary due to the renaming the receiver of 'conn' -> 'c'. However, LGTM with one suggestion. |
That's because |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
This PR is in preparation for adding tests for retrying temporary RPC errors.
It introduces two new interface types,
rpc.ClientConn
andrpc.ServerConn
whose purposes are self explanatory. Also provide constructor functions for these new interface types asNewConn
has been unexported.Remove the ability to provide a RequestNotifier when requesting a ClientConn, this was never used by any non test caller and is only part of the bidirectional code for the rpc package, which is also unused by juju.
Adjust the callers in the
api
andapiserver
packages to these new interfaces, very few changes were needed apart from adjusting the types in various wrapper types.The bidirection nature of the rpc package remains, but if needed the caller must assert their ServerConn value to a ClientConn, or vice versa. No code in Juju does this, but the rpc tests assert this behaviour
Finally, unexport
rpc.Conn
.