From 1c92e4cbc85f9501660444cb76ebb06770da9376 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 21 五月 2021 15:36:11 +0800
Subject: [PATCH] reserve #xxx proc id for internal use.

---
 utest/api_test.cpp |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/utest/api_test.cpp b/utest/api_test.cpp
index e278e29..5fa46da 100644
--- a/utest/api_test.cpp
+++ b/utest/api_test.cpp
@@ -60,7 +60,7 @@
 	std::string proc((const char *) proc_id, proc_id_len);
 	MsgPublish pub;
 	pub.ParseFromArray(data, data_len);
-	printf("Sub data, %s : %s\n", pub.topic().c_str(), pub.data().c_str());
+	printf("****************************************** Sub data, %s : %s\n", pub.topic().c_str(), pub.data().c_str());
 }
 
 void ServerProc(const void *proc_id,
@@ -120,10 +120,11 @@
 
 	// BHCleanup();
 	// return;
+	const std::string proc_id = "demo_client";
 	bool reg = false;
 	for (int i = 0; i < 3 && !reg; ++i) {
 		ProcInfo proc;
-		proc.set_proc_id("demo_client");
+		proc.set_proc_id(proc_id);
 		proc.set_public_info("public info of demo_client. etc...");
 		std::string proc_buf(proc.SerializeAsString());
 		void *reply = 0;
@@ -148,13 +149,13 @@
 		}
 
 		BHFree(reply, reply_len);
-		Sleep(1s);
+		// Sleep(1s);
 	}
 	if (!reg) {
 		return;
 	}
 
-	const std::string topic_ = "topic_";
+	const std::string topic_ = proc_id + "_topic_";
 
 	{ // Server Register Topics
 		MsgTopicList topics;
@@ -205,6 +206,7 @@
 		// query procs with normal topic request
 		MsgRequestTopic req;
 		req.set_topic("@center_query_procs");
+		// req.set_data("{\"proc_id\":\"#center.node\"}");
 		std::string s(req.SerializeAsString());
 		// Sleep(10ms, false);
 		std::string dest(BHAddress().SerializeAsString());
@@ -214,7 +216,7 @@
 		void *reply = 0;
 		int reply_len = 0;
 		DEFER1(BHFree(reply, reply_len));
-		bool r = BHRequest(dest.data(), dest.size(), s.data(), s.size(), &proc_id, &proc_id_len, &reply, &reply_len, 100);
+		bool r = BHRequest(dest.data(), dest.size(), s.data(), s.size(), &proc_id, &proc_id_len, &reply, &reply_len, 1000);
 		if (!r) {
 			int ec = 0;
 			std::string msg;
@@ -232,10 +234,10 @@
 			// }
 		}
 	}
-	// return;
 
 	{ // Subscribe
 		MsgTopicList topics;
+		topics.add_topic_list("#center.node");
 		for (int i = 0; i < 10; ++i) {
 			topics.add_topic_list(topic_ + std::to_string(i * 2));
 		}
@@ -285,7 +287,7 @@
 		void *reply = 0;
 		int reply_len = 0;
 		DEFER1(BHFree(reply, reply_len));
-		bool r = BHRequest(dest.data(), dest.size(), s.data(), s.size(), &proc_id, &proc_id_len, &reply, &reply_len, 100);
+		bool r = BHRequest(dest.data(), dest.size(), s.data(), s.size(), &proc_id, &proc_id_len, &reply, &reply_len, 1000);
 		if (!r) {
 			int ec = 0;
 			std::string msg;
@@ -361,7 +363,7 @@
 
 	ThreadManager threads;
 
-#if 0
+#if 1
 	BHStartWorker(&ServerProc, &SubRecvProc, &ClientProc);
 #else
 	BHStartWorker(FServerCallback(), &SubRecvProc, &ClientProc);
@@ -396,10 +398,11 @@
 		}
 	}
 
+	Sleep(1s);
+
 	run = false;
 	threads.WaitAll();
 	auto &st = Status();
-	Sleep(1s);
 	printf("nreq: %8ld, nsrv: %8ld, nreply: %8ld\n", st.nrequest_.load(), st.nserved_.load(), st.nreply_.load());
 	BHCleanup();
 	printf("after cleanup\n");

--
Gitblit v1.8.0