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

feat: add dubbo2kitex crosstest for basic type byte, []byte, int8 #32

Merged
merged 2 commits into from
Aug 19, 2023
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
4 changes: 4 additions & 0 deletions pkg/hessian2/hessian2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func NewEncoder() iface.Encoder {
func NewDecoder(b []byte) iface.Decoder {
return hessian.NewDecoder(b)
}

func ReflectResponse(int, out interface{}) error {
return hessian.ReflectResponse(int, out)
}
106 changes: 106 additions & 0 deletions tests/crosstest/dubbo2kitex/basic_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2023 CloudWeGo Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dubbo2kitex

import (
"context"
"helloworld/api"
"log"
"net"
"reflect"
"testing"

"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo/testservice"
"github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo/testsuite"
)

var cli = api.UserProviderClient

// runKitexServer starts Kitex server for testing based on specified address.
// use startCh to tell outer layer that Kitex server has already started.
// use exitCh to receive exiting signal.
func runKitexServer(startCh chan struct{}, exitCh chan error, addr string) {
netAddr, _ := net.ResolveTCPAddr("tcp", addr)
svr := testservice.NewServer(
new(testsuite.TestServiceImpl),
server.WithServiceAddr(netAddr),
server.WithExitSignal(func() <-chan error {
return exitCh
}),
)
server.RegisterStartHook(func() {
close(startCh)
})

if err := svr.Run(); err != nil {
log.Fatal(err)
}
}

func TestMain(m *testing.M) {
startCh := make(chan struct{})
exitCh := make(chan error)
go runKitexServer(startCh, exitCh, "127.0.0.1:20000")
<-startCh
// init dubbo cli until kitex srv has started
if err := config.Load(config.WithPath("./conf/dubbogo.yaml")); err != nil {
panic(err)
}
m.Run()
exitCh <- nil
}

func TestEchoByte(t *testing.T) {
var req byte = 12
resp, err := cli.EchoByte(context.Background(), req)
assertEcho(t, err, req, resp)
}

func TestEchoBytes(t *testing.T) {
req := []byte{1, 2}
resp, err := cli.EchoBytes(context.Background(), req)
assertEcho(t, err, req, resp)
}

func TestEchoInt8(t *testing.T) {
var req int8 = 12
resp, err := cli.EchoInt8(context.Background(), req)
assertEcho(t, err, req, resp)
}

// todo(DMwangnima): enhance hessian2.ReflectResponse to support reflecting []int8
//func TestEchoInt8s(t *testing.T) {
// var req = []int8{1, 2}
// resp, err := cli.EchoInt8s(context.Background(), req)
// assertEcho(t, err, req, resp)
// select {}
//}

func assertEcho(t *testing.T, err error, req, resp interface{}) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(req, resp) {
t.Fatalf("req is not equal to resp, req: %v, resp: %v", req, resp)
}
}
7 changes: 7 additions & 0 deletions tests/crosstest/dubbo2kitex/conf/dubbogo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dubbo:
consumer:
references:
UserProvider:
protocol: dubbo # dubbo protocol with hessian2 codec
interface: TestService # should be consistent with Java class
url: "dubbo://127.0.0.1:20000"
158 changes: 158 additions & 0 deletions tests/crosstest/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
module github.com/kitex-contrib/codec-dubbo/tests/crosstest

go 1.20

require (
dubbo.apache.org/dubbo-go/v3 v3.1.0
github.com/cloudwego/kitex v0.6.2-0.20230815060351-88ea60530d40
github.com/kitex-contrib/codec-dubbo/tests/kitex v0.0.0
helloworld v0.0.0
)

replace (
github.com/kitex-contrib/codec-dubbo/tests/kitex => ../kitex
helloworld => ../dubbo
github.com/kitex-contrib/codec-dubbo => ../../
)

require (
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
github.com/RoaringBitmap/roaring v1.2.3 // indirect
github.com/Workiva/go-datastructures v1.0.52 // indirect
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 // indirect
github.com/alibaba/sentinel-golang v1.0.4 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect
github.com/apache/dubbo-getty v1.4.9 // indirect
github.com/apache/dubbo-go-hessian2 v1.12.2 // indirect
github.com/apache/thrift v0.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/choleraehyq/pid v0.0.17 // indirect
github.com/cloudwego/configmanager v0.2.0 // indirect
github.com/cloudwego/dynamicgo v0.1.2 // indirect
github.com/cloudwego/fastpb v0.0.4 // indirect
github.com/cloudwego/frugal v0.1.7 // indirect
github.com/cloudwego/localsession v0.0.2 // indirect
github.com/cloudwego/netpoll v0.4.1 // indirect
github.com/cloudwego/thriftgo v0.3.0 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/creasty/defaults v1.5.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 // indirect
github.com/dubbogo/gost v1.14.0 // indirect
github.com/dubbogo/grpc-go v1.42.10 // indirect
github.com/dubbogo/triple v1.2.2-rc3 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/envoyproxy/go-control-plane v0.11.0 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-co-op/gocron v1.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/vault/sdk v0.7.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/influxdata/tdigest v0.0.1 // indirect
github.com/jhump/protoreflect v1.8.2 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k0kubun/pp v3.0.1+incompatible // indirect
github.com/kitex-contrib/codec-dubbo v0.0.0-20230817144706-07db3a9b55f8 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/nacos-group/nacos-sdk-go/v2 v2.2.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/oleiade/lane v1.0.1 // indirect
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polarismesh/polaris-go v1.3.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/tidwall/gjson v1.9.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
go.opentelemetry.io/otel v1.11.0 // indirect
go.opentelemetry.io/otel/trace v1.11.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading