Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["client_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/service/main/seq-server/model:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
importpath = "go-common/app/service/main/seq-server/rpc/client",
tags = ["automanaged"],
deps = [
"//app/service/main/seq-server/model:go_default_library",
"//library/net/rpc:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,41 @@
package client
import (
"context"
"go-common/app/service/main/seq-server/model"
"go-common/library/net/rpc"
)
const (
_ID = "RPC.ID"
_IDInt32 = "RPC.ID32"
)
const (
_appid = "seq.server"
)
// Service2 is seq rpc client.
type Service2 struct {
client *rpc.Client2
}
// New2 new a seq rpc client.
func New2(c *rpc.ClientConfig) (s *Service2) {
s = &Service2{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
// ID get id.
func (s *Service2) ID(c context.Context, arg *model.ArgBusiness) (id int64, err error) {
err = s.client.Call(c, _ID, arg, &id)
return
}
// ID32 get id32.
func (s *Service2) ID32(c context.Context, arg *model.ArgBusiness) (id int32, err error) {
err = s.client.Call(c, _IDInt32, arg, &id)
return
}

View File

@@ -0,0 +1,51 @@
package client
import (
"context"
"testing"
"time"
"go-common/app/service/main/seq-server/model"
)
func TestDynamic(t *testing.T) {
s := New2(nil)
time.Sleep(5 * time.Second)
testID(t, s)
testID32(t, s)
}
func testID(t *testing.T, s *Service2) {
res := make(map[int64]struct{})
for i := 0; i < 10000; i++ {
id, err := s.ID(context.TODO(), &model.ArgBusiness{BusinessID: 7, Token: "RA8yy0RjDCBTGgFUha4hPOnhxfXvM8hR"})
if err != nil {
t.Errorf("s.ID error(%v)", err)
continue
}
if _, ok := res[id]; ok {
t.Errorf("s.ID repeat id:%d", id)
t.FailNow()
}
res[id] = struct{}{}
t.Logf("got ID(%d)", id)
}
}
func testID32(t *testing.T, s *Service2) {
res := make(map[int32]struct{})
for i := 0; i < 10000; i++ {
id, err := s.ID32(context.TODO(), &model.ArgBusiness{BusinessID: 7, Token: "RA8yy0RjDCBTGgFUha4hPOnhxfXvM8hR"})
if err != nil {
t.Errorf("s.ID error(%v)", err)
continue
}
if _, ok := res[id]; ok {
t.Errorf("s.ID repeat id:%d", id)
t.FailNow()
}
res[id] = struct{}{}
t.Logf("got ID(%d)", id)
}
}