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

Added integration in Shard Distributor with the generated handler #6521

Merged
merged 3 commits into from
Nov 29, 2024
Merged
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
72 changes: 72 additions & 0 deletions common/types/mapper/proto/sharddistributor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 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 proto

import (
sharddistributorv1 "github.com/uber/cadence/.gen/proto/sharddistributor/v1"
"github.com/uber/cadence/common/types"
)

// FromShardDistributorGetShardOwnerRequest converts a types.GetShardOwnerRequest to a sharddistributor.GetShardOwnerRequest
func FromShardDistributorGetShardOwnerRequest(t *types.GetShardOwnerRequest) *sharddistributorv1.GetShardOwnerRequest {
if t == nil {
return nil
}
return &sharddistributorv1.GetShardOwnerRequest{
ShardKey: t.GetShardKey(),
Namespace: t.GetNamespace(),
}
}

// ToShardDistributorGetShardOwnerRequest converts a sharddistributor.GetShardOwnerRequest to a types.GetShardOwnerRequest
func ToShardDistributorGetShardOwnerRequest(t *sharddistributorv1.GetShardOwnerRequest) *types.GetShardOwnerRequest {
if t == nil {
return nil
}
return &types.GetShardOwnerRequest{
ShardKey: t.GetShardKey(),
Namespace: t.GetNamespace(),
}
}

// FromShardDistributorGetShardOwnerResponse converts a types.GetShardOwnerResponse to a sharddistributor.GetShardOwnerResponse
func FromShardDistributorGetShardOwnerResponse(t *types.GetShardOwnerResponse) *sharddistributorv1.GetShardOwnerResponse {
if t == nil {
return nil
}
return &sharddistributorv1.GetShardOwnerResponse{
Owner: t.GetOwner(),
Namespace: t.GetNamespace(),
}
}

// ToShardDistributorGetShardOwnerResponse converts a sharddistributor.GetShardOwnerResponse to a types.GetShardOwnerResponse
func ToShardDistributorGetShardOwnerResponse(t *sharddistributorv1.GetShardOwnerResponse) *types.GetShardOwnerResponse {
if t == nil {
return nil
}
return &types.GetShardOwnerResponse{
Owner: t.GetOwner(),
Namespace: t.GetNamespace(),
}
}
44 changes: 44 additions & 0 deletions common/types/mapper/proto/sharddistributor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 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 proto

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/uber/cadence/common/types"
"github.com/uber/cadence/common/types/testdata"
)

func TestFromShardDistributorGetShardOwnerRequest(t *testing.T) {
for _, item := range []*types.GetShardOwnerRequest{nil, {}, &testdata.ShardDistributorGetShardOwnerRequest} {
assert.Equal(t, item, ToShardDistributorGetShardOwnerRequest(FromShardDistributorGetShardOwnerRequest(item)))
}
}

func TestFromShardDistributorGetShardOwnerResponse(t *testing.T) {
for _, item := range []*types.GetShardOwnerResponse{nil, {}, &testdata.ShardDistributorGetShardOwnerResponse} {
assert.Equal(t, item, ToShardDistributorGetShardOwnerResponse(FromShardDistributorGetShardOwnerResponse(item)))
}
}
61 changes: 61 additions & 0 deletions common/types/sharddistributor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 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 types

type GetShardOwnerRequest struct {
ShardKey string
Namespace string
}

func (v *GetShardOwnerRequest) GetShardKey() (o string) {
if v != nil {
return v.ShardKey
}
return
}

func (v *GetShardOwnerRequest) GetNamespace() (o string) {
if v != nil {
return v.Namespace
}
return
}

type GetShardOwnerResponse struct {
Owner string
Namespace string
}

func (v *GetShardOwnerResponse) GetOwner() (o string) {
if v != nil {
return v.Owner
}
return
}

func (v *GetShardOwnerResponse) GetNamespace() (o string) {
if v != nil {
return v.Namespace
}
return
}
153 changes: 153 additions & 0 deletions common/types/sharddistributor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 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 types

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetShardOwnerRequest_GetShardKey(t *testing.T) {
tests := []struct {
name string
req *GetShardOwnerRequest
want string
}{
{
name: "nil request",
req: nil,
want: "",
},
{
name: "empty request",
req: &GetShardOwnerRequest{},
want: "",
},
{
name: "has shard key",
req: &GetShardOwnerRequest{ShardKey: "shard-key"},
want: "shard-key",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.req.GetShardKey()
assert.Equal(t, tt.want, got)
})
}
}

func TestGetShardOwnerRequest_GetNamespace(t *testing.T) {
tests := []struct {
name string
req *GetShardOwnerRequest
want string
}{
{
name: "nil request",
req: nil,
want: "",
},
{
name: "empty request",
req: &GetShardOwnerRequest{},
want: "",
},
{
name: "has namespace",
req: &GetShardOwnerRequest{Namespace: "namespace"},
want: "namespace",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.req.GetNamespace()
assert.Equal(t, tt.want, got)
})
}
}

func TestGetShardOwnerResponse_GetOwner(t *testing.T) {
tests := []struct {
name string
resp *GetShardOwnerResponse
want string
}{
{
name: "nil response",
resp: nil,
want: "",
},
{
name: "empty response",
resp: &GetShardOwnerResponse{},
want: "",
},
{
name: "has owner",
resp: &GetShardOwnerResponse{Owner: "owner"},
want: "owner",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.resp.GetOwner()
assert.Equal(t, tt.want, got)
})
}
}

func TestGetShardOwnerResponse_GetNamespace(t *testing.T) {
tests := []struct {
name string
resp *GetShardOwnerResponse
want string
}{
{
name: "nil response",
resp: nil,
want: "",
},
{
name: "empty response",
resp: &GetShardOwnerResponse{},
want: "",
},
{
name: "has namespace",
resp: &GetShardOwnerResponse{Namespace: "namespace"},
want: "namespace",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.resp.GetNamespace()
assert.Equal(t, tt.want, got)
})
}
}
36 changes: 36 additions & 0 deletions common/types/testdata/service_sharddistributor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 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 testdata

import "github.com/uber/cadence/common/types"

var (
ShardDistributorGetShardOwnerRequest = types.GetShardOwnerRequest{
ShardKey: "shard-key",
Namespace: "namespace",
}
ShardDistributorGetShardOwnerResponse = types.GetShardOwnerResponse{
Owner: "owner",
Namespace: "namespace",
}
)
1 change: 1 addition & 0 deletions config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ services:
shard-distributor:
rpc:
port: 7941
grpcPort: 7943
bindOnLocalHost: true
metrics:
statsd:
Expand Down
Loading