Skip to content

Commit

Permalink
chore(generic): remove deprecated apis/interfaces/variables (cloudweg…
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina-Sakai authored Nov 18, 2024
1 parent 2df8dfa commit 85107b7
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 67 deletions.
3 changes: 0 additions & 3 deletions client/genericclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func NewClient(destService string, g generic.Generic, opts ...client.Option) (Cl

// NewClientWithServiceInfo create a generic client with serviceInfo
func NewClientWithServiceInfo(destService string, g generic.Generic, svcInfo *serviceinfo.ServiceInfo, opts ...client.Option) (Client, error) {
if isDeprecated, ok := svcInfo.Extra[generic.DeprecatedGenericServiceInfoAPIKey].(bool); ok && isDeprecated {
svcInfo.Methods, svcInfo.ServiceName = generic.GetMethodInfo(g.MessageReaderWriter(), g.IDLServiceName())
}
var options []client.Option
options = append(options, client.WithGeneric(g))
options = append(options, client.WithDestService(destService))
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/binarythrift_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestBinaryThriftCodec(t *testing.T) {
return wl
},
ServiceInfoFunc: func() *serviceinfo.ServiceInfo {
return ServiceInfo(serviceinfo.Thrift)
return ServiceInfoWithGeneric(BinaryThriftGeneric())
},
}
err = btc.Unmarshal(context.Background(), svrMsg, bb)
Expand Down
18 changes: 2 additions & 16 deletions pkg/generic/generic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import (
"github.com/cloudwego/kitex/pkg/serviceinfo"
)

// TODO(marina.sakai): remove in v0.12.0
const DeprecatedGenericServiceInfoAPIKey = "deprecated_generic_service_info_api"

// Service generic service interface
type Service interface {
// GenericCall handle the generic call
Expand All @@ -41,7 +38,7 @@ type Service interface {
// ServiceInfoWithGeneric create a generic ServiceInfo
func ServiceInfoWithGeneric(g Generic) *serviceinfo.ServiceInfo {
isCombinedServices := getIsCombinedServices(g)
return newServiceInfo(g.PayloadCodecType(), g.MessageReaderWriter(), g.IDLServiceName(), isCombinedServices, true)
return newServiceInfo(g.PayloadCodecType(), g.MessageReaderWriter(), g.IDLServiceName(), isCombinedServices)
}

func getIsCombinedServices(g Generic) bool {
Expand All @@ -53,14 +50,7 @@ func getIsCombinedServices(g Generic) bool {
return false
}

// Deprecated: Replaced by ServiceInfoWithGeneric, this method will be removed in v0.12.0
// ServiceInfo create a generic ServiceInfo
// TODO(marina.sakai): remove in v0.12.0
func ServiceInfo(pcType serviceinfo.PayloadCodec) *serviceinfo.ServiceInfo {
return newServiceInfo(pcType, nil, "", false, false)
}

func newServiceInfo(pcType serviceinfo.PayloadCodec, messageReaderWriter interface{}, serviceName string, isCombinedServices, withGeneric bool) *serviceinfo.ServiceInfo {
func newServiceInfo(pcType serviceinfo.PayloadCodec, messageReaderWriter interface{}, serviceName string, isCombinedServices bool) *serviceinfo.ServiceInfo {
handlerType := (*Service)(nil)

methods, svcName := GetMethodInfo(messageReaderWriter, serviceName)
Expand All @@ -76,10 +66,6 @@ func newServiceInfo(pcType serviceinfo.PayloadCodec, messageReaderWriter interfa
if isCombinedServices {
svcInfo.Extra["combine_service"] = true
}
// TODO(marina.sakai): remove in v0.12.0
if !withGeneric {
svcInfo.Extra[DeprecatedGenericServiceInfoAPIKey] = true
}
return svcInfo
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/generic/generic_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
mocksn "github.com/cloudwego/kitex/internal/mocks"
mocks "github.com/cloudwego/kitex/internal/mocks/generic"
"github.com/cloudwego/kitex/internal/test"
"github.com/cloudwego/kitex/pkg/serviceinfo"
"github.com/cloudwego/kitex/pkg/utils"
)

Expand Down Expand Up @@ -124,14 +123,11 @@ func TestGenericService(t *testing.T) {
}

func TestServiceInfo(t *testing.T) {
s := ServiceInfo(serviceinfo.Thrift)
test.Assert(t, s.ServiceName == "$GenericService")

p, err := NewThriftFileProvider("./json_test/idl/mock.thrift")
test.Assert(t, err == nil)
g, err := JSONThriftGeneric(p)
test.Assert(t, err == nil)
s = ServiceInfoWithGeneric(g)
s := ServiceInfoWithGeneric(g)
test.Assert(t, s.ServiceName == "Mock")
}

Expand Down
29 changes: 0 additions & 29 deletions pkg/generic/map_test/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package test
import (
"context"
"encoding/base64"
"fmt"
"net"
"reflect"
"runtime"
Expand All @@ -36,9 +35,7 @@ import (
"github.com/cloudwego/kitex/internal/test"
"github.com/cloudwego/kitex/pkg/generic"
"github.com/cloudwego/kitex/pkg/generic/descriptor"
"github.com/cloudwego/kitex/pkg/serviceinfo"
"github.com/cloudwego/kitex/server"
"github.com/cloudwego/kitex/transport"
)

func TestThrift(t *testing.T) {
Expand Down Expand Up @@ -387,32 +384,6 @@ func TestThrift2NormalServer(t *testing.T) {
svr.Stop()
}

// TODO(marina.sakai): remove this test when we remove the API generic.ServiceInfo() in v0.12.0
func TestCompatible(t *testing.T) {
addr := test.GetLocalAddress()
svr := initThriftServer(t, addr, new(GenericServiceWithBase64Binary), true, false)
//lint:ignore SA1019 we will remove this later
svcInfo := generic.ServiceInfo(serviceinfo.Thrift)
p, err := generic.NewThriftFileProvider("./idl/example.thrift")
test.Assert(t, err == nil)
g, err := generic.MapThriftGeneric(p)
test.Assert(t, err == nil)
var opts []client.Option
opts = append(opts, client.WithHostPorts(addr), client.WithTransportProtocol(transport.TTHeader))
cli, err := genericclient.NewClientWithServiceInfo("destServiceName", g, svcInfo, opts...)
test.Assert(t, err == nil)

reqMsg = map[string]interface{}{"BinaryMsg": []byte("hello")}
resp, err := cli.GenericCall(context.Background(), "ExampleMethod", reqMsg, callopt.WithRPCTimeout(100*time.Second))
test.Assert(t, err == nil, err)
gr, ok := resp.(map[string]interface{})
fmt.Println(gr)
test.Assert(t, ok)
test.Assert(t, reflect.DeepEqual(gr["BinaryMsg"], "hello"))

svr.Stop()
}

func initThriftMockClient(t *testing.T, address string) genericclient.Client {
p, err := generic.NewThriftFileProvider("./idl/mock.thrift")
test.Assert(t, err == nil)
Expand Down
13 changes: 0 additions & 13 deletions pkg/generic/proto/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,9 @@ package proto

import (
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/dynamic"
)

type (
ServiceDescriptor = *desc.ServiceDescriptor
MessageDescriptor = *desc.MessageDescriptor
)

// Deprecated: this interface will be removed in v0.12.0
type Message interface {
Marshal() ([]byte, error)
TryGetFieldByNumber(fieldNumber int) (interface{}, error)
TrySetFieldByNumber(fieldNumber int, val interface{}) error
}

// Deprecated: this API will be removed in v0.12.0
func NewMessage(descriptor MessageDescriptor) Message {
return dynamic.NewMessage(descriptor)
}

0 comments on commit 85107b7

Please sign in to comment.