rpc: introduce ClientConn and ServerConn interfaces #4905

Merged
merged 8 commits into from Apr 4, 2016

Conversation

Projects
None yet
3 participants
Contributor

davecheney commented Mar 29, 2016

This PR is in preparation for adding tests for retrying temporary RPC errors.

It introduces two new interface types, rpc.ClientConn and rpc.ServerConn whose purposes are self explanatory. Also provide constructor functions for these new interface types as NewConn 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 and apiserver 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.

davecheney added some commits Mar 24, 2016

rpc: refactor NewConn into Client and Server methods
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.
rpc: remove ClientConn.Start method
ClientConn.Start is always called on return from rpc.NewClientConn, so
just make NewClientConn call Start before returning. This simplifies the
rpc client API.
rpc/rpc_test.go
@@ -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)
@howbazaar

howbazaar Apr 3, 2016

Owner

Can we please make this two lines?

client := a.root.conn.(rpc.ClientConn)
err := client.Call(...)
Owner

howbazaar commented Apr 3, 2016

The diff was much larger than necessary due to the renaming the receiver of 'conn' -> 'c'.

However, LGTM with one suggestion.

Contributor

davecheney commented Apr 3, 2016

The diff was much larger than necessary due to the renaming the receiver of 'conn' -> 'c'.

That's because conn became a type, so it couldn't also be the name of the receiver.

Contributor

davecheney commented Apr 3, 2016

$$merge$$

Contributor

jujubot commented Apr 3, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit da28cfa into juju:api-call-retry Apr 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment