From 365c864a587365fe443b11cc0cd7cfc8f8f8eb81 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期二, 01 六月 2021 11:19:22 +0800
Subject: [PATCH] refactor, clean up useless code.
---
api/bhsgo/bhome_node_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/api/bhsgo/bhome_node_test.go b/api/bhsgo/bhome_node_test.go
index d4f4278..cd4bfb9 100644
--- a/api/bhsgo/bhome_node_test.go
+++ b/api/bhsgo/bhome_node_test.go
@@ -1,19 +1,34 @@
package bhsgo
import (
- bh "bhshmq/proto/source/bhome_msg"
"fmt"
"testing"
"time"
+ "unsafe"
+
+ bh "basic.com/valib/bhshmq.git/proto/source/bhome_msg"
)
+func ServerCallback(src unsafe.Pointer, proc_id *string, req *bh.MsgRequestTopic) {
+ fmt.Println("user server cb called, request topic: " + string(req.Topic) + ", data:" + string(req.Data))
+ reply := bh.MsgRequestTopicReply{}
+ reply.Data = []byte("reply 1234")
+ SendReply(src, &reply)
+}
+
+func SubDataCallback(proc_id *string, pub *bh.MsgPublish) {
+ fmt.Println("user sub data cb called")
+}
+func ClientCallback(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply) {
+ fmt.Println("user client cb reply: " + string(reply.Data))
+}
func TestRegister(t *testing.T) {
proc_id := "test_proc"
proc := bh.ProcInfo{}
proc.ProcId = []byte(proc_id)
+ fmt.Println("proc id: ", proc.ProcId)
reply := bh.MsgCommonReply{}
-
- StartWorker(ClientCallback, ServerCallback, SubDataCallback)
+ defer Cleanup()
r := Register(&proc, &reply, 1000)
if r {
@@ -22,6 +37,23 @@
fmt.Println("register failed")
return
}
+ r = Unregister(&proc, &reply, 1000)
+ if r {
+ fmt.Println("Unregister ok")
+ } else {
+ fmt.Println("Unregister failed")
+ }
+
+ r = Register(&proc, &reply, 1000)
+ if r {
+ fmt.Println("register ok")
+ } else {
+ fmt.Println("register failed")
+ t.Log("register error")
+ return
+ }
+
+ StartWorker(ClientCallback, ServerCallback, SubDataCallback)
r = HeartbeatEasy(1000)
if r {
@@ -38,6 +70,7 @@
} else {
fmt.Println("reg topics failed")
}
+
req := bh.MsgRequestTopic{}
time.Sleep(time.Second * 1)
req.Topic = []byte("topic0")
@@ -49,8 +82,16 @@
pid := ""
rr := bh.MsgRequestTopicReply{}
- for i := 0; i < 10000; i++ {
- if Request(&req, &pid, &rr, 3000) {
+ dest := bh.BHAddress{}
+
+ queryProc := bh.MsgQueryProc{}
+ queryReply := bh.MsgQueryProcReply{}
+
+ QueryProcs(&dest, &queryProc, &queryReply, 3000)
+ fmt.Println("query result:", string(queryReply.ProcList[0].Proc.ProcId))
+
+ for i := 0; i < 10; i++ {
+ if Request(&dest, &req, &pid, &rr, 3000) {
fmt.Println("server:" + pid + ", reply:" + string(rr.Data))
} else {
e, s := GetLastError()
--
Gitblit v1.8.0