Skip to content
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

fix reference conflict in triple #2727

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion common/rpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ type TriplePBService interface {
}

// GetReference return the reference id of the service.
// If the service implemented the ReferencedRPCService interface,
// If the service implemented the TriplePBService or ReferencedRPCService interface,
// it will call the Reference method. If not, it will
// return the struct name as the reference id.
func GetReference(service RPCService) string {
if s, ok := service.(TriplePBService); ok {
return s.XXX_InterfaceName()
}

if s, ok := service.(ReferencedRPCService); ok {
return s.Reference()
}
Expand Down
11 changes: 11 additions & 0 deletions common/rpc_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
testInterfaceName = "testService"
testProtocol = "testprotocol"
testSuiteMethodExpectedString = "interface {}"
testTripleServiceName = "com.test.TriplePath"
)

type TestService struct{}
Expand Down Expand Up @@ -90,6 +91,12 @@ func (s *TestService1) Reference() string {
return referenceTestPathDistinct
}

type TestTriplePBService struct{}

func (s *TestTriplePBService) XXX_InterfaceName() string {
return testTripleServiceName
}

func TestServiceMapRegister(t *testing.T) {
// lowercase
s0 := &testService{}
Expand Down Expand Up @@ -250,4 +257,8 @@ func TestGetReference(t *testing.T) {
}{}
ref5 := GetReference(s5)
assert.Equal(t, expectedReference, ref5)

s6 := &TestTriplePBService{}
ref6 := GetReference(s6)
assert.Equal(t, testTripleServiceName, ref6)
}
Loading