From 58d904a328c0d849769b483e901a0be9426b8209 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 20 七月 2021 20:20:44 +0800 Subject: [PATCH] 调整Request C.BHFree的位置 --- utest/tcp_test.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 47 insertions(+), 10 deletions(-) diff --git a/utest/tcp_test.cpp b/utest/tcp_test.cpp index ff31c3e..0ead665 100644 --- a/utest/tcp_test.cpp +++ b/utest/tcp_test.cpp @@ -16,7 +16,10 @@ * ===================================================================================== */ +#include "defs.h" +#include "node_center.h" #include "tcp_connection.h" +#include "tcp_proxy.h" #include "tcp_server.h" #include "util.h" #include <sys/ioctl.h> @@ -31,21 +34,55 @@ BOOST_AUTO_TEST_CASE(TcpTest) { - const std::string bind_addr = "127.0.0.1"; const std::string connect_addr = "127.0.0.1"; - const uint16_t port = 10000; + const uint16_t port = kBHCenterPort; - TcpServer server(port); - server.Start(); - - boost::asio::io_context io; + IoService io; tcp::endpoint dest(ip::address::from_string(connect_addr), port); - for (int i = 0; i < 10; ++i) { - TcpRequest1::Create(io, dest, "client->server " + std::to_string(i)); - } - io.run(); + auto NewRequest = [&]() { + MsgRequestTopic req; + req.set_topic("#center_query_procs"); + req.set_data(""); + auto head = InitMsgHead(GetType(req), "#test_proc", 1000000); + auto route = head.add_route(); + route->set_mq_id(12345); + route->set_abs_addr(67890); + head.set_topic(req.topic()); + + head.mutable_dest()->set_ip(connect_addr); + // head.mutable_dest()->set_port(port); + // head.mutable_dest()->set_mq_id(201); + // head.mutable_dest()->set_abs_addr(10072); + + return (MsgI::Serialize(head, req)); + }; + auto onReply = [](BHMsgHead &head, std::string body_content) { + static int n = 0; + printf("reply %d: ", ++n); + MsgRequestTopicReply reply; + if (reply.ParseFromString(body_content)) { + if (IsSuccess(reply.errmsg().errcode())) { + printf("\ncontent: %s\n", reply.data().c_str()); + } else { + printf("error: %s\n", reply.errmsg().errstring().c_str()); + } + } else { + printf("parse error\n"); + } + }; + for (int i = 0; i < 100; ++i) { + auto request = NewRequest(); + TcpRequest1::Create(io.io(), dest, request, onReply); + } + Sleep(2s); + printf("-------------------------------------------------------\n"); + for (int i = 0; i < 3; ++i) { + auto request = NewRequest(); + TcpRequest1::Create(io.io(), dest, request, onReply); + } + Sleep(2s); printf("TcpTest\n"); } -- Gitblit v1.8.0