unit-test use tarsmock

master
ruanshudong 2024-03-14 15:38:55 +08:00
parent 6b57889905
commit 21bf27958a
43 changed files with 491 additions and 1753 deletions

View File

@ -505,7 +505,20 @@ void CDbHandle::addInactiveEndPoint(const string& objName, const string &host, c
void CDbHandle::cleanEndPoint()
{
ObjectsCache objectsCache;
ObjectsCache objectsCache = _objectsCache;
//从objectsCache删除不是tars的服务
for (auto it = objectsCache.begin(); it != objectsCache.end();)
{
if (it->first.find("tars.") == string::npos)
{
objectsCache.erase(it++);
}
else
{
++it;
}
}
updateObjectsCache(objectsCache, true);
}

View File

@ -1,18 +1,122 @@
#include "mock/FrameworkServer.h"
#include "mock/QueryImp.h"
#include "mock/ConfigImp.h"
#include "mock/QueryImp.h"
#include "mock/StatImp.h"
#include "mock/LogImp.h"
#include "mock/framework.h"
using namespace std;
vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _clientStatData;
vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _serverStatData;
FrameworkServer::~FrameworkServer()
{
}
void
FrameworkServer::initialize()
{
addServant<QueryImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".QueryObj");
CDbHandle::addActiveEndPoint("tars.tarsmock.ConfigObj", "127.0.0.1", 11003, 1);
CDbHandle::addActiveEndPoint("tars.tarsmock.QueryObj", "127.0.0.1", 17890, 1);
CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1);
CDbHandle::addActiveEndPoint("tars.tarsmock.StatObj", "127.0.0.1", 12004, 1);
addServant<ConfigImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".ConfigObj");
addServant<QueryImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".QueryObj");
addServant<StatImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".StatObj");
addServant<LogImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".LogObj");
string s;
loadLogFormat("","",s);
//日志路径
g_globe._log_path = _conf["/tars/log<logpath>"];
//启动写线程
g_globe._group.start(TC_Common::strto<size_t>(_conf["/tars/log<logthread>"]));
string prefix = TC_Common::lower(_conf.get("/tars/log<ipfix>","true"));
g_globe._bIpPrefix = (prefix == "true") ? true : false;
//增加对象
addServant<LogImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".LogObj");
TARS_ADD_ADMIN_CMD_NORMAL("reloadLogFormat", FrameworkServer::loadLogFormat);
}
bool FrameworkServer::loadLogFormat(const string& command, const string& params, string& result)
{
TLOGDEBUG("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << endl);
try
{
TC_Config conf;
conf.parseString(MOCK_FRAMEWORK_CONFIG);
vector<string> vHourlist;
map<string,string> mLogType;
try
{
string sHour = conf["/tars/log/format<hour>"];
vHourlist = TC_Common::sepstr<string>(sHour,"|;,");
sort(vHourlist.begin(),vHourlist.end());
unique(vHourlist.begin(),vHourlist.end());
result = "loadLogFormat succ:" + sHour;
TLOGDEBUG("FrameworkServer::loadLogFormat result:" << result << endl);
DLOG<< "FrameworkServer::loadLogFormat result:" << result << endl;
//hour=app.server.file|app2.server2.file2
map<string,string> mType;
if(conf.getDomainMap("/tars/log/logtype", mType))
{
map<string,string>::iterator it = mType.begin();
while(it != mType.end())
{
vector<string> vList = TC_Common::sepstr<string>(it->second,"|;,");
for(size_t i = 0;i < vList.size();i++)
{
//app.server.file = hour
mLogType[vList[i]] = it->first;
TLOGDEBUG("FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl);
DLOG<<"FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl;
}
it++;
}
}
g_globe.update(vHourlist, mLogType);
}
catch(exception& e)
{
result += e.what();
TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
}
return true;
}
catch(exception &e)
{
result += e.what();
TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
}
return false;
}
void FrameworkServer::destroyApp()
@ -21,5 +125,5 @@ void FrameworkServer::destroyApp()
void FrameworkServer::run()
{
waitForShutdown();
}
this->waitForShutdown();
}

View File

@ -28,6 +28,9 @@ public:
protected:
virtual void run();
bool loadLogFormat(const string& command, const string& params, string& result);
};

View File

@ -1,7 +1,7 @@

#include "StatImp.h"
#include "../FrameworkServer.h"
#include "FrameworkServer.h"
///////////////////////////////////////////////////////////
//

View File

@ -13,7 +13,7 @@ TarsMockUtil::TarsMockUtil()
void TarsMockUtil::startFramework()
{
_fs->main(FRAMEWORK_CONFIG);
_fs->main(MOCK_FRAMEWORK_CONFIG);
_fs->start();
_fs->waitForReady();
}

View File

@ -1,39 +1,144 @@
#pragma once
#define FRAMEWORK_CONFIG "<tars> \n\
<application> \n\
<client> \n\
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 \n \
sync-invoke-timeout = 5000 \n \
async-invoke-timeout = 60000 \n \
refresh-endpoint-interval = 5000 \n \
sendqueuelimit = 1000000 \n \
asyncqueuecap = 1000000 \n \
asyncthread = 3 \n \
netthread = 2 \n \
mergenetasync = 0 \n \
modulename = tars.tarsmock \n \
</client> \n \
<server> \n \
start_output = ERROR \n \
closecout = 0 \n \
app = tars \n \
server = tarsmock \n \
basepath = . \n \
datapath = . \n \
logpath = . \n \
netthread = 1 \n \
mergenetimp = 0 \n \
opencoroutine = 0 \n \
loglevel=TARS \n \
<RegistryAdapter> \n \
endpoint = tcp -h 127.0.0.1 -p 13004 -t 60000 \n \
allow = \n \
maxconns = 4096 \n \
threads = 5 \n \
servant = tars.tarsmock.QueryObj \n \
queuecap = 1000000 \n \
</RegistryAdapter> \n \
</server> \n \
</application> \n\
</tars>"
#include <string>
const static std::string &MOCK_FRAMEWORK_CONFIG = R"(
<tars>
<application>
#proxy需要的配置
<client>
#地址
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 5000
async-invoke-timeout = 60000
#刷新端口时间间隔(毫秒)
refresh-endpoint-interval = 5000
#模块间调用[可选]
stat = tars.tarsmock.StatObj
#发送队列长度
sendqueuelimit = 100000
#异步回调队列个数限制
asyncqueuecap = 100000
#网络异步回调线程个数
asyncthread = 3
#网络线程个数
netthread = 2
#合并回调线程和网络线程(以网络线程个数为准)
mergenetasync = 0
#模块名称
modulename = tars.tarsmock
</client>
#定义所有绑定的IP
<server>
start_output = ERROR
closecout = 0
#应用名称
app = tars
#服务名称
server = tarsmock
#服务的数据目录,可执行文件,配置文件等
basepath = .
datapath = .
#日志路径
logpath = .
#网络线程个数
netthread = 1
#合并网络和业务线程(以网络线程个数为准)
mergenetimp = 0
opencoroutine = 0
loglevel=TARS
#本地管理套接字[可选]
local = tcp -h 127.0.0.1 -p 15791 -t 10000
#本地node的ip:port:timeout[可选]
# node = ServerObj@tcp -h 127.0.0.1 -p 2345 -t 10000
#配置中心的地址[可选]
config = tars.tarsmock.ConfigObj
#配置中心的地址[可选]
# notify = tars.tarsconfig.NotifyObj
#远程LogServer[可选]
log = tars.tarsmock.LogObj
<ConfigAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 11003 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = tars.tarsmock.ConfigObj
#queue capacity
queuecap = 1000000
</ConfigAdapter>
<LogAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 11005 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = tars.tarsmock.LogObj
#queue capacity
queuecap = 1000000
</LogAdapter>
<RegistryAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 17890 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = tars.tarsmock.QueryObj
#queue capacity
queuecap = 1000000
</RegistryAdapter>
<StatAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 12004 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = tars.tarsmock.StatObj
#queue capacity
queuecap = 1000000
</StatAdapter>
</server>
</application>
<log>
logpath = .
logthread = 1
ipfix = true
<format>
hour=app.server.file|app2.server2.file2
</format>
<logtype>
app.server.file = hour
</logtype>
</log>
</tars>
)";

View File

@ -1,5 +1,6 @@
project(unit-test)
include_directories(${servant_SOURCE_DIR}/protocol/framework)
include_directories(${servant_SOURCE_DIR}/protocol/servant)
@ -7,14 +8,15 @@ include_directories(${CMAKE_BINARY_DIR}/src/gtest/include)
link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib)
link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib64)
include_directories(./)
include_directories(../)
build_tars_server("unit-test" "")
add_definitions(-DCMAKE_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
target_link_libraries(unit-test ${LIB_GTEST})
target_link_libraries(unit-test ${LIB_GTEST} tarsmock)
if(TARS_MYSQL)
target_link_libraries(unit-test ${LIB_MYSQL})
endif()
add_dependencies(unit-test FRAMEWORK-PROTOCOL)
add_dependencies(unit-test FRAMEWORK-PROTOCOL tarsmock)

View File

@ -2,6 +2,7 @@
#define PATH_HEAER
#include "util/tc_config.h"
#include "mock/framework.h"
using namespace tars;
@ -30,7 +31,7 @@ inline TC_Config CLIENT_CONFIG()
inline TC_Config FRAMEWORK_CONFIG()
{
TC_Config conf;
conf.parseFile(CONFIGPATH + "/server/framework.conf");
conf.parseString(MOCK_FRAMEWORK_CONFIG);
return conf;
}

View File

@ -866,7 +866,7 @@ void HelloTest::forEach(function<void(Communicator *comm)> func)
HelloServer server;
startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) i);
func(server.getCommunicator().get());
func(server.getApplicationCommunicator().get());
stopServer(server);
}
@ -895,7 +895,7 @@ void HelloTest::forEachInCoroutine(function<void(Communicator *comm)> func)
s->terminate();
});
func(server.getCommunicator().get());
func(server.getApplicationCommunicator().get());
});

View File

@ -193,8 +193,11 @@ public:
//添加日志
static void SetUpTestCase()
{
LocalRollLogger::getInstance()->setLogInfo("tars", "test", ".", 1024*1024*10, 5, nullptr, "");
LocalRollLogger::getInstance()->logger()->setLogLevel("TARS");
}
}
static void TearDownTestCase()
{
}
@ -259,7 +262,7 @@ public:
// comm->setProperty("asyncqueuecap", "1000000");
string obj = getObj(_conf, adapter);
LOG_CONSOLE_DEBUG << obj << endl;
// LOG_CONSOLE_DEBUG << obj << endl;
T prx = comm->stringToProxy<T>(obj);
prx->tars_timeout(60000);
@ -376,7 +379,6 @@ public:
protected:
int _count = 1000;
// int _count = 10;
string _buffer;

View File

@ -17,25 +17,22 @@
#include "hello_test.h"
#include "../server/WinServer.h"
#include "servant/AdminF.h"
#include "server/FrameworkServer.h"
#include "server/framework/DbHandle.h"
#include "mock/TarsMockUtil.h"
#include "mock/DbHandle.h"
#include "mock/ConfigImp.h"
TEST_F(HelloTest, testAdmin)
{
LocalRollLogger::getInstance()->setLogInfo("tars", "test", ".", 1024*1024*10, 5, nullptr, "");
LocalRollLogger::getInstance()->logger()->setLogLevel("TARS");
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
ConfigImp::setConfigFile("test.conf", "test-content");
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.ConfigObj", 11003, 1);
WinServer ws;
startServer(ws, WIN_CONFIG());
CommunicatorPtr c = ws.getCommunicator();
CommunicatorPtr c = ws.getApplicationCommunicator();
string adminObj = "AdminObj@" + getLocalEndpoint(WIN_CONFIG()).toString();
@ -81,11 +78,6 @@ TEST_F(HelloTest, testAdmin)
string reloadlocator = adminFPrx->notify("tars.reloadlocator reload");
EXPECT_TRUE(reloadlocator.find("[notify prefix object num:1]") != string::npos);
// string closecore = adminFPrx->notify("tars.closecore no");
// EXPECT_TRUE(closecore.find("after set cur:18446744073709551615;max: 18446744073709551615") != string::npos);
// closecore = adminFPrx->notify("tars.closecore yes");
// EXPECT_TRUE(closecore.find("after set cur:0;max: 18446744073709551615") != string::npos);
string errorcmd = adminFPrx->notify("tars.errorcmd");
EXPECT_STREQ(errorcmd.c_str(), "");
@ -96,8 +88,6 @@ TEST_F(HelloTest, testAdmin)
EXPECT_STREQ(normaldeletecmd.c_str(), "[notify servant object num:1]\n[1]:Delete success!\n");
stopServer(ws);
stopServer(fs);
tarsMockUtil.stopFramework();
}

View File

@ -12,6 +12,7 @@ TEST_F(HelloTest, test)
}
TEST_F(HelloTest, rpcASyncGlobalCommunicator)
{
{

View File

@ -277,7 +277,7 @@ TEST_F(HelloTest, testNotifyCtrlC)
HelloServer server;
startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0);
HelloPrx prx = getObj<HelloPrx>(server.getCommunicator(), "HelloAdapter");
HelloPrx prx = getObj<HelloPrx>(server.getApplicationCommunicator(), "HelloAdapter");
for(int i = 0; i < 10000; i++)
{

View File

@ -16,8 +16,10 @@
#include "hello_test.h"
#include "servant/AdminF.h"
#include "server/FrameworkServer.h"
#include "server/framework/DbHandle.h"
//#include "server/FrameworkServer.h"
//#include "server/framework/DbHandle.h"
#include "mock/TarsMockUtil.h"
#include "mock/DbHandle.h"
#define DYEFILEPATH (string("tars_dyeing") + FILE_SEP)
@ -52,11 +54,11 @@ TEST_F(HelloTest, DyeingNo)
HelloServer server;
startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0);
HelloPrx prx = getObj<HelloPrx>(server.getCommunicator().get(), "HelloAdapter");
HelloPrx prx = getObj<HelloPrx>(server.getApplicationCommunicator().get(), "HelloAdapter");
// int64_t tBegin = TC_TimeProvider::getInstance()->getNowMs();
// HelloPrx dyeingPrx= server.getCommunicator()->stringToProxy<HelloPrx>(DYEING_SERVANT_ENDPOINT);
// HelloPrx dyeingPrx= server.getApplicationCommunicator()->stringToProxy<HelloPrx>(DYEING_SERVANT_ENDPOINT);
string strIn="123456";
string strOut;
int ret=prx->testDyeing(strIn,strOut);
@ -70,26 +72,28 @@ TEST_F(HelloTest, DyeingNo)
//打开染色开关但未使用染色key调用的场景
TEST_F(HelloTest, DyeingNoKey)
{
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
// FrameworkServer fs;
// startServer(fs, FRAMEWORK_CONFIG());
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.LogObj", 11005, 1);
// CDbHandle::cleanEndPoint();
// CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1);
HelloServer server;
startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0);
// int64_t tBegin = TC_TimeProvider::getInstance()->getNowMs();
AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy<AdminFPrx>("AdminObj@" + getLocalEndpoint(CONFIG()).toString());
AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy<AdminFPrx>("AdminObj@" + getLocalEndpoint(CONFIG()).toString());
// AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy<AdminFPrx>(UNIT_TEST_ADMIN_NAME_ENDPOINT);
// AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy<AdminFPrx>(UNIT_TEST_ADMIN_NAME_ENDPOINT);
string setdyeing = adminFPrx->notify("tars.setdyeing 123456 TestApp.HelloServer.HelloObj testDyeing");
EXPECT_TRUE(setdyeing.find("DyeingKey=123456") != string::npos);
HelloPrx prx = getObj<HelloPrx>(server.getCommunicator().get(), "HelloAdapter");
HelloPrx prx = getObj<HelloPrx>(server.getApplicationCommunicator().get(), "HelloAdapter");
// DyeingTestPrx dyeingPrx= server.getCommunicator()->stringToProxy<DyeingTestPrx>(DYEING_SERVANT_ENDPOINT);
// DyeingTestPrx dyeingPrx= server.getApplicationCommunicator()->stringToProxy<DyeingTestPrx>(DYEING_SERVANT_ENDPOINT);
string strIn="abc";
string strOut;
int ret=prx->testDyeing(strIn,strOut);
@ -99,29 +103,31 @@ TEST_F(HelloTest, DyeingNoKey)
// TLOGDEBUG("dyeing without key request time cost: "<< " | " << TC_TimeProvider::getInstance()->getNowMs() - tBegin << "(ms)" << endl);
stopServer(server);
stopServer(fs);
tarsMockUtil.stopFramework();
// stopServer(fs);
}
//打开染色开关使用染色key调用的场景
TEST_F(HelloTest, DyeingKey)
{
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
// FrameworkServer fs;
// startServer(fs, FRAMEWORK_CONFIG());
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.LogObj", 11005, 1);
// CDbHandle::cleanEndPoint();
// CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1);
HelloServer server;
startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0);
AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy<AdminFPrx>("AdminObj@" + getLocalEndpoint(CONFIG()).toString());
AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy<AdminFPrx>("AdminObj@" + getLocalEndpoint(CONFIG()).toString());
string setdyeing = adminFPrx->notify("tars.setdyeing 123456 TestApp.HelloServer.HelloObj testDyeing");
EXPECT_TRUE(setdyeing.find("DyeingKey=123456") != string::npos);
TC_File::removeFile("./tars_dyeing", true);
HelloPrx prx = getObj<HelloPrx>(server.getCommunicator().get(), "HelloAdapter");
HelloPrx prx = getObj<HelloPrx>(server.getApplicationCommunicator().get(), "HelloAdapter");
string strIn="123456";
string strOut;
@ -138,7 +144,8 @@ TEST_F(HelloTest, DyeingKey)
EXPECT_EQ(getFileLine(dyeDebugFile.c_str()), 4);
stopServer(server);
stopServer(fs);
tarsMockUtil.stopFramework();
// stopServer(fs);
}

View File

@ -10,28 +10,22 @@ TEST_F(HelloTest, proxyInvokeTimeout)
checkSyncTimeout(comm);
}, c.get());
LOG_CONSOLE_DEBUG << endl;
transInCoroutineGlobalCommunicator([&](Communicator *comm){
checkSyncTimeout(comm);
}, c.get());
LOG_CONSOLE_DEBUG << endl;
transServerCommunicator([&](Communicator *comm){
checkSyncTimeout(comm);
});
LOG_CONSOLE_DEBUG << endl;
transInCoroutineServerCommunicator([&](Communicator *comm){
checkSyncTimeout(comm);
});
LOG_CONSOLE_DEBUG << endl;
transAllocCommunicator([&](Communicator *comm){
checkSyncTimeout(comm);
});
LOG_CONSOLE_DEBUG << endl;
transInCoroutineAllocCommunicator([&](Communicator *comm){
checkSyncTimeout(comm);
});

View File

@ -2,8 +2,8 @@
#include "hello_test.h"
#include "servant/CommunicatorEpoll.h"
#include "servant/ObjectProxy.h"
#include "server/framework/DbHandle.h"
#include "server/FrameworkServer.h"
//#include "server/framework/DbHandle.h"
#include "server/RpcServer.h"
#include "QueryF.h"
TEST_F(HelloTest, prxUpdate)

View File

@ -2,9 +2,10 @@
#include "hello_test.h"
#include "servant/CommunicatorEpoll.h"
#include "servant/ObjectProxy.h"
#include "server/framework/DbHandle.h"
#include "server/FrameworkServer.h"
#include "mock/DbHandle.h"
#include "mock/TarsMockUtil.h"
#include "QueryF.h"
#include "server/RpcServer.h"
TEST_F(HelloTest, registryQuery)
{
@ -17,11 +18,13 @@ TEST_F(HelloTest, registryQuery)
TC_Config fconf = FRAMEWORK_CONFIG();
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9990, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9991, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9990, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9991, 1);
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
// FrameworkServer fs;
// startServer(fs, FRAMEWORK_CONFIG());
string obj = getObj(fconf, "RegistryAdapter");
@ -36,7 +39,7 @@ TEST_F(HelloTest, registryQuery)
}
{
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1);
TC_Common::sleep(6);
@ -55,7 +58,7 @@ TEST_F(HelloTest, registryQuery)
}
{
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9993, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9993, 1);
TC_Common::sleep(6);
@ -74,16 +77,17 @@ TEST_F(HelloTest, registryQuery)
}
}
stopServer(fs);
tarsMockUtil.stopFramework();
// stopServer(fs);
}
#define START_FRAMEWORK_SERVER_1_2 \
CDbHandle::cleanEndPoint(); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9990, 1); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9991, 1); \
FrameworkServer fs; \
startServer(fs, FRAMEWORK_CONFIG()); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9990, 1); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9991, 1); \
TarsMockUtil tarsMockUtil; \
tarsMockUtil.startFramework(); \
RpcServer rpc1Server; \
startServer(rpc1Server, RPC1_CONFIG()); \
RpcServer rpc2Server; \
@ -92,16 +96,16 @@ startServer(rpc2Server, RPC2_CONFIG());
#define START_FRAMEWORK_HTTP_SERVER_1_2 \
CDbHandle::cleanEndPoint(); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8180, 1); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8181, 1); \
FrameworkServer fs; \
startServer(fs, FRAMEWORK_CONFIG()); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8180, 1); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8181, 1); \
TarsMockUtil tarsMockUtil; \
tarsMockUtil.startFramework(); \
RpcServer rpc1Server; \
startServer(rpc1Server, RPC1_CONFIG()); \
RpcServer rpc2Server; \
startServer(rpc2Server, RPC2_CONFIG());
#define STOP_FRAMEWORK_SERVER stopServer(fs);
#define STOP_FRAMEWORK_SERVER tarsMockUtil.stopFramework();
#define HELLO_CALL {\
HelloPrx qPrx = comm->stringToProxy<HelloPrx>("TestApp.RpcServer.HelloObj"); \
@ -114,7 +118,7 @@ ASSERT_TRUE(out == _buffer); }
#define CHECK_REGISTRY_UPDATE {\
stopServer(rpc1Server); \
CDbHandle::cleanEndPoint(); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); \
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); \
RpcServer rpc3Server; \
startServer(rpc3Server, RPC3_CONFIG()); \
wait(6000); \
@ -188,7 +192,8 @@ TEST_F(HelloTest, registryRpc)
LOG_CONSOLE_DEBUG << endl;
stopServer(rpc1Server);
stopServer(rpc2Server);
stopServer(fs);
tarsMockUtil.stopFramework();
// stopServer(fs);
}
@ -196,8 +201,8 @@ TEST_F(HelloTest, registryRpc)
TEST_F(HelloTest, registryRpcConHashInvoke)
{
START_FRAMEWORK_SERVER_1_2
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj","127.0.0.1", 9992, 1);
shared_ptr<Communicator> c = getCommunicator();
@ -330,7 +335,7 @@ TEST_F(HelloTest, registryRpcCheckUpdateList)
//更新主控ip list
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1);
RpcServer rpc3Server;
startServer(rpc3Server, RPC3_CONFIG());
@ -430,7 +435,7 @@ TEST_F(HelloTest, registryHttpRpcCheckUpdateList)
//更新主控ip list
CDbHandle::cleanEndPoint();
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8182, 1);
CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8182, 1);
RpcServer rpc3Server;
startServer(rpc3Server, RPC3_CONFIG());
@ -471,8 +476,8 @@ TEST_F(HelloTest, registryHttpRpcCheckUpdateList)
TEST_F(HelloTest, registryRpcHashTagInvoke)
{
START_FRAMEWORK_SERVER_1_2
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1);
shared_ptr<Communicator> c = getCommunicator();
@ -495,8 +500,8 @@ TEST_F(HelloTest, registryRpcHashTagInvoke)
TEST_F(HelloTest, registryRpcMultiHashTagInvoke)
{
START_FRAMEWORK_SERVER_1_2
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1);
CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1);
shared_ptr<Communicator> c = getCommunicator();

View File

@ -1,6 +1,6 @@

#include "hello_test.h"
#include "server/FrameworkServer.h"
#include "mock/TarsMockUtil.h"
int getStatCount(const vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> &data)
{
@ -21,8 +21,10 @@ int getStatCount(const vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> &
TEST_F(HelloTest, statReport)
{
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
// FrameworkServer fs;
// startServer(fs, FRAMEWORK_CONFIG());
HelloServer hs;
startServer(hs, CONFIG());
@ -62,14 +64,15 @@ TEST_F(HelloTest, statReport)
// LOG_CONSOLE_DEBUG << "server stat:" << _serverStatData.size() << endl;
stopServer(hs);
stopServer(fs);
tarsMockUtil.stopFramework();
// stopServer(fs);
}
TEST_F(HelloTest, statReportInCoroutine)
{
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
HelloServer hs;
startServer(hs, CONFIG());
@ -110,5 +113,5 @@ TEST_F(HelloTest, statReportInCoroutine)
}, true);
stopServer(hs);
stopServer(fs);
tarsMockUtil.stopFramework();
}

View File

@ -1,7 +1,7 @@

#include "hello_test.h"
TEST_F(HelloTest, rpcTransGlobalCommunicator)
TEST_F(HelloTest, transGlobalCommunicator)
{
shared_ptr<Communicator> c = getCommunicator();
@ -22,7 +22,7 @@ TEST_F(HelloTest, rpcTransGlobalCommunicator)
}, c.get());
}
TEST_F(HelloTest, rpcTransGlobalCommunicatorInCoroutine)
TEST_F(HelloTest, transGlobalCommunicatorInCoroutine)
{
shared_ptr<Communicator> c = getCommunicator();
@ -43,7 +43,7 @@ TEST_F(HelloTest, rpcTransGlobalCommunicatorInCoroutine)
}, c.get());
}
TEST_F(HelloTest, rpcTransServerCommunicator)
TEST_F(HelloTest, transServerCommunicator)
{
transServerCommunicator([&](Communicator *comm){
checkTransSyncASync(comm);
@ -62,7 +62,7 @@ TEST_F(HelloTest, rpcTransServerCommunicator)
});
}
TEST_F(HelloTest, rpcTransServerCommunicatorInCoroutine)
TEST_F(HelloTest, transServerCommunicatorInCoroutine)
{
transInCoroutineServerCommunicator([&](Communicator *comm){
checkTransSyncASync(comm);
@ -81,7 +81,7 @@ TEST_F(HelloTest, rpcTransServerCommunicatorInCoroutine)
});
}
TEST_F(HelloTest, rpcTransAllocCommunicator)
TEST_F(HelloTest, transAllocCommunicator)
{
transAllocCommunicator([&](Communicator *comm){
checkTransSyncASync(comm);
@ -100,7 +100,7 @@ TEST_F(HelloTest, rpcTransAllocCommunicator)
});
}
TEST_F(HelloTest, rpcTransAllocCommunicatorInCoroutine)
TEST_F(HelloTest, transAllocCommunicatorInCoroutine)
{
transInCoroutineAllocCommunicator([&](Communicator *comm){
checkTransSyncASync(comm);
@ -120,7 +120,7 @@ TEST_F(HelloTest, rpcTransAllocCommunicatorInCoroutine)
}
TEST_F(HelloTest, rpcTransComplexCommunicator)
TEST_F(HelloTest, transComplexCommunicator)
{
shared_ptr<Communicator> c = getCommunicator();
@ -142,7 +142,7 @@ TEST_F(HelloTest, rpcTransComplexCommunicator)
}
TEST_F(HelloTest, rpcTransComplexCommunicatorInCoroutine)
TEST_F(HelloTest, transComplexCommunicatorInCoroutine)
{
shared_ptr<Communicator> c = getCommunicator();

View File

@ -1,9 +1,9 @@

#include "hello_test.h"
#include "../server/WinServer.h"
#include "server/FrameworkServer.h"
#include "server/framework/DbHandle.h"
#include "server/framework/ConfigImp.h"
#include "mock/TarsMockUtil.h"
#include "mock/DbHandle.h"
#include "mock/ConfigImp.h"
TEST_F(HelloTest, winServerInCoroutine)
@ -370,10 +370,15 @@ TEST_F(HelloTest, winServerConfig)
TC_File::removeFile("./test.conf.2.bak", true);
TC_File::removeFile("./test.conf.3.bak", true);
TC_File::removeFile("./test.conf.4.bak", true);
TC_File::removeFile("./FrameworkServer.tarsdat", true);
TC_File::removeFile("./tarsmock.tarsdat", true);
FrameworkServer fs;
startServer(fs, FRAMEWORK_CONFIG());
TarsMockUtil tarsMockUtil;
tarsMockUtil.startFramework();
ConfigImp::setConfigFile("test.conf", "test-content");
// FrameworkServer fs;
// startServer(fs, FRAMEWORK_CONFIG());
{
WinServer ws;
@ -385,7 +390,7 @@ TEST_F(HelloTest, winServerConfig)
stopServer(ws);
}
CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.ConfigObj", 11003, 1);
// CDbHandle::addActiveEndPoint("tars.tarsmock.ConfigObj", "127.0.0.1", 11003, 1);
{
WinServer ws;
@ -420,6 +425,7 @@ TEST_F(HelloTest, winServerConfig)
stopServer(ws);
}
stopServer(fs);
// stopServer(fs);
tarsMockUtil.stopFramework();
}

View File

@ -1,7 +1,7 @@

#include "hello_test.h"
TEST_F(HelloTest, rpcWupTransGlobalCommunicator)
TEST_F(HelloTest, wupTransGlobalCommunicator)
{
shared_ptr<Communicator> c = getCommunicator();
@ -10,7 +10,7 @@ TEST_F(HelloTest, rpcWupTransGlobalCommunicator)
}, c.get());
}
TEST_F(HelloTest, rpcWupTransGlobalCommunicatorInCoroutine)
TEST_F(HelloTest, wupTransGlobalCommunicatorInCoroutine)
{
shared_ptr<Communicator> c = getCommunicator();
@ -20,7 +20,7 @@ TEST_F(HelloTest, rpcWupTransGlobalCommunicatorInCoroutine)
}
TEST_F(HelloTest, rpcWupTransServerCommunicator)
TEST_F(HelloTest, wupTransServerCommunicator)
{
transServerCommunicator([&](Communicator *comm){
checkWupTransSync(comm);

View File

@ -1,154 +0,0 @@
#include "FrameworkServer.h"
#include "framework/ConfigImp.h"
#include "framework/QueryImp.h"
#include "framework/StatImp.h"
#include "framework/LogImp.h"
#include "HttpImp.h"
#include "HelloImp.h"
using namespace std;
vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _clientStatData;
vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _serverStatData;
FrameworkServer::~FrameworkServer()
{
}
void
FrameworkServer::initialize()
{
ConfigImp::setConfigFile("test.conf", "test-content");
addServant<ConfigImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".ConfigObj");
addServant<QueryImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".QueryObj");
addServant<StatImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".StatObj");
addServant<LogImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".LogObj");
string s;
loadLogFormat("","",s);
//日志路径
g_globe._log_path = _conf["/tars/log<logpath>"];
//启动写线程
g_globe._group.start(TC_Common::strto<size_t>(_conf["/tars/log<logthread>"]));
string prefix = TC_Common::lower(_conf.get("/tars/log<ipfix>","true"));
g_globe._bIpPrefix = (prefix == "true") ? true : false;
//增加对象
addServant<LogImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".LogObj");
TARS_ADD_ADMIN_CMD_NORMAL("reloadLogFormat", FrameworkServer::loadLogFormat);
}
bool FrameworkServer::loadLogFormat(const string& command, const string& params, string& result)
{
TLOGDEBUG("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << endl);
try
{
TC_Config conf;
conf.parseFile(ServerConfig::ConfigFile);
vector<string> vHourlist;
map<string,string> mLogType;
try
{
string sHour = conf["/tars/log/format<hour>"];
vHourlist = TC_Common::sepstr<string>(sHour,"|;,");
sort(vHourlist.begin(),vHourlist.end());
unique(vHourlist.begin(),vHourlist.end());
result = "loadLogFormat succ:" + sHour;
TLOGDEBUG("FrameworkServer::loadLogFormat result:" << result << endl);
DLOG<< "FrameworkServer::loadLogFormat result:" << result << endl;
//hour=app.server.file|app2.server2.file2
map<string,string> mType;
if(conf.getDomainMap("/tars/log/logtype", mType))
{
map<string,string>::iterator it = mType.begin();
while(it != mType.end())
{
vector<string> vList = TC_Common::sepstr<string>(it->second,"|;,");
for(size_t i = 0;i < vList.size();i++)
{
//app.server.file = hour
mLogType[vList[i]] = it->first;
TLOGDEBUG("FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl);
DLOG<<"FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl;
}
it++;
}
}
g_globe.update(vHourlist, mLogType);
}
catch(exception& e)
{
result += e.what();
TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
}
return true;
}
catch(exception &e)
{
result += e.what();
TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
}
return false;
}
void FrameworkServer::destroyApp()
{
}
void FrameworkServer::run()
{
this->waitForShutdown();
}
/////////////////////////////////////////////////////////////////
RpcServer::~RpcServer()
{
}
void
RpcServer::initialize()
{
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".HelloObj");
addServant<HttpImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp);
}
/////////////////////////////////////////////////////////////////
void RpcServer::destroyApp()
{
}
void RpcServer::run()
{
this->waitForShutdown();
}

View File

@ -1,62 +0,0 @@
#ifndef _FrameworkServer_H_
#define _FrameworkServer_H_
#include <iostream>
#include "servant/Application.h"
using namespace tars;
extern vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _clientStatData;
extern vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _serverStatData;
class FrameworkServer : public Application, public TC_Thread
{
public:
/**
*
**/
virtual ~FrameworkServer();
/**
*
**/
virtual void initialize();
/**
*
**/
virtual void destroyApp();
protected:
virtual void run();
bool loadLogFormat(const string& command, const string& params, string& result);
};
class RpcServer : public Application, public TC_Thread
{
public:
/**
*
**/
virtual ~RpcServer();
/**
*
**/
virtual void initialize();
/**
*
**/
virtual void destroyApp();
protected:
virtual void run();
};
////////////////////////////////////////////
#endif

View File

@ -55,42 +55,42 @@ HelloServer::initialize()
{
// this->_epollServer->setUdpRecvBufferSize(10 * 1024 * 1024);
// this->_epollServer->setUdpSendBufferSize(10 * 1024 * 1024);
g_HelloServerObj = ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObj@" + getEpollServer()->getBindAdapter("HelloAdapter")->getEndpoint().toString();
g_TransDstServerObj = ServerConfig::Application + "." + ServerConfig::ServerName +".TransDstObj@" + getEpollServer()->getBindAdapter("TransDstAdapter")->getEndpoint().toString();
g_HelloServerObj =_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloObj@" + getEpollServer()->getBindAdapter("HelloAdapter")->getEndpoint().toString();
g_TransDstServerObj =_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransDstObj@" + getEpollServer()->getBindAdapter("TransDstAdapter")->getEndpoint().toString();
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".TransObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloTimeoutObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloNoTimeoutObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloTimeoutObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloNoTimeoutObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".Ipv6Obj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".Ipv6Obj");
addServant<HttpImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".HttpObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp);
addServant<HttpImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".HttpsObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpsObj", &TC_NetWorkBuffer::parseHttp);
addServant<HttpImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HttpObj");
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp);
addServant<HttpImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HttpsObj");
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpsObj", &TC_NetWorkBuffer::parseHttp);
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".TransDstObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransDstObj");
addServant<TranImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".TransWupObj");
addServant<TranImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransWupObj");
//设置服务的协议解析器, 对服务器端而言, 解析器的目的就是识别包长度
//parseStream,表示第0个字节开始,类型是uint32_t, 字节序, 这个字段表示包的长度
TC_NetWorkBuffer::protocol_functor func = AppProtocol::parseStream<0, uint32_t, true>;
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName +".TransWupObj", func);
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransWupObj", func);
addServant<CustomImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".CustomObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".CustomObj", parse);
addServant<CustomImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".CustomObj");
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".CustomObj", parse);
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSLObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL1Obj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL2Obj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL3Obj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".AuthObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".UdpObj");
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".UdpIpv6Obj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSLObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL1Obj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL2Obj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL3Obj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".AuthObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".UdpObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".UdpIpv6Obj");
addServant<PushImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".PushObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".PushObj", parse);
addServant<PushImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".PushObj");
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".PushObj", parse);
pushThread = new PushInfoThread();
pushThread->start();

View File

@ -0,0 +1,32 @@
//
// Created by jarod on 2024/3/14.
//
#include "RpcServer.h"
#include "HelloImp.h"
#include "HttpImp.h"
RpcServer::~RpcServer()
{
}
void
RpcServer::initialize()
{
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HelloObj");
addServant<HttpImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj");
addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp);
}
/////////////////////////////////////////////////////////////////
void RpcServer::destroyApp()
{
}
void RpcServer::run()
{
this->waitForShutdown();
}

View File

@ -0,0 +1,32 @@
//
// Created by jarod on 2024/3/14.
//
#pragma once
#include <iostream>
#include "servant/Application.h"
using namespace tars;
class RpcServer : public Application, public TC_Thread
{
public:
/**
*
**/
virtual ~RpcServer();
/**
*
**/
virtual void initialize();
/**
*
**/
virtual void destroyApp();
protected:
virtual void run();
};

View File

@ -13,7 +13,7 @@ WinServer::~WinServer()
void
WinServer::initialize()
{
addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".WinObj");
addServant<HelloImp>(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".WinObj");
addConfig("test.conf");
TARS_ADD_ADMIN_CMD_NORMAL("AdminCmdNormalTest", WinServer::cmdAdd);

View File

@ -3,13 +3,13 @@
<client>
#tarsregistry locator
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
sync-invoke-timeout = 50000
async-invoke-timeout = 50000
#refresh endpoint interval
refresh-endpoint-interval = 3000
#stat obj
stat = TestApp.FrameworkServer.StatObj@tcp -h 127.0.0.1 -p 12004
stat = tars.tarsmock.StatObj@tcp -h 127.0.0.1 -p 12004
#max send queue length limit
sendqueuelimit = 1000000
#async queue length limit

View File

@ -1,129 +0,0 @@
<tars>
<application>
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
#最大超时时间(毫秒)
sync-invoke-timeout = 5000
async-invoke-timeout = 60000
#刷新端口时间间隔(毫秒)
refresh-endpoint-interval = 5000
#模块间调用[可选]
stat = TestApp.FrameworkServer.StatObj
#发送队列长度
sendqueuelimit = 1000000
#异步回调队列个数限制
asyncqueuecap = 1000000
#网络异步回调线程个数
asyncthread = 3
#网络线程个数
netthread = 2
#合并回调线程和网络线程(以网络线程个数为准)
mergenetasync = 0
#模块名称
modulename = TestApp.FrameworkServer
</client>
#定义所有绑定的IP
<server>
start_output = ERROR
closecout = 0
#应用名称
app = TestApp
#服务名称
server = FrameworkServer
#服务的数据目录,可执行文件,配置文件等
basepath = .
datapath = .
#日志路径
logpath = .
#网络线程个数
netthread = 1
#合并网络和业务线程(以网络线程个数为准)
mergenetimp = 0
opencoroutine = 0
loglevel=TARS
#本地管理套接字[可选]
local = tcp -h 127.0.0.1 -p 15791 -t 10000
#本地node的ip:port:timeout[可选]
# node = ServerObj@tcp -h 127.0.0.1 -p 2345 -t 10000
#配置中心的地址[可选]
config = TestApp.FrameworkServer.ConfigObj
#配置中心的地址[可选]
# notify = tars.tarsconfig.NotifyObj
#远程LogServer[可选]
log = TestApp.FrameworkServer.LogObj
<ConfigAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 11003 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = TestApp.FrameworkServer.ConfigObj
#queue capacity
queuecap = 1000000
</ConfigAdapter>
<LogAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 11005 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = TestApp.FrameworkServer.LogObj
#queue capacity
queuecap = 1000000
</LogAdapter>
<RegistryAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 11004 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = TestApp.FrameworkServer.QueryObj
#queue capacity
queuecap = 1000000
</RegistryAdapter>
<StatAdapter>
#ip:port:timeout
endpoint = tcp -h 127.0.0.1 -p 12004 -t 60000
#allow ip
allow =
#max connection num
maxconns = 4096
#imp thread num
threads = 5
#servant
servant = TestApp.FrameworkServer.StatObj
#queue capacity
queuecap = 1000000
</StatAdapter>
</server>
</application>
<log>
logpath = .
logthread = 1
ipfix = true
</log>
</tars>

View File

@ -1,688 +0,0 @@

#include <iterator>
#include <algorithm>
#include "DbHandle.h"
TC_ReadersWriterData<ObjectsCache> CDbHandle::_objectsCache;
TC_ReadersWriterData<CDbHandle::SetDivisionCache> CDbHandle::_setDivisionCache;
TC_ReadersWriterData<std::map<int, CDbHandle::GroupPriorityEntry> > CDbHandle::_mapGroupPriority;
//key-ip, value-组编号
TC_ReadersWriterData<map<string, int> > CDbHandle::_groupIdMap;
//key-group_name, value-组编号
TC_ReadersWriterData<map<string, int> > CDbHandle::_groupNameMap;
int CDbHandle::init(TC_Config *pconf)
{
return 0;
}
vector<EndpointF> CDbHandle::findObjectById(const string& id)
{
ObjectsCache::iterator it;
ObjectsCache& usingCache = _objectsCache.getReaderData();
if ((it = usingCache.find(id)) != usingCache.end())
{
return it->second.vActiveEndpoints;
}
else
{
vector<EndpointF> activeEp;
return activeEp;
}
}
int CDbHandle::findObjectById4All(const string& id, vector<EndpointF>& activeEp, vector<EndpointF>& inactiveEp)
{
TLOGDEBUG(__FUNCTION__ << " id: " << id << endl);
ObjectsCache::iterator it;
ObjectsCache& usingCache = _objectsCache.getReaderData();
if ((it = usingCache.find(id)) != usingCache.end())
{
activeEp = it->second.vActiveEndpoints;
inactiveEp = it->second.vInactiveEndpoints;
}
else
{
activeEp.clear();
inactiveEp.clear();
}
return 0;
}
vector<EndpointF> CDbHandle::getEpsByGroupId(const vector<EndpointF>& vecEps, const GroupUseSelect GroupSelect, int iGroupId, ostringstream& os)
{
os << "|";
vector<EndpointF> vResult;
for (unsigned i = 0; i < vecEps.size(); i++)
{
os << vecEps[i].host << ":" << vecEps[i].port << "(" << vecEps[i].groupworkid << ");";
if (GroupSelect == ENUM_USE_WORK_GROUPID && vecEps[i].groupworkid == iGroupId)
{
vResult.push_back(vecEps[i]);
}
if (GroupSelect == ENUM_USE_REAL_GROUPID && vecEps[i].grouprealid == iGroupId)
{
vResult.push_back(vecEps[i]);
}
}
return vResult;
}
vector<EndpointF> CDbHandle::getEpsByGroupId(const vector<EndpointF>& vecEps, const GroupUseSelect GroupSelect, const set<int>& setGroupID, ostringstream& os)
{
os << "|";
std::vector<EndpointF> vecResult;
for (std::vector<EndpointF>::size_type i = 0; i < vecEps.size(); i++)
{
os << vecEps[i].host << ":" << vecEps[i].port << "(" << vecEps[i].groupworkid << ")";
if (GroupSelect == ENUM_USE_WORK_GROUPID && setGroupID.count(vecEps[i].groupworkid) == 1)
{
vecResult.push_back(vecEps[i]);
}
if (GroupSelect == ENUM_USE_REAL_GROUPID && setGroupID.count(vecEps[i].grouprealid) == 1)
{
vecResult.push_back(vecEps[i]);
}
}
return vecResult;
}
int CDbHandle::findObjectByIdInSameGroup(const string& id, const string& ip, vector<EndpointF>& activeEp, vector<EndpointF>& inactiveEp, ostringstream& os)
{
activeEp.clear();
inactiveEp.clear();
int iClientGroupId = getGroupId(ip);
os << "|(" << iClientGroupId << ")";
if (iClientGroupId == -1)
{
return findObjectById4All(id, activeEp, inactiveEp);
}
ObjectsCache::iterator it;
ObjectsCache& usingCache = _objectsCache.getReaderData();
if ((it = usingCache.find(id)) != usingCache.end())
{
activeEp = getEpsByGroupId(it->second.vActiveEndpoints, ENUM_USE_WORK_GROUPID, iClientGroupId, os);
inactiveEp = getEpsByGroupId(it->second.vInactiveEndpoints, ENUM_USE_WORK_GROUPID, iClientGroupId, os);
if (activeEp.size() == 0) //没有同组的endpoit,匹配未启用分组的服务
{
activeEp = getEpsByGroupId(it->second.vActiveEndpoints, ENUM_USE_WORK_GROUPID, -1, os);
inactiveEp = getEpsByGroupId(it->second.vInactiveEndpoints, ENUM_USE_WORK_GROUPID, -1, os);
}
if (activeEp.size() == 0) //没有同组的endpoit
{
activeEp = it->second.vActiveEndpoints;
inactiveEp = it->second.vInactiveEndpoints;
}
}
return 0;
}
int CDbHandle::findObjectByIdInGroupPriority(const std::string& sID, const std::string& sIP, std::vector<EndpointF>& vecActive, std::vector<EndpointF>& vecInactive, std::ostringstream& os)
{
vecActive.clear();
vecInactive.clear();
int iClientGroupID = getGroupId(sIP);
os << "|(" << iClientGroupID << ")";
if (iClientGroupID == -1)
{
return findObjectById4All(sID, vecActive, vecInactive);
}
ObjectsCache& usingCache = _objectsCache.getReaderData();
ObjectsCache::iterator itObject = usingCache.find(sID);
if (itObject == usingCache.end()) return 0;
//首先在同组中查找
{
vecActive = getEpsByGroupId(itObject->second.vActiveEndpoints, ENUM_USE_WORK_GROUPID, iClientGroupID, os);
vecInactive = getEpsByGroupId(itObject->second.vInactiveEndpoints, ENUM_USE_WORK_GROUPID, iClientGroupID, os);
os << "|(In Same Group: " << iClientGroupID << " Active=" << vecActive.size() << " Inactive=" << vecInactive.size() << ")";
}
//启用分组,但同组中没有找到,在优先级序列中查找
std::map<int, GroupPriorityEntry> & mapPriority = _mapGroupPriority.getReaderData();
for (std::map<int, GroupPriorityEntry>::iterator it = mapPriority.begin(); it != mapPriority.end() && vecActive.empty(); it++)
{
if (it->second.setGroupID.count(iClientGroupID) == 0)
{
os << "|(Not In Priority " << it->second.sGroupID << ")";
continue;
}
vecActive = getEpsByGroupId(itObject->second.vActiveEndpoints, ENUM_USE_WORK_GROUPID, it->second.setGroupID, os);
vecInactive = getEpsByGroupId(itObject->second.vInactiveEndpoints, ENUM_USE_WORK_GROUPID, it->second.setGroupID, os);
os << "|(In Priority: " << it->second.sGroupID << " Active=" << vecActive.size() << " Inactive=" << vecInactive.size() << ")";
}
//没有同组的endpoit,匹配未启用分组的服务
if (vecActive.empty())
{
vecActive = getEpsByGroupId(itObject->second.vActiveEndpoints, ENUM_USE_WORK_GROUPID, -1, os);
vecInactive = getEpsByGroupId(itObject->second.vInactiveEndpoints, ENUM_USE_WORK_GROUPID, -1, os);
os << "|(In No Grouop: Active=" << vecActive.size() << " Inactive=" << vecInactive.size() << ")";
}
//在未分组的情况下也没有找到,返回全部地址(此时基本上所有的服务都已挂掉)
if (vecActive.empty())
{
vecActive = itObject->second.vActiveEndpoints;
vecInactive = itObject->second.vInactiveEndpoints;
os << "|(In All: Active=" << vecActive.size() << " Inactive=" << vecInactive.size() << ")";
}
return 0;
}
int CDbHandle::findObjectByIdInSameStation(const std::string& sID, const std::string& sStation, std::vector<EndpointF>& vecActive, std::vector<EndpointF>& vecInactive, std::ostringstream& os)
{
vecActive.clear();
vecInactive.clear();
//获得station所有组
std::map<int, GroupPriorityEntry> & mapPriority = _mapGroupPriority.getReaderData();
std::map<int, GroupPriorityEntry>::iterator itGroup = mapPriority.end();
for (itGroup = mapPriority.begin(); itGroup != mapPriority.end(); itGroup++)
{
if (itGroup->second.sStation != sStation) continue;
break;
}
if (itGroup == mapPriority.end())
{
os << "|not found station:" << sStation;
return -1;
}
ObjectsCache& usingCache = _objectsCache.getReaderData();
ObjectsCache::iterator itObject = usingCache.find(sID);
if (itObject == usingCache.end()) return 0;
//查找对应所有组下的IP地址
vecActive = getEpsByGroupId(itObject->second.vActiveEndpoints, ENUM_USE_REAL_GROUPID, itGroup->second.setGroupID, os);
vecInactive = getEpsByGroupId(itObject->second.vInactiveEndpoints, ENUM_USE_REAL_GROUPID, itGroup->second.setGroupID, os);
return 0;
}
int CDbHandle::findObjectByIdInSameSet(const string& sID, const vector<string>& vtSetInfo, std::vector<EndpointF>& vecActive, std::vector<EndpointF>& vecInactive, std::ostringstream& os)
{
string sSetName = vtSetInfo[0];
string sSetArea = vtSetInfo[0] + "." + vtSetInfo[1];
string sSetId = vtSetInfo[0] + "." + vtSetInfo[1] + "." + vtSetInfo[2];
SetDivisionCache& usingSetDivisionCache = _setDivisionCache.getReaderData();
SetDivisionCache::iterator it = usingSetDivisionCache.find(sID);
if (it == usingSetDivisionCache.end())
{
//此情况下没启动set
TLOGINFO("CDbHandle::findObjectByIdInSameSet:" << __LINE__ << "|" << sID << " haven't start set|" << sSetId << endl);
return -1;
}
map<string, vector<SetServerInfo> >::iterator setNameIt = it->second.find(sSetName);
if (setNameIt == (it->second).end())
{
//此情况下没启动set
TLOGINFO("CDbHandle::findObjectByIdInSameSet:" << __LINE__ << "|" << sID << " haven't start set|" << sSetId << endl);
return -1;
}
if (vtSetInfo[2] == "*")
{
//检索通配组和set组中的所有服务
vector<SetServerInfo> vServerInfo = setNameIt->second;
for (size_t i = 0; i < vServerInfo.size(); i++)
{
if (vServerInfo[i].sSetArea == sSetArea)
{
if (vServerInfo[i].bActive)
{
vecActive.push_back(vServerInfo[i].epf);
}
else
{
vecInactive.push_back(vServerInfo[i].epf);
}
}
}
return (vecActive.empty() && vecInactive.empty()) ? -2 : 0;
}
else
{
// 1.从指定set组中查找
int iRet = findObjectByIdInSameSet(sSetId, setNameIt->second, vecActive, vecInactive, os);
if (iRet != 0 && vtSetInfo[2] != "*")
{
// 2. 步骤1中没找到在通配组里找
string sWildSetId = vtSetInfo[0] + "." + vtSetInfo[1] + ".*";
iRet = findObjectByIdInSameSet(sWildSetId, setNameIt->second, vecActive, vecInactive, os);
}
return iRet;
}
}
int CDbHandle::findObjectByIdInSameSet(const string& sSetId, const vector<SetServerInfo>& vSetServerInfo, std::vector<EndpointF>& vecActive, std::vector<EndpointF>& vecInactive, std::ostringstream& os)
{
for (size_t i = 0; i < vSetServerInfo.size(); ++i)
{
if (vSetServerInfo[i].sSetId == sSetId)
{
if (vSetServerInfo[i].bActive)
{
vecActive.push_back(vSetServerInfo[i].epf);
}
else
{
vecInactive.push_back(vSetServerInfo[i].epf);
}
}
}
int iRet = (vecActive.empty() && vecInactive.empty()) ? -2 : 0;
return iRet;
}
void CDbHandle::updateObjectsCache(const ObjectsCache& objCache, bool updateAll)
{
//全量更新
if (updateAll)
{
_objectsCache.getWriterData() = objCache;
_objectsCache.swap();
}
else
{
//用查询数据覆盖一下
_objectsCache.getWriterData() = _objectsCache.getReaderData();
ObjectsCache& tmpObjCache = _objectsCache.getWriterData();
ObjectsCache::const_iterator it = objCache.begin();
for (; it != objCache.end(); it++)
{
//增量的时候加载的是服务的所有节点,因此这里直接替换
tmpObjCache[it->first] = it->second;
}
_objectsCache.swap();
}
}
void CDbHandle::updateInactiveObjectsCache(const ObjectsCache& objCache, bool updateAll)
{
//全量更新
if (updateAll)
{
_objectsCache.getWriterData() = objCache;
_objectsCache.swap();
}
else
{
//用查询数据覆盖一下
_objectsCache.getWriterData() = _objectsCache.getReaderData();
ObjectsCache& tmpObjCache = _objectsCache.getWriterData();
ObjectsCache::const_iterator it = objCache.begin();
for (; it != objCache.end(); it++)
{
//增量的时候加载的是服务的所有节点,因此这里直接替换
tmpObjCache[it->first].vInactiveEndpoints.push_back((it->second).vInactiveEndpoints[0]);
}
_objectsCache.swap();
}
}
void CDbHandle::updateActiveObjectsCache(const ObjectsCache& objCache, bool updateAll)
{
//全量更新
if (updateAll)
{
_objectsCache.getWriterData() = objCache;
_objectsCache.swap();
}
else
{
//用查询数据覆盖一下
_objectsCache.getWriterData() = _objectsCache.getReaderData();
ObjectsCache& tmpObjCache = _objectsCache.getWriterData();
ObjectsCache::const_iterator it = objCache.begin();
for (; it != objCache.end(); it++)
{
//增量的时候加载的是服务的所有节点,因此这里直接替换
tmpObjCache[it->first].vActiveEndpoints.push_back((it->second).vActiveEndpoints[0]);
}
_objectsCache.swap();
}
}
void CDbHandle::addActiveEndPoint(const string& objName, const Int32 port, const Int32 istcp)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
//endPoint.setId = setName + "." + setArea + "." + setGroup;
objectsCache[objName].vActiveEndpoints.push_back(endPoint);
updateActiveObjectsCache(objectsCache, false);
}
void CDbHandle::addEndPointbySet(const string& objName, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
endPoint.setId = setName + "." + setArea + "." + setGroup;
objectsCache[objName].vActiveEndpoints.push_back(endPoint);
updateActiveObjectsCache(objectsCache, false);
if (setName.size())
{
InsertSetRecord(objName, setName, setArea, setGroup, endPoint);
}
}
void CDbHandle::addActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
endPoint.setId = setName;
endPoint.weight = 2;
endPoint.weightType = 1;
objectsCache[objName].vActiveEndpoints.push_back(endPoint);
updateActiveObjectsCache(objectsCache, false);
}
void CDbHandle::addInActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
endPoint.setId = setName;
endPoint.weight = 2;
endPoint.weightType = 1;
objectsCache[objName].vInactiveEndpoints.push_back(endPoint);
updateInactiveObjectsCache(objectsCache, false);
}
void CDbHandle::addActiveWeight2EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
endPoint.setId = setName;
endPoint.weight = 2;
endPoint.weightType = 2;
objectsCache[objName].vActiveEndpoints.push_back(endPoint);
updateActiveObjectsCache(objectsCache, false);
}
void CDbHandle::addInactiveEndPoint(const string& objName, const Int32 port, const Int32 istcp)
{
#define LOCAL_HOST "127.0.0.1"
ObjectsCache objectsCache;
EndpointF endPoint;
endPoint.host = LOCAL_HOST;
endPoint.port = port;
endPoint.timeout = 30000;
endPoint.istcp = istcp;
//endPoint.setId = setName;
objectsCache[objName].vInactiveEndpoints.push_back(endPoint);
updateInactiveObjectsCache(objectsCache, false);
}
void CDbHandle::cleanEndPoint()
{
ObjectsCache objectsCache;
updateObjectsCache(objectsCache, true);
}
int CDbHandle::getGroupId(const string& ip)
{
map<string, int>& groupIdMap = _groupIdMap.getReaderData();
map<string, int>::iterator it = groupIdMap.find(ip);
if (it != groupIdMap.end())
{
return it->second;
}
uint32_t uip = stringIpToInt(ip);
string ipStar = Ip2StarStr(uip);
it = groupIdMap.find(ipStar);
if (it != groupIdMap.end())
{
return it->second;
}
return -1;
}
uint32_t CDbHandle::stringIpToInt(const std::string& sip)
{
string ip1, ip2, ip3, ip4;
uint32_t dip, p1, p2, p3;
dip = 0;
p1 = sip.find('.');
p2 = sip.find('.', p1 + 1);
p3 = sip.find('.', p2 + 1);
ip1 = sip.substr(0, p1);
ip2 = sip.substr(p1 + 1, p2 - p1 - 1);
ip3 = sip.substr(p2 + 1, p3 - p2 - 1);
ip4 = sip.substr(p3 + 1, sip.size() - p3 - 1);
(((unsigned char *)&dip)[0]) = TC_Common::strto<unsigned int>(ip1);
(((unsigned char *)&dip)[1]) = TC_Common::strto<unsigned int>(ip2);
(((unsigned char *)&dip)[2]) = TC_Common::strto<unsigned int>(ip3);
(((unsigned char *)&dip)[3]) = TC_Common::strto<unsigned int>(ip4);
return htonl(dip);
}
string CDbHandle::Ip2Str(uint32_t ip)
{
char str[50];
unsigned char *p = (unsigned char *)&ip;
sprintf(str, "%u.%u.%u.%u", p[3], p[2], p[1], p[0]);
return string(str);
}
string CDbHandle::Ip2StarStr(uint32_t ip)
{
char str[50];
unsigned char *p = (unsigned char *)&ip;
sprintf(str, "%u.%u.%u.*", p[3], p[2], p[1]);
return string(str);
}
void CDbHandle::InsertSetRecord(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf)
{
SetDivisionCache setDivisionCache;
string setId = setName + "." + setArea + "." + setGroup;
SetServerInfo setServerInfo;
setServerInfo.bActive = true;
setServerInfo.epf = epf;
setServerInfo.sSetId = setId;
setServerInfo.sSetArea = setArea;
setDivisionCache[objName][setName].push_back(setServerInfo);
setServerInfo.bActive = false;
setServerInfo.epf.port = 10204;
setDivisionCache[objName][setName].push_back(setServerInfo);
updateDivisionCache(setDivisionCache, true);
}
void CDbHandle::InsertSetRecord4Inactive(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf)
{
SetDivisionCache setDivisionCache;
string setId = setName + "." + setArea + "." + setGroup;
SetServerInfo setServerInfo;
setServerInfo.bActive = false;
setServerInfo.epf = epf;
setServerInfo.sSetId = setId;
setServerInfo.sSetArea = setArea;
setDivisionCache[objName][setName].push_back(setServerInfo);
updateDivisionCache(setDivisionCache, false);
}
void CDbHandle::updateDivisionCache(SetDivisionCache& setDivisionCache,bool updateAll)
{
//ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(updateAll)
{
if (setDivisionCache.size() == 0)
{
return;
}
SetDivisionCache::iterator it = setDivisionCache.begin();
for(;it != setDivisionCache.end();it++)
{
if(it->second.size() > 0)
{
map<string,vector<CDbHandle::SetServerInfo> >::iterator it_inner = it->second.begin();
for(;it_inner != it->second.end();it_inner++)
{
//updateCpuLoadInfo(it_inner->second);
}
}
}
_setDivisionCache.getWriterData() = setDivisionCache;
_setDivisionCache.swap();
}
else
{
_setDivisionCache.getWriterData() = _setDivisionCache.getReaderData();
SetDivisionCache& tmpsetCache = _setDivisionCache.getWriterData();
SetDivisionCache::const_iterator it = setDivisionCache.begin();
for(;it != setDivisionCache.end();it++)
{
//<2F><>set<65><74>Ϣ<EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
if(it->second.size() > 0)
{
tmpsetCache[it->first] = it->second;
}
else if(tmpsetCache.count(it->first))
{
tmpsetCache.erase(it->first);
}
}
_setDivisionCache.swap();
}
}
#if 0
void CDbHandle::updateCpuLoadInfo(vector<EndpointF> &vEndpointF)
{
CpuLoadCache &cpuLoadCacheMap = _cpuLoadCacheMap.getReaderData();
for(size_t i = 0; i < vEndpointF.size(); ++i)
{
map<string,CpuLoadInfo>::const_iterator const_it_cpu = cpuLoadCacheMap.find(vEndpointF[i].host);
if(const_it_cpu != cpuLoadCacheMap.end())
{
struct tm tb;
int ret = TC_Common::str2tm(const_it_cpu->second.sHeartTime, "%Y-%m-%d %H:%M:%S", tb);
if(ret == 0)
{
vEndpointF[i].cpuload = const_it_cpu->second.iCpuLoad;
vEndpointF[i].sampletime = mktime(&tb);
}
else
{
vEndpointF[i].cpuload = -1;
vEndpointF[i].sampletime = 0;
}
}
else
{
vEndpointF[i].cpuload = -1;
vEndpointF[i].sampletime = 0;
}
}
}
void CDbHandle::updateCpuLoadInfo(vector<CDbHandle::SetServerInfo> &vSetServerInfo)
{
CpuLoadCache &cpuLoadCacheMap = _cpuLoadCacheMap.getReaderData();
for(size_t i = 0; i < vSetServerInfo.size(); ++i)
{
map<string,CpuLoadInfo>::const_iterator const_it_cpu = cpuLoadCacheMap.find(vSetServerInfo[i].epf.host);
if(const_it_cpu != cpuLoadCacheMap.end())
{
struct tm tb;
int ret = TC_Common::str2tm(const_it_cpu->second.sHeartTime, "%Y-%m-%d %H:%M:%S", tb);
if(ret == 0)
{
vSetServerInfo[i].epf.cpuload = const_it_cpu->second.iCpuLoad;
vSetServerInfo[i].epf.sampletime = mktime(&tb);
}
else
{
vSetServerInfo[i].epf.cpuload = -1;
vSetServerInfo[i].epf.sampletime = 0;
}
}
else
{
vSetServerInfo[i].epf.cpuload = -1;
vSetServerInfo[i].epf.sampletime = 0;
}
}
}
#endif

View File

@ -1,214 +0,0 @@

#ifndef __DB_HANDLE_H__
#define __DB_HANDLE_H__
#include "util/tc_common.h"
#include "util/tc_config.h"
#include "util/tc_monitor.h"
#include "util/tc_file.h"
#include "jmem/jmem_hashmap.h"
#include "util/tc_readers_writer_data.h"
#include <set>
#include "servant/RemoteLogger.h"
#include "servant/EndpointF.h"
#include "RegistryDescriptor.h"
using namespace tars;
//////////////////////////////////////////////////////
//<servant, ObjectItem>
typedef map<string, ObjectItem> ObjectsCache;
//////////////////////////////////////////////////////
/**
*
*/
class CDbHandle
{
private:
struct GroupPriorityEntry
{
std::string sGroupID;
std::string sStation;
std::set<int> setGroupID;
};
enum GroupUseSelect
{
ENUM_USE_WORK_GROUPID,
ENUM_USE_REAL_GROUPID
};
//set中服务的信息
struct SetServerInfo
{
string sSetId;
string sSetArea;
bool bActive;
EndpointF epf;
};
//<servant,setname,vector>
typedef map<string,map<string,vector<CDbHandle::SetServerInfo> > > SetDivisionCache;
public:
/**
*
*/
CDbHandle()
{
}
/**
*
* @param pconf
* @return 0- others-
*/
int init(TC_Config *pconf);
/** 根据id获取对象
*
* @param id
*
* @return endpoint
*/
vector<EndpointF> findObjectById(const string & id);
/** 根据id获取对象
*
* @param id
* @out param activeEp
* @out param inactiveEp
*
* @return 0- others-
*/
int findObjectById4All(const string & id, vector<EndpointF>& activeEp, vector<EndpointF>& inactiveEp);
/** 根据id获取同组对象
*
* @param id
* @param ip
* @out param activeEp
* @out param inactiveEp
* @out param os 使
*
* @return 0- others-
*/
int findObjectByIdInSameGroup(const string & id, const string & ip, vector<EndpointF>& activeEp, vector<EndpointF>& inactiveEp, ostringstream &os);
/** 根据id获取优先级序列中的对象
*
* @param id
* @param ip
* @out param vecActive
* @out param vecInactive
* @out param os 使
*
* @return 0- others-
*/
int findObjectByIdInGroupPriority(const std::string &sID, const std::string &sIP, std::vector<EndpointF> & vecActive, std::vector<EndpointF> & vecInactive, std::ostringstream & os);
/** 根据id和归属地获取全部对象
*
* @param id
* @param sStation
* @out param vecActive
* @out param vecInactive
* @out param os 使
*
* @return 0- others-
*/
int findObjectByIdInSameStation(const std::string &sID, const std::string & sStation, std::vector<EndpointF> & vecActive, std::vector<EndpointF> & vecInactive, std::ostringstream & os);
/** 根据id和set信息获取全部对象
*
* @param sID
* @param vtSetInfo set
* @out param vecActive
* @out param vecInactive
* @out param os 使
*
* @return 0- others-
*/
int findObjectByIdInSameSet(const string &sID, const vector<string> &vtSetInfo, std::vector<EndpointF> & vecActive, std::vector<EndpointF> & vecInactive, std::ostringstream & os);
/** 根据setId获取全部对象
*
* @param sSetId set
* @param vSetServerInfo SetName
* @out param vecActive
* @out param vecInactive
* @out param os 使
*
* @return 0- others-
*/
int findObjectByIdInSameSet(const string &sSetId, const vector<SetServerInfo>& vSetServerInfo, std::vector<EndpointF> & vecActive, std::vector<EndpointF> & vecInactive, std::ostringstream & os);
/**
* ipid
* @return int <0
*/
int getGroupId(const string& ip);
/**
* ip
*/
static uint32_t stringIpToInt(const std::string& sip);
/**
* ip
*/
static string Ip2Str(uint32_t ip);
/**
* ip
*/
static string Ip2StarStr(uint32_t ip);
static void updateObjectsCache(const ObjectsCache& objCache, bool updateAll);
static void updateActiveObjectsCache(const ObjectsCache& objCache, bool updateAll);
static void updateInactiveObjectsCache(const ObjectsCache& objCache, bool updateAll);
static void updateDivisionCache(SetDivisionCache& setDivisionCache,bool updateAll);
static void updateCpuLoadInfo(vector<EndpointF> &vEndpointF);
static void updateCpuLoadInfo(vector<CDbHandle::SetServerInfo> &vSetServerInfo);
static void InsertSetRecord(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf);
static void InsertSetRecord4Inactive(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf);
static void addActiveEndPoint(const string& objName, const Int32 port, const Int32 istcp);
static void addInactiveEndPoint(const string& objName, const Int32 port, const Int32 istcp);
static void addEndPointbySet(const string& objName, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup);
static void addActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = "");
static void addInActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = "");
static void addActiveWeight2EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = "");
static void cleanEndPoint();;
protected:
/**
* group idEndpoint
*/
vector<EndpointF> getEpsByGroupId(const vector<EndpointF> & vecEps, const GroupUseSelect GroupSelect, int iGroupId, ostringstream &os);
vector<EndpointF> getEpsByGroupId(const vector<EndpointF> & vecEps, const GroupUseSelect GroupSelect, const set<int> & setGroupID, ostringstream & os);
protected:
static TC_ReadersWriterData<ObjectsCache> _objectsCache;
//set划分缓存
static TC_ReadersWriterData<SetDivisionCache> _setDivisionCache;
//优先级的序列
static TC_ReadersWriterData<std::map<int, GroupPriorityEntry> > _mapGroupPriority;
//分组信息
static TC_ReadersWriterData<map<string,int> > _groupIdMap;
static TC_ReadersWriterData<map<string,int> > _groupNameMap;
};
#endif

View File

@ -1,196 +0,0 @@

#include "QueryImp.h"
#include "util/tc_logger.h"
#include "util/tc_clientsocket.h"
void QueryImp::initialize()
{
TLOGDEBUG("begin QueryImp init"<<endl);
}
vector<EndpointF> QueryImp::findObjectById(const string & id, tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
vector<EndpointF> eps = _db.findObjectById(id);
ostringstream os;
doDaylog(FUNID_findObjectById,id,eps,vector<EndpointF>(),current,os);
return eps;
}
tars::Int32 QueryImp::findObjectById4Any(const std::string & id,vector<tars::EndpointF> &activeEp,vector<tars::EndpointF> &inactiveEp,tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
int iRet = _db.findObjectById4All(id, activeEp, inactiveEp);
ostringstream os;
doDaylog(FUNID_findObjectById4Any,id,activeEp,inactiveEp,current,os);
return iRet;
}
int QueryImp::findObjectById4All(const std::string & id, vector<tars::EndpointF> &activeEp,vector<tars::EndpointF> &inactiveEp,tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
ostringstream os;
int iRet = _db.findObjectByIdInGroupPriority(id,current->getIp(),activeEp, inactiveEp,os);
doDaylog(FUNID_findObjectById4All,id,activeEp,inactiveEp,current,os);
return iRet;
}
int QueryImp::findObjectByIdInSameGroup(const std::string & id, vector<tars::EndpointF> &activeEp,vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
ostringstream os;
TLOGINFO(__FUNCTION__ << ":" << __LINE__ << "|" << id << "|" << current->getIp() << endl);
int iRet = _db.findObjectByIdInGroupPriority(id, current->getIp(), activeEp, inactiveEp, os);
doDaylog(FUNID_findObjectByIdInSameGroup,id,activeEp,inactiveEp,current,os);
return iRet;
}
Int32 QueryImp::findObjectByIdInSameStation(const std::string & id, const std::string & sStation, vector<tars::EndpointF> &activeEp, vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
ostringstream os;
int iRet = _db.findObjectByIdInSameStation(id, sStation, activeEp, inactiveEp, os);
doDaylog(FUNID_findObjectByIdInSameStation,id,activeEp,inactiveEp,current,os);
return iRet;
}
Int32 QueryImp::findObjectByIdInSameSet(const std::string & id,const std::string & setId,vector<tars::EndpointF> &activeEp,vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current)
{
// LOG_CONSOLE_DEBUG << endl;
vector<string> vtSetInfo = TC_Common::sepstr<string>(setId,".");
if (vtSetInfo.size()!=3 ||(vtSetInfo.size()==3&&(vtSetInfo[0]=="*"||vtSetInfo[1]=="*")))
{
TLOGERROR("QueryImp::findObjectByIdInSameSet:|set full name error[" << id << "_" << setId <<"]|" << current->getIp() << endl);
return -1;
}
ostringstream os;
int iRet = _db.findObjectByIdInSameSet(id, vtSetInfo, activeEp, inactiveEp, os);
if (-1 == iRet)
{
//未启动set启动ip分组策略
return findObjectByIdInSameGroup(id, activeEp, inactiveEp, current);
}
else if (-2 == iRet)
{
//启动了set但未找到任何服务节点
TLOGERROR("QueryImp::findObjectByIdInSameSet |no one server found for [" << id << "_" << setId <<"]|" << current->getIp() << endl);
return -1;
}
else if (-3 == iRet)
{
//启动了set但未找到任何地区set,严格上不应该出现此类情形,配置错误或主调设置错误会引起此类错误
TLOGERROR("QueryImp::findObjectByIdInSameSet |no set area found [" << id << "_" << setId <<"]|" << current->getIp() << endl);
return -1;
}
doDaylog(FUNID_findObjectByIdInSameSet,id,activeEp,inactiveEp,current,os,setId);
return iRet;
}
void QueryImp::doDaylog(const FUNID eFnId,const string& id,const vector<tars::EndpointF> &activeEp, const vector<tars::EndpointF> &inactiveEp, const tars::CurrentPtr& current,const ostringstream& os,const string& sSetid)
{
string sEpList;
for(size_t i = 0; i < activeEp.size(); i++)
{
if(0 != i)
{
sEpList += ";";
}
sEpList += activeEp[i].host + ":" + TC_Common::tostr(activeEp[i].port);
}
sEpList += "|";
for(size_t i = 0; i < inactiveEp.size(); i++)
{
if(0 != i)
{
sEpList += ";";
}
sEpList += inactiveEp[i].host + ":" + TC_Common::tostr(inactiveEp[i].port);
}
switch(eFnId)
{
case FUNID_findObjectById4All:
case FUNID_findObjectByIdInSameGroup:
{
FDLOG("query_idc") << eFunTostr(eFnId)<<"|"<<current->getIp() << "|"<< current->getPort() << "|" << id << "|" <<sSetid << "|" << sEpList <<os.str()<< endl;
}
break;
case FUNID_findObjectByIdInSameSet:
{
FDLOG("query_set") << eFunTostr(eFnId)<<"|"<<current->getIp() << "|"<< current->getPort() << "|" << id << "|" <<sSetid << "|" << sEpList <<os.str()<< endl;
}
break;
case FUNID_findObjectById4Any:
case FUNID_findObjectById:
case FUNID_findObjectByIdInSameStation:
default:
{
FDLOG("query") << eFunTostr(eFnId)<<"|"<<current->getIp() << "|"<< current->getPort() << "|" << id << "|" <<sSetid << "|" << sEpList <<os.str()<< endl;
}
break;
}
}
string QueryImp::eFunTostr(const FUNID eFnId)
{
string sFun = "";
switch(eFnId)
{
case FUNID_findObjectByIdInSameGroup:
{
sFun = "findObjectByIdInSameGroup";
}
break;
case FUNID_findObjectByIdInSameSet:
{
sFun = "findObjectByIdInSameSet";
}
break;
case FUNID_findObjectById4Any:
{
sFun = "findObjectById4All";
}
break;
case FUNID_findObjectById:
{
sFun = "findObjectById";
}
break;
case FUNID_findObjectById4All:
{
sFun = "findObjectById4All";
}
break;
case FUNID_findObjectByIdInSameStation:
{
sFun = "findObjectByIdInSameStation";
}
break;
default:
sFun = "UNKNOWN";
break;
}
return sFun;
}

View File

@ -1,119 +0,0 @@

#ifndef __QUERY_IMP_H__
#define __QUERY_IMP_H__
#include "servant/QueryF.h"
#include "DbHandle.h"
using namespace tars;
//////////////////////////////////////////////////////
enum FUNID
{
FUNID_findObjectById = 0,
FUNID_findObjectById4Any = 1,
FUNID_findObjectById4All = 2,
FUNID_findObjectByIdInSameGroup = 3,
FUNID_findObjectByIdInSameStation = 4,
FUNID_findObjectByIdInSameSet = 5
};
//////////////////////////////////////////////////////
/**
*
*/
class QueryImp: public QueryF
{
public:
/**
*
*/
QueryImp(){};
/**
*
*/
virtual void initialize();
/**
** 退
*/
virtual void destroy() {};
/**
* idendpoint
*/
virtual vector<EndpointF> findObjectById(const string & id, tars::CurrentPtr current);
/**
* id,
*/
virtual tars::Int32 findObjectById4Any(const std::string & id, vector<tars::EndpointF> &activeEp, vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current);
/**
* idendpoint
*/
Int32 findObjectById4All(const std::string & id, vector<tars::EndpointF> &activeEp, vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current);
/**
* idendpoint
*/
Int32 findObjectByIdInSameGroup(const std::string & id, vector<tars::EndpointF> &activeEp, vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current);
/**
* idendpoint
*/
Int32 findObjectByIdInSameStation(const std::string & id, const std::string & sStation, vector<tars::EndpointF> &activeEp, vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current);
/**
* idset endpoint
*/
Int32 findObjectByIdInSameSet(const std::string & id,const std::string & setId,vector<tars::EndpointF> &activeEp,vector<tars::EndpointF> &inactiveEp, tars::CurrentPtr current);
/** 查找某个obj部署在哪些节点上 (企业版功能)
*
* @param id obj
* @return: 0- others-
*/
int findObjectNodeName(const string &id, vector<string> &nodeName, CurrentPtr current) { return -1; };
/** 注册数据通知, 同时上报本地缓存数据的最后时间, 如果服务端发现变化则全量推送(企业版功能)
*
* @param timestamp <, >
* @param name
* @return: 0- others-
*/
Int32 registerChange(const map<string, string> &timestamp, const string &name, CurrentPtr current) { return -1; };
/** 注册id变化的通知, 通知时后需要自己主动find(企业版功能)
*
* @param id
* @param name
* @return: 0- others-
*/
Int32 registerQuery(const string &id, const string &name, CurrentPtr current) { return -1; };
/**
* , ()
* @return 0: 1 2 -1
*/
Int32 getLocker(const tars::GetMasterSlaveLock &req, CurrentPtr current) { return -1;};
private:
/**
*
*/
void doDaylog(const FUNID eFnId,const string& id,const vector<tars::EndpointF> &activeEp, const vector<tars::EndpointF> &inactiveEp, const tars::CurrentPtr& current,const std::ostringstream& os,const string& sSetid="");
/**
*
*/
string eFunTostr(const FUNID eFnId);
protected:
//数据库操作
CDbHandle _db;
};
#endif

View File

@ -3,14 +3,14 @@
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 50000
async-invoke-timeout = 60000
#刷新端口时间间隔(毫秒)
refresh-endpoint-interval = 100000
#模块间调用[可选]
stat = TestApp.FrameworkServer.StatObj
stat = tars.tarsmock.StatObj
#发送队列长度
sendqueuelimit = 1000000
#异步回调队列个数限制
@ -95,11 +95,11 @@
local = tcp -h 127.0.0.1 -p 18001 -t 10000
#配置中心的地址[可选]
config = TestApp.FrameworkServer.ConfigObj
config = tars.tarsmock.ConfigObj
#配置中心的地址[可选]
# notify = tars.tarsconfig.NotifyObj
#远程LogServer[可选]
log = TestApp.FrameworkServer.LogObj
log = tars.tarsmock.LogObj
# manuallisten = 1

View File

@ -3,7 +3,7 @@
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 5000
async-invoke-timeout = 60000

View File

@ -3,7 +3,7 @@
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 5000
async-invoke-timeout = 60000

View File

@ -3,7 +3,7 @@
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 5000
async-invoke-timeout = 60000

View File

@ -3,14 +3,14 @@
#proxy需要的配置
<client>
#地址
locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004
locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890
#最大超时时间(毫秒)
sync-invoke-timeout = 15000
async-invoke-timeout = 60000
#刷新端口时间间隔(毫秒)
refresh-endpoint-interval = 100000
#模块间调用[可选]
stat = TestApp.FrameworkServer.StatObj
stat = tars.tarsmock.StatObj
#发送队列长度
sendqueuelimit = 1000000
#异步回调队列个数限制
@ -49,7 +49,7 @@
local = tcp -h 127.0.0.1 -p 15001 -t 10000
#配置中心的地址[可选]
config = TestApp.FrameworkServer.ConfigObj
config = tars.tarsmock.ConfigObj
#配置中心的地址[可选]
# notify = tars.tarsconfig.NotifyObj
#远程LogServer[可选]