Skip to content

Commit

Permalink
Use shared.Name instead of shared.UUID to reduce changes and keep con…
Browse files Browse the repository at this point in the history
…sistent
  • Loading branch information
Nils Dijk committed Aug 2, 2016
1 parent 221f384 commit f92ab49
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions test/remoteservice/.gitignore
@@ -1,3 +1,4 @@
*.go
!*_test.go
mocks/
.gen/
2 changes: 1 addition & 1 deletion test/remoteservice/remoteservice.thrift
Expand Up @@ -7,5 +7,5 @@ include "./shared.thrift"
include "./unused.thrift"

service RemoteService {
void RemoteCall(1: shared.UUID id)
void RemoteCall(1: shared.Name name)
}
32 changes: 16 additions & 16 deletions test/remoteservice/remoteservice_test.go
Expand Up @@ -28,7 +28,7 @@ func TestNewRingpopRemoteServiceAdapter(t *testing.T) {

adapter, err := NewRingpopRemoteServiceAdapter(serviceImpl, rp, nil, RemoteServiceConfiguration{
RemoteCall: &RemoteServiceRemoteCallConfiguration{
Key: func(ctx thrift.Context, name shared.UUID) (string, error) {
Key: func(ctx thrift.Context, name shared.Name) (string, error) {
return string(name), nil
},
},
Expand Down Expand Up @@ -62,22 +62,22 @@ func TestRingpopRemoteServiceAdapterCallLocal(t *testing.T) {
rp.On("WhoAmI").Return("127.0.0.1:3000", nil)

serviceImpl := &servicemocks.TChanRemoteService{}
serviceImpl.On("RemoteCall", mock.Anything, shared.UUID("hello")).Return(nil)
serviceImpl.On("RemoteCall", mock.Anything, shared.Name("hello")).Return(nil)
ctx, _ := thrift.NewContext(0 * time.Second)

adapter, err := NewRingpopRemoteServiceAdapter(serviceImpl, rp, nil, RemoteServiceConfiguration{
RemoteCall: &RemoteServiceRemoteCallConfiguration{
Key: func(ctx thrift.Context, name shared.UUID) (string, error) {
Key: func(ctx thrift.Context, name shared.Name) (string, error) {
return string(name), nil
},
},
})
assert.Equal(t, err, nil, "creation of adator gave an error")

err = adapter.RemoteCall(ctx, shared.UUID("hello"))
err = adapter.RemoteCall(ctx, shared.Name("hello"))
assert.Equal(t, err, nil, "calling RemoteCall gave an error")

serviceImpl.AssertCalled(t, "RemoteCall", mock.Anything, shared.UUID("hello"))
serviceImpl.AssertCalled(t, "RemoteCall", mock.Anything, shared.Name("hello"))
}

func TestRingpopRemoteServiceAdapterCallRemote(t *testing.T) {
Expand All @@ -87,15 +87,15 @@ func TestRingpopRemoteServiceAdapterCallRemote(t *testing.T) {
rp.On("WhoAmI").Return("127.0.0.1:3000", nil)

serviceImpl := &servicemocks.TChanRemoteService{}
serviceImpl.On("RemoteCall", mock.Anything, shared.UUID("hello")).Return(nil)
serviceImpl.On("RemoteCall", mock.Anything, shared.Name("hello")).Return(nil)
ctx, _ := thrift.NewContext(0 * time.Second)

ch, err := tchannel.NewChannel("remote", nil)
assert.Equal(t, err, nil, "could not create tchannel")

adapter, err := NewRingpopRemoteServiceAdapter(serviceImpl, rp, ch, RemoteServiceConfiguration{
RemoteCall: &RemoteServiceRemoteCallConfiguration{
Key: func(ctx thrift.Context, name shared.UUID) (string, error) {
Key: func(ctx thrift.Context, name shared.Name) (string, error) {
return string(name), nil
},
},
Expand All @@ -116,25 +116,25 @@ func TestGetLocalClient(t *testing.T) {
rp.On("WhoAmI").Return("127.0.0.1:3000")

serviceImpl := &servicemocks.TChanRemoteService{}
serviceImpl.On("RemoteCall", mock.Anything, shared.UUID("hello")).Return(nil)
serviceImpl.On("RemoteCall", mock.Anything, shared.Name("hello")).Return(nil)
ctx, _ := thrift.NewContext(0 * time.Second)

ch, err := tchannel.NewChannel("remote", nil)
assert.Equal(t, err, nil, "could not create tchannel")

adapter, err := NewRingpopRemoteServiceAdapter(serviceImpl, rp, ch, RemoteServiceConfiguration{
RemoteCall: &RemoteServiceRemoteCallConfiguration{
Key: func(ctx thrift.Context, name shared.UUID) (string, error) {
Key: func(ctx thrift.Context, name shared.Name) (string, error) {
return string(name), nil
},
},
})

cf := adapter.(router.ClientFactory)
localClient := cf.GetLocalClient().(TChanRemoteService)
err = localClient.RemoteCall(ctx, shared.UUID("hello"))
err = localClient.RemoteCall(ctx, shared.Name("hello"))
assert.Equal(t, err, nil, "calling the local client gave an error")
serviceImpl.AssertCalled(t, "RemoteCall", mock.Anything, shared.UUID("hello"))
serviceImpl.AssertCalled(t, "RemoteCall", mock.Anything, shared.Name("hello"))

}

Expand All @@ -145,27 +145,27 @@ func TestMakeRemoteClient(t *testing.T) {
rp.On("WhoAmI").Return("127.0.0.1:3000")

serviceImpl := &servicemocks.TChanRemoteService{}
serviceImpl.On("RemoteCall", mock.Anything, shared.UUID("hello")).Return(nil)
serviceImpl.On("RemoteCall", mock.Anything, shared.Name("hello")).Return(nil)
ctx, _ := thrift.NewContext(0 * time.Second)

ch, err := tchannel.NewChannel("remote", nil)
assert.Equal(t, err, nil, "could not create tchannel")

adapter, err := NewRingpopRemoteServiceAdapter(serviceImpl, rp, ch, RemoteServiceConfiguration{
RemoteCall: &RemoteServiceRemoteCallConfiguration{
Key: func(ctx thrift.Context, name shared.UUID) (string, error) {
Key: func(ctx thrift.Context, name shared.Name) (string, error) {
return string(name), nil
},
},
})

tchanClient := &mocks.TChanClient{}
tchanClient.On("Call", mock.Anything, "RemoteService", "RemoteCall", &RemoteServiceRemoteCallArgs{ID: shared.UUID("hello")}, mock.Anything).Return(true, nil)
tchanClient.On("Call", mock.Anything, "RemoteService", "RemoteCall", &RemoteServiceRemoteCallArgs{Name: shared.Name("hello")}, mock.Anything).Return(true, nil)

cf := adapter.(router.ClientFactory)
remoteClient := cf.MakeRemoteClient(tchanClient).(TChanRemoteService)
err = remoteClient.RemoteCall(ctx, shared.UUID("hello"))
err = remoteClient.RemoteCall(ctx, shared.Name("hello"))
assert.Equal(t, err, nil, "calling the remote client gave an error")

tchanClient.AssertCalled(t, "Call", mock.Anything, "RemoteService", "RemoteCall", &RemoteServiceRemoteCallArgs{ID: shared.UUID("hello")}, mock.Anything)
tchanClient.AssertCalled(t, "Call", mock.Anything, "RemoteService", "RemoteCall", &RemoteServiceRemoteCallArgs{Name: shared.Name("hello")}, mock.Anything)
}
2 changes: 1 addition & 1 deletion test/remoteservice/shared.thrift
@@ -1 +1 @@
typedef string UUID
typedef string Name

0 comments on commit f92ab49

Please sign in to comment.