Skip to content

Commit

Permalink
Merge af0c6cf into dcb7fef
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Dec 7, 2016
2 parents dcb7fef + af0c6cf commit 2d58b40
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 321 deletions.
36 changes: 17 additions & 19 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,17 @@ func Benchmark_HTTP_NetHTTPToNetHTTP(b *testing.B) {
}

func Benchmark_TChannel_YARPCToYARPC(b *testing.B) {
serverCh, err := tchannel.NewChannel("server", nil)
require.NoError(b, err, "failed to build server TChannel")

serverTChannel := ytchannel.NewChannelTransport(
ytchannel.WithServiceName("server"),
)
serverCfg := yarpc.Config{
Name: "server",
Inbounds: yarpc.Inbounds{ytchannel.NewInbound(serverCh)},
Inbounds: yarpc.Inbounds{serverTChannel.NewInbound()},
}

clientCh, err := tchannel.NewChannel("client", nil)
require.NoError(b, err, "failed to build client TChannel")
clientTChannel := ytchannel.NewChannelTransport(
ytchannel.WithServiceName("client"),
)

// no defer close on channels because YARPC will take care of that

Expand All @@ -208,8 +209,7 @@ func Benchmark_TChannel_YARPCToYARPC(b *testing.B) {
Name: "client",
Outbounds: yarpc.Outbounds{
"server": {
Unary: ytchannel.NewOutbound(clientCh).
WithHostPort(serverCh.PeerInfo().HostPort),
Unary: clientTChannel.NewSingleOutbound(serverTChannel.ListenAddr()),
},
},
}
Expand All @@ -228,15 +228,12 @@ func Benchmark_TChannel_YARPCToTChannel(b *testing.B) {
serverCh.Register(traw.Wrap(tchannelEcho{t: b}), "echo")
require.NoError(b, serverCh.ListenAndServe(":0"), "failed to start up TChannel")

clientCh, err := tchannel.NewChannel("client", nil)
require.NoError(b, err, "failed to build client TChannel")

clientTChannel := ytchannel.NewChannelTransport(ytchannel.WithServiceName("client"))
clientCfg := yarpc.Config{
Name: "client",
Outbounds: yarpc.Outbounds{
"server": {
Unary: ytchannel.NewOutbound(clientCh).
WithHostPort(serverCh.PeerInfo().HostPort),
Unary: clientTChannel.NewSingleOutbound(serverCh.PeerInfo().HostPort),
},
},
}
Expand All @@ -248,23 +245,24 @@ func Benchmark_TChannel_YARPCToTChannel(b *testing.B) {
}

func Benchmark_TChannel_TChannelToYARPC(b *testing.B) {
serverCh, err := tchannel.NewChannel("server", nil)
require.NoError(b, err, "failed to build server TChannel")
tchannelTransport := ytchannel.NewChannelTransport(
ytchannel.WithServiceName("server"),
)

serverCfg := yarpc.Config{
Name: "server",
Inbounds: yarpc.Inbounds{ytchannel.NewInbound(serverCh)},
Inbounds: yarpc.Inbounds{tchannelTransport.NewInbound()},
}

withDispatcher(b, serverCfg, func(server yarpc.Dispatcher) {
server.Register(raw.Procedure("echo", yarpcEcho))
withDispatcher(b, serverCfg, func(dispatcher yarpc.Dispatcher) {
dispatcher.Register(raw.Procedure("echo", yarpcEcho))

clientCh, err := tchannel.NewChannel("client", nil)
require.NoError(b, err, "failed to build client TChannel")
defer clientCh.Close()

b.ResetTimer()
runTChannelClient(b, clientCh, serverCh.PeerInfo().HostPort)
runTChannelClient(b, clientCh, tchannelTransport.ListenAddr())
})
}

Expand Down
13 changes: 5 additions & 8 deletions dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@ import (
. "go.uber.org/yarpc"
"go.uber.org/yarpc/transport"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"
"go.uber.org/yarpc/transport/tchannel"
"go.uber.org/yarpc/transport/transporttest"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber/tchannel-go"
)

func basicDispatcher(t *testing.T) Dispatcher {
ch, err := tchannel.NewChannel("test", nil)
require.NoError(t, err, "failed to create TChannel")

httpTransport := http.NewTransport()
tchannelTransport := tchannel.NewChannelTransport(tchannel.WithServiceName("test"))
return NewDispatcher(Config{
Name: "test",
Inbounds: Inbounds{
tch.NewInbound(ch).WithListenAddr(":0"),
tchannelTransport.NewInbound(),
httpTransport.NewInbound(":0"),
},
})
Expand Down Expand Up @@ -74,7 +71,7 @@ func TestInboundsOrderIsMaintained(t *testing.T) {
dispatcher := basicDispatcher(t)

// Order must be maintained
_, ok := dispatcher.Inbounds()[0].(*tch.Inbound)
_, ok := dispatcher.Inbounds()[0].(*tchannel.ChannelInbound)
assert.True(t, ok, "first inbound must be TChannel")

_, ok = dispatcher.Inbounds()[1].(*http.Inbound)
Expand All @@ -89,7 +86,7 @@ func TestInboundsOrderAfterStart(t *testing.T) {

inbounds := dispatcher.Inbounds()

tchInbound := inbounds[0].(*tch.Inbound)
tchInbound := inbounds[0].(*tchannel.ChannelInbound)
assert.NotEqual(t, "0.0.0.0:0", tchInbound.Channel().PeerInfo().HostPort)

httpInbound := inbounds[1].(*http.Inbound)
Expand Down
9 changes: 3 additions & 6 deletions internal/crossdock/client/ctxpropagation/behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

"github.com/crossdock/crossdock-go"
"github.com/opentracing/opentracing-go"
"github.com/uber/tchannel-go"
)

// Run verifies that opentracing context is propagated across multiple hops.
Expand Down Expand Up @@ -319,18 +318,16 @@ func buildDispatcher(t crossdock.T) (dispatcher yarpc.Dispatcher, tconfig server
fatals.NotEmpty(self, "ctxclient is required")
fatals.NotEmpty(subject, "ctxserver is required")

ch, err := tchannel.NewChannel("ctxclient", nil)
fatals.NoError(err, "failed to create TChannel")

httpTransport := http.NewTransport()
tchannelTransport := tch.NewChannelTransport(tch.WithListenAddr(":8087"), tch.WithServiceName("ctxclient"))

var outbound transport.UnaryOutbound
switch trans := t.Param(params.Transport); trans {
case "http":
outbound = httpTransport.NewSingleOutbound(fmt.Sprintf("http://%s:8081", subject))
tconfig.TChannel = &server.TChannelTransport{Host: self, Port: 8087}
case "tchannel":
outbound = tch.NewOutbound(ch).WithHostPort(fmt.Sprintf("%s:8082", subject))
outbound = tchannelTransport.NewSingleOutbound(fmt.Sprintf("%s:8082", subject))
tconfig.HTTP = &server.HTTPTransport{Host: self, Port: 8086}
default:
fatals.Fail("", "unknown transport %q", trans)
Expand All @@ -339,7 +336,7 @@ func buildDispatcher(t crossdock.T) (dispatcher yarpc.Dispatcher, tconfig server
dispatcher = yarpc.NewDispatcher(yarpc.Config{
Name: "ctxclient",
Inbounds: yarpc.Inbounds{
tch.NewInbound(ch).WithListenAddr(":8087"),
tchannelTransport.NewInbound(),
httpTransport.NewInbound(":8086"),
},
Outbounds: yarpc.Outbounds{
Expand Down
11 changes: 4 additions & 7 deletions internal/crossdock/client/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import (
"go.uber.org/yarpc/internal/crossdock/client/params"
"go.uber.org/yarpc/transport"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"
"go.uber.org/yarpc/transport/tchannel"

"github.com/crossdock/crossdock-go"
"github.com/uber/tchannel-go"
)

// Create creates an RPC from the given parameters or fails the whole behavior.
Expand All @@ -41,17 +40,15 @@ func Create(t crossdock.T) yarpc.Dispatcher {
server := t.Param(params.Server)
fatals.NotEmpty(server, "server is required")

httpTransport := http.NewTransport()

var unaryOutbound transport.UnaryOutbound
trans := t.Param(params.Transport)
switch trans {
case "http":
httpTransport := http.NewTransport()
unaryOutbound = httpTransport.NewSingleOutbound(fmt.Sprintf("http://%s:8081", server))
case "tchannel":
ch, err := tchannel.NewChannel("client", nil)
fatals.NoError(err, "couldn't create tchannel")
unaryOutbound = tch.NewOutbound(ch).WithHostPort(server + ":8082")
tchannelTransport := tchannel.NewChannelTransport(tchannel.WithServiceName("client"))
unaryOutbound = tchannelTransport.NewSingleOutbound(server + ":8082")
default:
fatals.Fail("", "unknown transport %q", trans)
}
Expand Down
9 changes: 3 additions & 6 deletions internal/crossdock/client/tchserver/behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import (

"go.uber.org/yarpc"
"go.uber.org/yarpc/internal/crossdock/client/params"
tch "go.uber.org/yarpc/transport/tchannel"
"go.uber.org/yarpc/transport/tchannel"

"github.com/crossdock/crossdock-go"
"github.com/uber/tchannel-go"
)

const (
Expand All @@ -44,14 +43,12 @@ func Run(t crossdock.T) {
server := t.Param(params.Server)
serverHostPort := fmt.Sprintf("%v:%v", server, serverPort)

ch, err := tchannel.NewChannel("yarpc-client", nil)
fatals.NoError(err, "could not create channel")

tchannelTransport := tchannel.NewChannelTransport(tchannel.WithServiceName("yarpc-client"))
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: "yarpc-client",
Outbounds: yarpc.Outbounds{
serverName: {
Unary: tch.NewOutbound(ch).WithHostPort(serverHostPort),
Unary: tchannelTransport.NewSingleOutbound(serverHostPort),
},
},
})
Expand Down
11 changes: 3 additions & 8 deletions internal/crossdock/server/yarpc/phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import (
"go.uber.org/yarpc/internal/clientconfig"
"go.uber.org/yarpc/transport"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"

"github.com/uber/tchannel-go"
"go.uber.org/yarpc/transport/tchannel"
)

// HTTPTransport contains information about an HTTP transport.
Expand Down Expand Up @@ -74,6 +72,7 @@ func Phone(ctx context.Context, reqMeta yarpc.ReqMeta, body *PhoneRequest) (*Pho
var outbound transport.UnaryOutbound

httpTransport := http.NewTransport()
tchannelTransport := tchannel.NewChannelTransport(tchannel.WithServiceName("yarpc-test-client"))

switch {
case body.Transport.HTTP != nil:
Expand All @@ -82,11 +81,7 @@ func Phone(ctx context.Context, reqMeta yarpc.ReqMeta, body *PhoneRequest) (*Pho
case body.Transport.TChannel != nil:
t := body.Transport.TChannel
hostport := fmt.Sprintf("%s:%d", t.Host, t.Port)
ch, err := tchannel.NewChannel("yarpc-test-client", nil)
if err != nil {
return nil, nil, fmt.Errorf("failed to build TChannel: %v", err)
}
outbound = tch.NewOutbound(ch).WithHostPort(hostport)
outbound = tchannelTransport.NewSingleOutbound(hostport)
default:
return nil, nil, fmt.Errorf("unconfigured transport")
}
Expand Down
16 changes: 6 additions & 10 deletions internal/crossdock/server/yarpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package yarpc

import (
"fmt"
"log"

"go.uber.org/yarpc"
"go.uber.org/yarpc/encoding/json"
Expand All @@ -32,26 +31,23 @@ import (
"go.uber.org/yarpc/internal/crossdock/thrift/gauntlet/yarpc/thrifttestserver"
"go.uber.org/yarpc/transport"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"

"github.com/uber/tchannel-go"
"go.uber.org/yarpc/transport/tchannel"
)

var dispatcher yarpc.Dispatcher

// Start starts the test server that clients will make requests to
func Start() {
ch, err := tchannel.NewChannel("yarpc-test", nil)
if err != nil {
log.Fatalln("couldn't create tchannel: %v", err)
}

tchannelTransport := tchannel.NewChannelTransport(
tchannel.WithListenAddr(":8082"),
tchannel.WithServiceName("yarpc-test"),
)
httpTransport := http.NewTransport()
dispatcher = yarpc.NewDispatcher(yarpc.Config{
Name: "yarpc-test",
Inbounds: yarpc.Inbounds{
tchannelTransport.NewInbound(),
httpTransport.NewInbound(":8081"),
tch.NewInbound(ch).WithListenAddr(":8082"),
},
})

Expand Down
11 changes: 3 additions & 8 deletions internal/examples/json/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import (
"go.uber.org/yarpc/encoding/json"
"go.uber.org/yarpc/transport"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"

"github.com/uber/tchannel-go"
"go.uber.org/yarpc/transport/tchannel"
)

type getRequest struct {
Expand Down Expand Up @@ -91,17 +89,14 @@ func main() {
flag.Parse()

httpTransport := http.NewTransport()
tchannelTransport := tchannel.NewChannelTransport(tchannel.WithServiceName("keyvalue-client"))

var outbound transport.UnaryOutbound
switch strings.ToLower(outboundName) {
case "http":
outbound = httpTransport.NewSingleOutbound("http://127.0.0.1:24034")
case "tchannel":
channel, err := tchannel.NewChannel("keyvalue-client", nil)
if err != nil {
log.Fatalln(err)
}
outbound = tch.NewOutbound(channel).WithHostPort("localhost:28941")
outbound = tchannelTransport.NewSingleOutbound("localhost:28941")
default:
log.Fatalf("invalid outbound: %q\n", outboundName)
}
Expand Down
16 changes: 6 additions & 10 deletions internal/examples/json/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ package main
import (
"context"
"fmt"
"log"
"os"
"sync"

"go.uber.org/yarpc"
"go.uber.org/yarpc/encoding/json"
"go.uber.org/yarpc/transport/http"
tch "go.uber.org/yarpc/transport/tchannel"

"github.com/uber/tchannel-go"
"go.uber.org/yarpc/transport/tchannel"
)

type getRequest struct {
Expand Down Expand Up @@ -72,16 +69,15 @@ func (h *handler) Set(ctx context.Context, reqMeta yarpc.ReqMeta, body *setReque
}

func main() {
channel, err := tchannel.NewChannel("keyvalue", nil)
if err != nil {
log.Fatalln(err)
}

tchannelTransport := tchannel.NewChannelTransport(
tchannel.WithServiceName("keyvalue"),
tchannel.WithListenAddr(":28941"),
)
httpTransport := http.NewTransport()
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: "keyvalue",
Inbounds: yarpc.Inbounds{
tch.NewInbound(channel).WithListenAddr(":28941"),
tchannelTransport.NewInbound(),
httpTransport.NewInbound(":24034"),
},
InboundMiddleware: yarpc.InboundMiddleware{
Expand Down

0 comments on commit 2d58b40

Please sign in to comment.