Skip to content

Commit

Permalink
build: remove unused modules (#27)
Browse files Browse the repository at this point in the history
* feat: remove unused modules

* update CI
  • Loading branch information
AsterDY authored Jun 28, 2023
1 parent e821b25 commit 6ec0698
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/benchmark-linux-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
- name: Testdata
run: |
go get -t github.com/cloudwego/dynamicgo/testdata
go get github.com/json-iterator/go@latest
go get github.com/thrift-iterator/go@latest
go get github.com/cloudwego/kitex/pkg/remote/codec/thrift@latest
go get github.com/cloudwego/kitex/pkg/generic@latest
go get github.com/cloudwego/frugal@latest
Expand Down
50 changes: 1 addition & 49 deletions conv/j2t/conv_timing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import (
"github.com/cloudwego/dynamicgo/conv"
"github.com/cloudwego/dynamicgo/testdata/kitex_gen/example3"

// "github.com/cloudwego/dynamicgo/thrift"
// athrift "github.com/apache/thrift/lib/go/thrift"
// kg "github.com/cloudwego/kitex/pkg/generic"
// kd "github.com/cloudwego/kitex/pkg/generic/descriptor"
// gthrift "github.com/cloudwego/kitex/pkg/generic/thrift"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -128,47 +123,4 @@ func BenchmarkConvHTTP2Thrift_Parallel_DynamicGo(b *testing.B) {
_, _ = cv.Do(ctx, desc, data)
}
})
}

// func getKitexGenericDesc() *kd.ServiceDescriptor {
// p, err := kg.NewThriftFileProvider(exampleIDLPath)
// if err != nil {
// panic(err.Error())
// }
// return <-p.Provide()
// }

// func wrapKitexGenericRequestPayload(in []byte) []byte {
// out := make([]byte, 0, len(in)+4)
// p := thrift.NewBinaryProtocol(out)
// p.WriteFieldBegin("", athrift.STRUCT, 1)
// p.Buf = append(p.Buf, in...)
// p.WriteFieldEnd()
// p.WriteStructEnd()
// return p.Buf
// }

// func BenchmarkThriftMarshalAll_KitexGeneric(b *testing.B) {
// b.Run("sequential", func(b *testing.B) {
// data := string(getExampleData())
// svcDsc := getKitexGenericDesc()
// var _args kg.Args
// _args.Method = "ExampleMethod"
// _args.Request = string(data)
// codec, err := gthrift.NewWriteJSON(svcDsc, "ExampleMethod", true)
// if err != nil {
// b.Fatal(err)
// }
// var mm = athrift.NewTMemoryBuffer()
// bc := athrift.NewTBinaryProtocol(mm, false, true)
// if err := codec.Write(context.Background(), bc, data, nil); err != nil {
// b.Fatal(err)
// }

// b.ResetTimer()
// for i := 0; i < b.N; i++ {
// mm.Reset()
// _ = codec.Write(context.Background(), bc, data, nil)
// }
// })
// }
}
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ require (
github.com/apache/thrift v0.13.0
github.com/bytedance/sonic v1.8.8
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311
github.com/choleraehyq/pid v0.0.16 // indirect
github.com/cloudwego/kitex v0.4.4
github.com/cloudwego/thriftgo v0.2.7
github.com/cloudwego/kitex v0.6.1
github.com/cloudwego/thriftgo v0.2.11
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/iancoleman/strcase v0.2.0
github.com/klauspost/cpuid/v2 v2.2.4
github.com/stretchr/testify v1.8.2
github.com/thrift-iterator/go v0.0.0-20190402154806-9b5a67519118
github.com/v2pro/plz v0.0.0-20221028024117-e5f9aec5b631 // indirect
github.com/v2pro/quokka v0.0.0-20171201153428-382cb39c6ee6 // indirect
github.com/v2pro/wombat v0.0.0-20180402055224-a56dbdcddef2 // indirect

)
127 changes: 114 additions & 13 deletions go.sum

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions testdata/binary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright 2023 CloudWeGo Authors.
*
* Licensed 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 testdata

import (
"bytes"
"encoding/hex"
"reflect"
"testing"

"github.com/cloudwego/dynamicgo/meta"
"github.com/cloudwego/dynamicgo/thrift"
thrift_iter "github.com/thrift-iterator/go"
"github.com/thrift-iterator/go/general"
"github.com/thrift-iterator/go/protocol"
)

func TestBinaryUnwrapReply(t *testing.T) {

type args struct {
proto meta.Encoding
msg general.Message
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "simple",
args: args{
proto: meta.EncodingThriftBinary,
msg: general.Message{
MessageHeader: protocol.MessageHeader{
MessageName: "GetFavoriteMethod",
MessageType: protocol.MessageTypeReply,
},
Arguments: general.Struct{
1: general.Struct{
1: int32(7749),
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// pair of buffer
inputBytes, err := thrift_iter.Marshal(tt.args.msg)
if err != nil {
t.Fatalf("failed to marshal input %s", err)
}
wantBytes, err := thrift_iter.Marshal(tt.args.msg.Arguments[1].(general.Struct))
if err != nil {
t.Fatalf("failed to marshal want bytes %s", err)
}
//
_, _, _, _, got, err := thrift.UnwrapBinaryMessage(inputBytes)
if (err != nil) != tt.wantErr {
t.Errorf("UnwrapReply() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, wantBytes) {
t.Errorf("UnwrapReply() = %s, want %s", hex.EncodeToString(got), hex.EncodeToString(wantBytes))
}
header, footer, err := thrift.GetBinaryMessageHeaderAndFooter(tt.args.msg.MessageHeader.MessageName, thrift.TMessageType(tt.args.msg.MessageHeader.MessageType), 1, 0)
if err != nil {
t.Fatalf("failed to wrap message %s", err)
}
header = append(header, got...)
header = append(header, footer...)
if !bytes.Equal(header, inputBytes) {
t.Errorf("WrapBinaryMessage() = %s, want %s", hex.EncodeToString(header), hex.EncodeToString(inputBytes))
}

})
}
}
7 changes: 4 additions & 3 deletions conv/j2t/http_conv_test.go → testdata/h2t_conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

package j2t
package testdata

import (
"context"
"testing"

"github.com/cloudwego/dynamicgo/conv"
"github.com/cloudwego/dynamicgo/conv/j2t"
"github.com/cloudwego/dynamicgo/http"
"github.com/cloudwego/dynamicgo/internal/util_test"
"github.com/cloudwego/dynamicgo/meta"
Expand All @@ -44,7 +45,7 @@ func getFnDescByPathName(t *testing.T, filePath, fnName string) *thrift.Function
return fn
}

func TestHTTPConv_Do(t *testing.T) {
func TestHTTP2ThriftConv_Do(t *testing.T) {
t.Parallel()
getFavoriteFn := getFnDescByPathName(t, "testdata/idl/example4.thrift", "GetFavoriteMethod")

Expand Down Expand Up @@ -107,7 +108,7 @@ func TestHTTPConv_Do(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
convIns := NewHTTPConv(tt.proto, tt.fn)
convIns := j2t.NewHTTPConv(tt.proto, tt.fn)
gotTbytes := make([]byte, 0, 1)
err := convIns.DoInto(context.Background(), tt.req, &gotTbytes, conv.Options{
WriteRequireField: true,
Expand Down
9 changes: 5 additions & 4 deletions conv/t2j/http_conv_test.go → testdata/t2h_conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
* limitations under the License.
*/

package t2j
package testdata

import (
"context"
"testing"

"github.com/cloudwego/dynamicgo/conv"
"github.com/cloudwego/dynamicgo/conv/t2j"
"github.com/cloudwego/dynamicgo/internal/util_test"
"github.com/cloudwego/dynamicgo/meta"
"github.com/cloudwego/dynamicgo/thrift"
"github.com/stretchr/testify/assert"
)

func TestHTTPConv_Do(t *testing.T) {
func TestThrift2HTTPConv_Do(t *testing.T) {
svc, err := thrift.NewDescritorFromPath(context.Background(), util_test.MustGitPath("testdata/idl/example4.thrift"))
if err != nil {
t.Fatal(err)
Expand All @@ -39,14 +40,14 @@ func TestHTTPConv_Do(t *testing.T) {

tests := []struct {
name string
conv *HTTPConv
conv *t2j.HTTPConv
tbytes []byte
wantErr bool
want util_test.Resp
}{
{
name: "example4",
conv: NewHTTPConv(meta.EncodingThriftBinary, fn),
conv: t2j.NewHTTPConv(meta.EncodingThriftBinary, fn),
tbytes: util_test.MustDecodeHex(
t,
"80010002000000114765744661766f726974654d6574686f64000000130c00000c000108000100001e450f00020b00000002"+
Expand Down
71 changes: 0 additions & 71 deletions thrift/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@
package thrift

import (
"bytes"
"context"
"encoding/hex"
"io/ioutil"
"os"
"reflect"
"runtime"
"runtime/debug"
"testing"
"time"

"github.com/cloudwego/dynamicgo/meta"
thrift_iter "github.com/thrift-iterator/go"
"github.com/thrift-iterator/go/general"
"github.com/thrift-iterator/go/protocol"
)

var (
Expand Down Expand Up @@ -67,67 +59,4 @@ func getExampleData() []byte {
panic(err)
}
return out
}

func TestBinaryUnwrapReply(t *testing.T) {

type args struct {
proto meta.Encoding
msg general.Message
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "simple",
args: args{
proto: meta.EncodingThriftBinary,
msg: general.Message{
MessageHeader: protocol.MessageHeader{
MessageName: "GetFavoriteMethod",
MessageType: protocol.MessageTypeReply,
},
Arguments: general.Struct{
1: general.Struct{
1: int32(7749),
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// pair of buffer
inputBytes, err := thrift_iter.Marshal(tt.args.msg)
if err != nil {
t.Fatalf("failed to marshal input %s", err)
}
wantBytes, err := thrift_iter.Marshal(tt.args.msg.Arguments[1].(general.Struct))
if err != nil {
t.Fatalf("failed to marshal want bytes %s", err)
}
//
_, _, _, _, got, err := UnwrapBinaryMessage(inputBytes)
if (err != nil) != tt.wantErr {
t.Errorf("UnwrapReply() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, wantBytes) {
t.Errorf("UnwrapReply() = %s, want %s", hex.EncodeToString(got), hex.EncodeToString(wantBytes))
}
header, footer, err := GetBinaryMessageHeaderAndFooter(tt.args.msg.MessageHeader.MessageName, TMessageType(tt.args.msg.MessageHeader.MessageType), 1, 0)
if err != nil {
t.Fatalf("failed to wrap message %s", err)
}
header = append(header, got...)
header = append(header, footer...)
if !bytes.Equal(header, inputBytes) {
t.Errorf("WrapBinaryMessage() = %s, want %s", hex.EncodeToString(header), hex.EncodeToString(inputBytes))
}

})
}
}

0 comments on commit 6ec0698

Please sign in to comment.