Ver Fonte

odb test

libf há 1 ano atrás
pai
commit
a060e3405f
6 ficheiros alterados com 57 adições e 39 exclusões
  1. 0 17
      client/client.go
  2. 1 0
      go.mod
  3. 3 0
      go.sum
  4. 48 0
      odbclient/client.go
  5. 5 22
      client/client_test.go
  6. 0 0
      odbclient/make.sh

+ 0 - 17
client/client.go

@@ -1,17 +0,0 @@
-package client
-
-import "git.wecise.com/wecise/odb-go/odb"
-
-func getClient() (c odb.Client, err error) {
-	client, err := odb.NewClient(&odb.Config{
-		// Hosts:    []string{"47.92.151.165:11001"},
-		Hosts:    []string{"127.0.0.1:11001"},
-		Keyspace: "oktest",
-		// User:     "这个客户端是用来测试的",
-		// Pass: "********",
-	})
-	if err != nil {
-		return nil, err
-	}
-	return client, nil
-}

+ 1 - 0
go.mod

@@ -12,6 +12,7 @@ require (
 	github.com/mattn/go-colorable v0.1.7 // indirect
 	github.com/mattn/go-isatty v0.0.12 // indirect
 	github.com/redis/go-redis/v9 v9.0.5 // indirect
+	github.com/scylladb/go-set v1.0.2 // indirect
 	github.com/spf13/cast v1.3.1 // indirect
 	github.com/tidwall/uhatools v0.4.1 // indirect
 	github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect

+ 3 - 0
go.sum

@@ -35,6 +35,7 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
 github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
+github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
@@ -89,6 +90,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
 github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
 github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
+github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE=
+github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
 github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
 github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

+ 48 - 0
odbclient/client.go

@@ -0,0 +1,48 @@
+package odbclient
+
+import (
+	"fmt"
+	"strings"
+
+	ccfg "git.wecise.com/wecise/common/matrix/cfg"
+	clog "git.wecise.com/wecise/common/matrix/logger"
+	"git.wecise.com/wecise/odb-go/odb"
+	"github.com/scylladb/go-set/strset"
+)
+
+var cfg = ccfg.MConfig()
+var log = clog.New().WithConfig(cfg, "log")
+
+var odbcfg *odb.Config
+
+func init() {
+	odbpath := cfg.GetStrings("ODBPATH", "127.0.0.1:11001")
+	keyspace := cfg.GetString("KEYSPACE", "oktest")
+	poolsize := cfg.GetInt("Poolsize", 10)
+
+	odbpaths := strset.New()
+	for _, p := range odbpath {
+		odbpaths.Add(strings.Split(p, ",")...)
+	}
+
+	odbcfg = &odb.Config{
+		Hosts:    odbpaths.List(),
+		Keyspace: keyspace,
+		User:     fmt.Sprint("测试客户端", cfg.GetString("N")),
+		Pass:     "********",
+		PoolSize: poolsize,
+	}
+}
+
+func Config() *odb.Config {
+	return odbcfg
+
+}
+
+func NewClient() (c odb.Client, err error) {
+	client, err := odb.NewClient(odbcfg)
+	if err != nil {
+		return nil, err
+	}
+	return client, nil
+}

+ 5 - 22
client/client_test.go

@@ -1,4 +1,4 @@
-package client_test
+package odbclient_test
 
 import (
 	"fmt"
@@ -11,35 +11,18 @@ import (
 	ccfg "git.wecise.com/wecise/common/matrix/cfg"
 	clog "git.wecise.com/wecise/common/matrix/logger"
 	"git.wecise.com/wecise/odb-go/odb"
+	"git.wecise.com/wecise/odbtest/odbclient"
 )
 
 var cfg = ccfg.MConfig()
 var log = clog.New().WithConfig(cfg, "log")
 
-var config = &odb.Config{
-	// Hosts: []string{"47.92.151.165:11001"},
-	Hosts:    []string{"127.0.0.1:11001"},
-	Keyspace: "oktest",
-	// Keyspace: "icbctest",
-	User:     fmt.Sprint("测试客户端", cfg.GetString("N")),
-	Pass:     "********",
-	PoolSize: 2,
-}
-
-func getClient() (c odb.Client, err error) {
-	client, err := odb.NewClient(config)
-	if err != nil {
-		return nil, err
-	}
-	return client, nil
-}
-
 func TestConcurrent(t *testing.T) {
 	var n, reqcount, okcount, confirmcount, errcount int32
 	odb.QueryDoAsync = true
 	fmt.Println("QueryDoAsync =", odb.QueryDoAsync)
-	fmt.Println("开始测试连接到", config.Hosts)
-	client, err := odb.NewClient(config)
+	fmt.Println("开始测试连接到", odbclient.Config().Hosts)
+	client, err := odbclient.NewClient()
 	if err != nil {
 		println(fmt.Sprint("connection error:", err, atomic.AddInt32(&errcount, 1)))
 		return
@@ -213,7 +196,7 @@ func TestConcurrent(t *testing.T) {
 			}
 		}
 	}()
-	for i := 0; i < config.PoolSize*1000; i++ {
+	for i := 0; i < odbclient.Config().PoolSize*1000; i++ {
 		go func(i int) {
 			for {
 				identifier := fmt.Sprint("222.129.134.178.1.3.6.1.4.1.2011.5.25.219.2.5.665.25.219.2.5.6.", i, ".", atomic.AddInt32(&n, 1))

client/make.sh → odbclient/make.sh