|
@@ -20,16 +20,16 @@ var log = clog.New().WithConfig(cfg, "log")
|
|
|
func TestConcurrent(t *testing.T) {
|
|
|
var n, reqcount, okcount, confirmcount, errcount int32
|
|
|
odb.QueryDoAsync = true
|
|
|
- fmt.Println("QueryDoAsync =", odb.QueryDoAsync)
|
|
|
- fmt.Println("开始测试连接到", odbclient.Config().Hosts)
|
|
|
+ log.Info("QueryDoAsync =", odb.QueryDoAsync)
|
|
|
+ log.Info("开始测试连接到", odbclient.Config().Hosts)
|
|
|
client, err := odbclient.NewClient()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("connection error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("connection error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
return
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = client.Close()
|
|
|
- fmt.Println("connection closed")
|
|
|
+ log.Info("connection closed")
|
|
|
}()
|
|
|
|
|
|
classname := "/oktest/alert_status"
|
|
@@ -38,7 +38,11 @@ func TestConcurrent(t *testing.T) {
|
|
|
classname += "_" + strconv.Itoa(N)
|
|
|
}
|
|
|
|
|
|
- fmt.Println("开始创建相关类", classname)
|
|
|
+ log.Info("开启事件订阅")
|
|
|
+ odbclient.Subscribe(client, "CLASS_DATA_CHANGE:/")
|
|
|
+ odbclient.Subscribe(client, "META_DATA_CHANGE:/")
|
|
|
+
|
|
|
+ log.Info("开始创建相关类", classname)
|
|
|
cns := regexp.MustCompile("^/([^/]+)/([^/]+)").FindAllStringSubmatch(classname, -1)
|
|
|
rootclass := "/" + cns[0][1]
|
|
|
aliasname := cns[0][2] + "_" + cns[0][1]
|
|
@@ -166,25 +170,25 @@ func TestConcurrent(t *testing.T) {
|
|
|
)with ttl=366 day , autosearch=true , version=true , key=manu, alias='` + aliasname + `' , nickname='` + aliasname + `' ;
|
|
|
`).Do()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("query count error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("query count error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
}
|
|
|
|
|
|
- fmt.Println("检查历史数据")
|
|
|
+ log.Info("检查历史数据")
|
|
|
|
|
|
result, err := client.Query("select count(id) as count FROM " + classname + " LIMIT -1").Do()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("query count error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("query count error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
} else {
|
|
|
- fmt.Println(fmt.Sprintf("query count return: %#v", result.Data[0]["count"]))
|
|
|
+ log.Info(fmt.Sprintf("query count return: %#v", result.Data[0]["count"]))
|
|
|
}
|
|
|
|
|
|
- fmt.Println("清除历史数据")
|
|
|
+ log.Info("清除历史数据")
|
|
|
|
|
|
_, err = client.Query("delete FROM " + classname + "").Do()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("delete error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("delete error:", err, atomic.AddInt32(&errcount, 1)))
|
|
|
} else {
|
|
|
- fmt.Println(fmt.Sprintf("delete ok"))
|
|
|
+ log.Info(fmt.Sprintf("delete ok"))
|
|
|
}
|
|
|
st := time.Now()
|
|
|
go func() {
|
|
@@ -192,11 +196,11 @@ func TestConcurrent(t *testing.T) {
|
|
|
for {
|
|
|
select {
|
|
|
case <-t.C:
|
|
|
- fmt.Println(time.Since(st), "插入数据", "req:", atomic.AddInt32(&reqcount, 0), "ok:", atomic.AddInt32(&okcount, 0), "confirm:", atomic.AddInt32(&confirmcount, 0), "err:", atomic.AddInt32(&errcount, 0))
|
|
|
+ log.Info(time.Since(st), "插入数据", "req:", atomic.AddInt32(&reqcount, 0), "ok:", atomic.AddInt32(&okcount, 0), "confirm:", atomic.AddInt32(&confirmcount, 0), "err:", atomic.AddInt32(&errcount, 0))
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
- for i := 0; i < odbclient.Config().PoolSize*1000; i++ {
|
|
|
+ for i := 0; i < client.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))
|
|
@@ -205,19 +209,17 @@ func TestConcurrent(t *testing.T) {
|
|
|
atomic.AddInt32(&reqcount, 1)
|
|
|
result, err := client.Query(mql, params...).Do()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("connection", i, err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("connection", i, err, atomic.AddInt32(&errcount, 1)))
|
|
|
time.Sleep(1 * time.Second)
|
|
|
} else {
|
|
|
atomic.AddInt32(&okcount, 1)
|
|
|
result, err = client.Query("select id,tally FROM "+classname+" where identifier=?", identifier).Do()
|
|
|
if err != nil {
|
|
|
- println(fmt.Sprint("connection", i, err, atomic.AddInt32(&errcount, 1)))
|
|
|
+ log.Error(fmt.Sprint("connection", i, err, atomic.AddInt32(&errcount, 1)))
|
|
|
time.Sleep(1 * time.Second)
|
|
|
} else {
|
|
|
atomic.AddInt32(&confirmcount, 1)
|
|
|
- if "log" == "info" {
|
|
|
- fmt.Println(fmt.Sprint("connection", i, result))
|
|
|
- }
|
|
|
+ log.Debug(fmt.Sprint("connection", i, result))
|
|
|
// time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
}
|
|
@@ -226,5 +228,5 @@ func TestConcurrent(t *testing.T) {
|
|
|
}(i)
|
|
|
}
|
|
|
time.Sleep(3600 * time.Second)
|
|
|
- fmt.Println("测试结束")
|
|
|
+ log.Info("测试结束")
|
|
|
}
|