Skip to content

Commit

Permalink
rename Outbound -> UnaryOutbound and add 'Unary' to handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Peats-Bond committed Nov 3, 2016
1 parent 14570a0 commit 5a1b224
Show file tree
Hide file tree
Showing 65 changed files with 422 additions and 354 deletions.
2 changes: 1 addition & 1 deletion crossdock/client/ctxpropagation/behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func buildDispatcher(t crossdock.T) (dispatcher yarpc.Dispatcher, tconfig server
ch, err := tchannel.NewChannel("ctxclient", nil)
fatals.NoError(err, "failed to create TChannel")

var outbound transport.Outbound
var outbound transport.UnaryOutbound
switch trans := t.Param(params.Transport); trans {
case "http":
outbound = ht.NewOutbound(fmt.Sprintf("http://%s:8081", subject))
Expand Down
8 changes: 4 additions & 4 deletions crossdock/client/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ func Create(t crossdock.T) yarpc.Dispatcher {
server := t.Param(params.Server)
fatals.NotEmpty(server, "server is required")

var outbound transport.Outbound
var unaryOutbound transport.UnaryOutbound
trans := t.Param(params.Transport)
switch trans {
case "http":
outbound = ht.NewOutbound(fmt.Sprintf("http://%s:8081", server))
unaryOutbound = ht.NewOutbound(fmt.Sprintf("http://%s:8081", server))
case "tchannel":
ch, err := tchannel.NewChannel("client", nil)
fatals.NoError(err, "couldn't create tchannel")
outbound = tch.NewOutbound(ch, tch.HostPort(server+":8082"))
unaryOutbound = tch.NewOutbound(ch, tch.HostPort(server+":8082"))
default:
fatals.Fail("", "unknown transport %q", trans)
}

return yarpc.NewDispatcher(yarpc.Config{
Name: "client",
Outbounds: transport.Outbounds{"yarpc-test": outbound},
Outbounds: transport.Outbounds{"yarpc-test": unaryOutbound},
})
}
20 changes: 20 additions & 0 deletions crossdock/internal/header.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package internal

import "go.uber.org/yarpc"
Expand Down
2 changes: 1 addition & 1 deletion crossdock/server/yarpc/phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type PhoneResponse struct {

// Phone implements the phone procedure
func Phone(ctx context.Context, reqMeta yarpc.ReqMeta, body *PhoneRequest) (*PhoneResponse, yarpc.ResMeta, error) {
var outbound transport.Outbound
var outbound transport.UnaryOutbound

switch {
case body.Transport.HTTP != nil:
Expand Down
4 changes: 2 additions & 2 deletions crossdock/thrift/echo/yarpc/echoserver/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crossdock/thrift/gauntlet/yarpc/secondserviceserver/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions crossdock/thrift/gauntlet/yarpc/thrifttestserver/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (d dispatcher) Inbounds() []transport.Inbound {
func (d dispatcher) Channel(service string) transport.Channel {
if out, ok := d.Outbounds[service]; ok {
out = transport.ApplyFilter(out, d.Filter)
out = request.ValidatorOutbound{Outbound: out}
out = request.ValidatorOutbound{UnaryOutbound: out}
return transport.IdentityChannel(d.Name, service, out)
}
panic(noOutboundForService{Service: service})
Expand Down
30 changes: 15 additions & 15 deletions dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func TestStartStopFailures(t *testing.T) {
return inbounds
},
outbounds: func(mockCtrl *gomock.Controller) transport.Outbounds {
outbounds := make(transport.Outbounds)
outbounds := make(transport.Outbounds, 10)
for i := 0; i < 10; i++ {
out := transporttest.NewMockOutbound(mockCtrl)
out := transporttest.NewMockUnaryOutbound(mockCtrl)
out.EXPECT().Start(gomock.Any()).Return(nil)
out.EXPECT().Stop().Return(nil)
outbounds[fmt.Sprintf("service-%v", i)] = out
outbounds[fmt.Sprintf("servuce-%v", i)] = out
}
return outbounds
},
Expand All @@ -144,12 +144,12 @@ func TestStartStopFailures(t *testing.T) {
return inbounds
},
outbounds: func(mockCtrl *gomock.Controller) transport.Outbounds {
outbounds := make(transport.Outbounds)
outbounds := make(transport.Outbounds, 10)
for i := 0; i < 10; i++ {
out := transporttest.NewMockOutbound(mockCtrl)
out := transporttest.NewMockUnaryOutbound(mockCtrl)
out.EXPECT().Start(gomock.Any()).Return(nil)
out.EXPECT().Stop().Return(nil)
outbounds[fmt.Sprintf("service-%v", i)] = out
outbounds[fmt.Sprintf("servuce-%v", i)] = out
}
return outbounds
},
Expand All @@ -172,12 +172,12 @@ func TestStartStopFailures(t *testing.T) {
return inbounds
},
outbounds: func(mockCtrl *gomock.Controller) transport.Outbounds {
outbounds := make(transport.Outbounds)
outbounds := make(transport.Outbounds, 10)
for i := 0; i < 10; i++ {
out := transporttest.NewMockOutbound(mockCtrl)
out := transporttest.NewMockUnaryOutbound(mockCtrl)
out.EXPECT().Start(gomock.Any()).Return(nil)
out.EXPECT().Stop().Return(nil)
outbounds[fmt.Sprintf("service-%v", i)] = out
outbounds[fmt.Sprintf("servuce-%v", i)] = out
}
return outbounds
},
Expand All @@ -196,16 +196,16 @@ func TestStartStopFailures(t *testing.T) {
return inbounds
},
outbounds: func(mockCtrl *gomock.Controller) transport.Outbounds {
outbounds := make(transport.Outbounds)
outbounds := make(transport.Outbounds, 10)
for i := 0; i < 10; i++ {
out := transporttest.NewMockOutbound(mockCtrl)
out := transporttest.NewMockUnaryOutbound(mockCtrl)
if i == 5 {
out.EXPECT().Start(gomock.Any()).Return(errors.New("something went wrong"))
} else {
out.EXPECT().Start(gomock.Any()).Return(nil)
out.EXPECT().Stop().Return(nil)
}
outbounds[fmt.Sprintf("service-%v", i)] = out
outbounds[fmt.Sprintf("servuce-%v", i)] = out
}
return outbounds
},
Expand All @@ -225,16 +225,16 @@ func TestStartStopFailures(t *testing.T) {
return inbounds
},
outbounds: func(mockCtrl *gomock.Controller) transport.Outbounds {
outbounds := make(transport.Outbounds)
outbounds := make(transport.Outbounds, 10)
for i := 0; i < 10; i++ {
out := transporttest.NewMockOutbound(mockCtrl)
out := transporttest.NewMockUnaryOutbound(mockCtrl)
out.EXPECT().Start(gomock.Any()).Return(nil)
if i == 7 {
out.EXPECT().Stop().Return(errors.New("something went wrong"))
} else {
out.EXPECT().Stop().Return(nil)
}
outbounds[fmt.Sprintf("service-%v", i)] = out
outbounds[fmt.Sprintf("servuce-%v", i)] = out
}
return outbounds
},
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type jsonHandler struct {
handler reflect.Value
}

func (h jsonHandler) Handle(ctx context.Context, treq *transport.Request, rw transport.ResponseWriter) error {
func (h jsonHandler) HandleUnary(ctx context.Context, treq *transport.Request, rw transport.ResponseWriter) error {
if err := encoding.Expect(treq, Encoding); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions encoding/json/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestHandleStructSuccess(t *testing.T) {
}

resw := new(transporttest.FakeResponseWriter)
err := handler.Handle(context.Background(), &transport.Request{
err := handler.HandleUnary(context.Background(), &transport.Request{
Procedure: "simpleCall",
Encoding: "json",
Body: jsonBody(`{"name": "foo", "attributes": {"bar": 42}}`),
Expand All @@ -67,7 +67,7 @@ func TestHandleMapSuccess(t *testing.T) {
}

resw := new(transporttest.FakeResponseWriter)
err := handler.Handle(context.Background(), &transport.Request{
err := handler.HandleUnary(context.Background(), &transport.Request{
Procedure: "foo",
Encoding: "json",
Body: jsonBody(`{"foo": 42, "bar": ["a", "b", "c"]}`),
Expand All @@ -87,7 +87,7 @@ func TestHandleInterfaceEmptySuccess(t *testing.T) {
handler := jsonHandler{reader: ifaceEmptyReader{}, handler: reflect.ValueOf(h)}

resw := new(transporttest.FakeResponseWriter)
err := handler.Handle(context.Background(), &transport.Request{
err := handler.HandleUnary(context.Background(), &transport.Request{
Procedure: "foo",
Encoding: "json",
Body: jsonBody(`["a", "b", "c"]`),
Expand All @@ -109,7 +109,7 @@ func TestHandleSuccessWithResponseHeaders(t *testing.T) {
}

resw := new(transporttest.FakeResponseWriter)
err := handler.Handle(context.Background(), &transport.Request{
err := handler.HandleUnary(context.Background(), &transport.Request{
Procedure: "simpleCall",
Encoding: "json",
Body: jsonBody(`{"name": "foo", "attributes": {"bar": 42}}`),
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c jsonClient) Call(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody
}

treq.Body = bytes.NewReader(encoded)
tres, err := c.ch.GetOutbound().Call(ctx, &treq)
tres, err := c.ch.GetUnaryOutbound().Call(ctx, &treq)

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestCall(t *testing.T) {
}

for _, tt := range tests {
outbound := transporttest.NewMockOutbound(mockCtrl)
outbound := transporttest.NewMockUnaryOutbound(mockCtrl)
client := New(transport.IdentityChannel(caller, service, outbound))

if !tt.noCall {
Expand Down
8 changes: 4 additions & 4 deletions encoding/json/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func Procedure(name string, handler interface{}) []transport.Registrant {
return []transport.Registrant{
{
Procedure: name,
Handler: wrapHandler(name, handler),
Handler: wrapUnaryHandler(name, handler),
},
}
}

// wrapHandler takes a valid JSON handler function and converts it into a
// transport.Handler.
func wrapHandler(name string, handler interface{}) transport.Handler {
// wrapUnaryHandler takes a valid JSON handler function and converts it into a
// transport.UnaryHandler.
func wrapUnaryHandler(name string, handler interface{}) transport.UnaryHandler {
reqBodyType := verifySignature(name, reflect.TypeOf(handler))

var r requestReader
Expand Down
6 changes: 3 additions & 3 deletions encoding/json/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func TestWrapHandlerInvalid(t *testing.T) {

for _, tt := range tests {
assert.Panics(t, assert.PanicTestFunc(func() {
wrapHandler(tt.Name, tt.Func)
wrapUnaryHandler(tt.Name, tt.Func)
}))
}
}

func TestWrapHandlerValid(t *testing.T) {
func TestWrapUnaryHandlerValid(t *testing.T) {
tests := []struct {
Name string
Func interface{}
Expand Down Expand Up @@ -98,6 +98,6 @@ func TestWrapHandlerValid(t *testing.T) {
}

for _, tt := range tests {
wrapHandler(tt.Name, tt.Func)
wrapUnaryHandler(tt.Name, tt.Func)
}
}
8 changes: 4 additions & 4 deletions encoding/raw/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
"go.uber.org/yarpc/transport"
)

// rawHandler adapts a Handler into a transport.Handler
// rawHandler adapts a Handler into a transport.UnaryHandler
type rawHandler struct {
h Handler
UnaryHandler UnaryHandler
}

func (r rawHandler) Handle(ctx context.Context, treq *transport.Request, rw transport.ResponseWriter) error {
func (r rawHandler) HandleUnary(ctx context.Context, treq *transport.Request, rw transport.ResponseWriter) error {
if err := encoding.Expect(treq, Encoding); err != nil {
return err
}
Expand All @@ -45,7 +45,7 @@ func (r rawHandler) Handle(ctx context.Context, treq *transport.Request, rw tran
}

reqMeta := meta.FromTransportRequest(treq)
resBody, resMeta, err := r.h(ctx, reqMeta, reqBody)
resBody, resMeta, err := r.UnaryHandler(ctx, reqMeta, reqBody)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions encoding/raw/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestRawHandler(t *testing.T) {
procedure string
headers transport.Headers
bodyChunks [][]byte
handler Handler
handler UnaryHandler

wantErr string
wantHeaders transport.Headers
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRawHandler(t *testing.T) {
}

for _, tt := range tests {
handler := rawHandler{tt.handler}
handler := rawHandler{UnaryHandler: tt.handler}
resw := new(transporttest.FakeResponseWriter)

writer, chunkReader := testreader.ChunkReader()
Expand All @@ -109,7 +109,7 @@ func TestRawHandler(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

err := handler.Handle(ctx, &transport.Request{
err := handler.HandleUnary(ctx, &transport.Request{
Procedure: tt.procedure,
Headers: tt.headers,
Encoding: "raw",
Expand Down
Loading

0 comments on commit 5a1b224

Please sign in to comment.