Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.cpp
/
Microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
918261ae
authored
Apr 20, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add test_zmq as a test class for microservice_test app
parent
e2f193f6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
145 deletions
CMakeLists.txt
doc/todo.txt
test/Microservice_ClientTest.cpp
test/Microservice_Test.cpp
test/Microservice_ZMQTest.cpp
CMakeLists.txt
View file @
918261ae
...
...
@@ -57,8 +57,8 @@ add_executable(test_MicroserviceClient test/Microservice_ClientTest.cpp) #EXCLUD
target_link_libraries
(
test_MicroserviceClient Microservice
)
# test_ZMQ
add_executable
(
test_ZMQ test/Microservice_ZMQTest.cpp
)
#EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
target_link_libraries
(
test_ZMQ Microservice
)
#
add_executable(test_ZMQ test/Microservice_ZMQTest.cpp) #EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
#
target_link_libraries (test_ZMQ Microservice)
# install part
#set (CMAKE_INSTALL_PREFIX ../internals)
...
...
doc/todo.txt
View file @
918261ae
- client->createAsync(asyncTaskParams,[asyncTaskParams](MSRetstat retstat) {
if (retStat.IsSuccess())
clientAsyncTaskParamsPtr->p_IContainer_->WriteObjectToResponse(
clientAsyncTaskParamsPtr->p_IResponse_.get(),
*clientAsyncTaskParamsPtr->p_baseRestResoonse_);
else
clientAsyncTaskParamsPtr->p_IContainer_->SendErrorResp(clientAsyncTaskParamsPtr->p_IResponse_.get(),
retStat.GetError());
});
- memory leak on performance testing of SendZmqRestRequests
- upon receiving the response , forward it to a new task to be carried by another thread
\ No newline at end of file
test/Microservice_ClientTest.cpp
View file @
918261ae
...
...
@@ -29,13 +29,14 @@ static const char *const PUBSUBHOST = "zmqpubsub";
using
namespace
std
;
void
pubsubtest
(
cMicroservice_Client
*
p_Client
);
void
performance
(
cMicroservice_Client
*
p_Client
);
void
testRapidJson
();
void
SendZmqRestRequests
(
const
Microservice_App
&
msApp
,
cMicroservice_Client
*
p_zmqClient
);
void
SendZmqRestRequests
(
const
Microservice_App
&
msApp
,
cMicroservice_Client
*
p_zmqClient
,
int
iterations
);
void
runTest
()
{
...
...
@@ -335,6 +336,8 @@ void runRestZmqTest(){
std
::
string
appName
(
"myZmqService"
);
Microservice_App
msApp
(
appName
.
c_str
());
/**
* Start server
*/
...
...
@@ -343,11 +346,17 @@ void runRestZmqTest(){
.
withMonitoring
()
// need to add reload
.
withPubSub
(
NULL
)
.
withServiceDiscovery
(
NULL
)
.
addClient
(
ClientFactory
::
createZmqCommandImpl
(
appName
,
"clientApp"
,
0
,
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerCivetWebImpl
(
""
,
50010
,
1
))
.
addServer
(
ServerFactory
::
createIRestServerZmqImpl
(
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addTest
(
"SendZmqRestRequests"
,
[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
auto
p_zmqClient
=
ClientFactory
::
createZmqCommandImpl
(
appName
,
"clientApp"
,
0
,
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
);
output
<<
" Testing "
<<
ITERATIONS
<<
" SendZmqRestRequests took: "
<<
CommonUtils
::
measureFunc
<>
(
SendZmqRestRequests
,
msApp
,
p_zmqClient
)
<<
"msec"
<<
'\n'
;
auto
p_zmqClient
=
msApp
.
GetMSClient
(
appName
);
int
iterations
=
ITERATIONS
;
auto
iterator
=
queryParams
.
find
(
"iterations"
);
if
(
iterator
!=
queryParams
.
end
()){
iterations
=
std
::
atoi
(
iterator
->
second
.
begin
()
->
c_str
());
}
output
<<
" Testing "
<<
iterations
<<
" iterations in SendZmqRestRequests took: "
<<
CommonUtils
::
measureFunc
<>
(
SendZmqRestRequests
,
msApp
,
p_zmqClient
,
iterations
)
<<
"msec"
<<
'\n'
;
return
MSRetStat
();
})
.
addTest
(
"testCaches"
,[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
...
...
@@ -366,9 +375,9 @@ void runRestZmqTest(){
getchar
();
}
void
SendZmqRestRequests
(
const
Microservice_App
&
msApp
,
cMicroservice_Client
*
p_zmqClient
)
{
void
SendZmqRestRequests
(
const
Microservice_App
&
msApp
,
cMicroservice_Client
*
p_zmqClient
,
int
iterations
)
{
auto
p_logger
=
msApp
.
GetLogger
();
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
ClientAsyncTaskParamsPtr
clientAsyncTaskParamsPtr
=
ClientAsyncTaskParamsFactory
::
CreateCommndParamsAsyncTask
(
nullptr
,
nullptr
);
clientAsyncTaskParamsPtr
->
p_command_params_
->
WithEntity
(
""
)
...
...
@@ -386,11 +395,6 @@ void SendZmqRestRequests(const Microservice_App &msApp, cMicroservice_Client *p_
if
(
i
!=
p_rr
->
getCommandId
())
cerr
<<
"CommandId mismatch"
<<
endl
;
//}
// rapidjson::StringBuffer buffer;
// rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
// clientAsyncTaskParamsPtr->p_baseRestResoonse_->GetObjectNode().Accept(writer);
// p_logger->info("SUCCESS: Response: %s",buffer.GetString());
}
else
{
p_logger
->
error
(
"%s, failed on %s, Cmnd Id: %u"
,
__PRETTY_FUNCTION__
,
retStat
.
GetError
().
c_str
(),
i
);
...
...
test/Microservice_Test.cpp
View file @
918261ae
...
...
@@ -26,6 +26,7 @@
#include <common/Microservice_RestResponse.h>
#include <utils/ServerFactory.h>
#include <utils/ClientFactory.h>
#include "Microservice_ZMQTest.cpp"
static
const
char
*
const
START
=
"Start"
;
static
const
char
*
const
STOP
=
"Stop"
;
...
...
@@ -288,30 +289,8 @@ public:
};
void
runNewMS
(){
cMicroservice_BaseClientParams
clientParams
(
"other-service"
,
true
,
10
,
false
,
"localhost"
,
32010
,
"localhost:6379"
);
Microservice_App
msApp
(
"myCppService"
);
msApp
.
withMetrics
()
.
withMonitoring
()
// need to add reload
.
withPubSub
(
NULL
)
.
withServiceDiscovery
(
NULL
)
.
addClient
(
ClientFactory
::
createHttpImplMsClient
(
"other-service"
,
"localhost"
,
32010
,
true
,
10
,
false
,
"localhost:6379"
))
//new cMicroservice_Client(new MSICommandClientHttpImpl(),&clientParams))
.
addClient
(
ClientFactory
::
createZmqMsgQImp
(
"zmq-service"
,
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerCivetWebImpl
(
""
,
50010
,
1
))
// .addRestServer(new cMicroservice_IRestServerCivetWebImpl(new cMicroservice_RestServerParams(50010,"",1)))
.
addServer
(
ServerFactory
::
createIMsgQueueServerZmqImpl
(
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addHandler
(
"/xxx"
,(
Microservice_RestHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
.
build
()
.
run
();
}
void
testCache
(){
using
CacheClient
=
nsMicroservice_Iface
::
ICacheClient
;
using
CacheClient
=
nsMicroservice_Iface
::
ICacheClient
<
std
::
string
,
std
::
string
>
;
using
Str
=
std
::
string
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
retKeyValue
;
Str
key
=
"keytest"
;
...
...
@@ -385,18 +364,23 @@ void test_timers()
int
main
(
int
argc
,
char
*
argv
[])
{
// testCache();
//TO to2 = testDocs();
// test_timers();
runNewMS
();
if
(
argc
<
6
)
{
printf
(
"Usage: Test_Microservice app-name host port handler-prefix get-returned-string
\n
"
);
return
0
;
}
//runOldMS(argv);
cMicroservice_BaseClientParams
clientParams
(
"other-service"
,
true
,
10
,
false
,
"localhost"
,
32010
,
"localhost:6379"
);
zmqtest
::
TestZMQ
testZMQ
;
Microservice_App
msApp
(
"myCppService"
);
msApp
.
withMetrics
()
.
withMonitoring
()
// need to add reload
.
withPubSub
(
NULL
)
.
withServiceDiscovery
(
NULL
)
.
addClient
(
ClientFactory
::
createHttpImplMsClient
(
"other-service"
,
"localhost"
,
32010
,
true
,
10
,
false
,
"localhost:6379"
))
//new cMicroservice_Client(new MSICommandClientHttpImpl(),&clientParams))
.
addClient
(
ClientFactory
::
createZmqMsgQImp
(
"zmq-service"
,
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerCivetWebImpl
(
""
,
50010
,
1
))
// .addRestServer(new cMicroservice_IRestServerCivetWebImpl(new cMicroservice_RestServerParams(50010,"",1)))
.
addServer
(
ServerFactory
::
createIMsgQueueServerZmqImpl
(
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addHandler
(
"/xxx"
,(
Microservice_RestHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
.
addTest
(
&
testZMQ
)
.
build
()
.
run
();
}
test/Microservice_ZMQTest.cpp
View file @
918261ae
...
...
@@ -13,12 +13,13 @@
#include <common/RestMsg_generated.h>
#include <common/RestResponse_generated.h>
static
const
char
*
const
IPC_FILE1
=
"/tmp/service-name1.ipc"
;
static
const
char
*
const
IPC_FILE2
=
"/tmp/service-name2.ipc"
;
namespace
zmqtest
{
static
const
char
*
const
IPC_FILE1
=
"/tmp/service-name1.ipc"
;
static
const
char
*
const
IPC_FILE2
=
"/tmp/service-name2.ipc"
;
static
const
int
ITERATIONS
=
1000000
;
static
const
char
*
const
JSON_CONTENT
=
"{
\n
"
static
const
int
ITERATIONS
=
1000000
;
static
const
char
*
const
JSON_CONTENT
=
"{
\n
"
"
\"
success
\"
: true,
\n
"
"
\"
error
\"
: null,
\n
"
"
\"
objectNode
\"
: {
\n
"
...
...
@@ -57,80 +58,66 @@ static const char *const JSON_CONTENT = "{\n"
" }
\n
"
"}"
;
static
const
char
*
const
SOURCE_CHANNEL
=
"ipc:///tmp/some-file.ipc"
;
static
const
char
*
const
SOURCE_CHANNEL
=
"ipc:///tmp/some-file.ipc"
;
static
const
char
*
const
URI
=
"/xxx/resource/subResource"
;
static
const
char
*
const
URI
=
"/xxx/resource/subResource"
;
static
const
char
*
const
QUERY_STRING
=
"a=b&c=d&abba=sabba"
;
static
const
char
*
const
QUERY_STRING
=
"a=b&c=d&abba=sabba"
;
static
const
char
*
const
EXIT_MSG
=
"exit"
;
static
const
int
EXIT_MSG_LEN
=
std
::
strlen
(
EXIT_MSG
);
static
const
char
*
const
EXIT_MSG
=
"exit"
;
static
const
int
EXIT_MSG_LEN
=
std
::
strlen
(
EXIT_MSG
);
void
test_msgQ
();
void
test_Cereal
()
{
Microservice_MsgQContext
msgQContext
,
msgQContext1
;
void
test_Cereal
(
int
iterations
)
{
Microservice_MsgQContext
msgQContext
,
msgQContext1
;
msgQContext
.
header_
=
"head"
;
msgQContext
.
msg_
=
"msg"
;
//"{\\\"name\\\":\\\"amir\\\",\\\"error\\\":\\\"no error\\\",\\\"objectNode\\\":\\\"text\\\"}}";
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
std
::
stringstream
ss
;
{
cereal
::
JSONOutputArchive
jsonOutputArchive
(
ss
);
jsonOutputArchive
(
msgQContext
);
}
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
//
std::cout << ss.str() << std::endl;
{
cereal
::
JSONInputArchive
jsonInputArchive
(
ss
);
jsonInputArchive
(
msgQContext1
);
}
}
}
}
void
test_MsgQueue
(
zmqpp
::
context
*
p_context
)
{
const
char
*
ipcfile
=
IPC_FILE1
;
void
test_MsgQueue
(
zmqpp
::
context
*
p_context
)
{
const
char
*
ipcfile
=
IPC_FILE1
;
std
::
fopen
(
ipcfile
,
"a"
);
//zmqpp::context context;
// create and bind a server socket
std
::
string
ipcAddress
=
std
::
string
(
"ipc://"
).
append
(
ipcfile
);
zmqpp
::
socket
server
(
*
p_context
,
zmqpp
::
socket_type
::
pull
);
zmqpp
::
socket
server
(
*
p_context
,
zmqpp
::
socket_type
::
pull
);
//server.bind("tcp://*:9000");
server
.
bind
(
ipcAddress
);
server
.
bind
(
"inproc://maint"
);
bool
keepRunning
=
true
;
while
(
keepRunning
)
{
// create and connect a client socket
// zmqpp::socket client (context, zmqpp::socket_type::push);
// client.connect("tcp://127.0.0.1:9000");
//
// // Send a single message from server to client
// zmqpp::message request;
// request << "Hello";
// client.send(request);
while
(
keepRunning
)
{
zmqpp
::
message
response
;
server
.
receive
(
response
);
auto
msg
=
response
.
get
(
0
);
//assert("Hello" == response.get(0));
std
::
cout
<<
msg
<<
std
::
endl
;
//
std::cout << msg << std::endl;
if
(
msg
.
compare
(
EXIT_MSG
)
==
0
)
keepRunning
=
false
;
}
}
}
void
testRequestResponse
(
zmqpp
::
context
&
context
)
{
const
char
*
ipcFile1
=
IPC_FILE1
;
void
testRequestResponse
(
zmqpp
::
context
&
context
,
int
iterations
)
{
const
char
*
ipcFile1
=
IPC_FILE1
;
std
::
fopen
(
ipcFile1
,
"a"
);
const
char
*
ipcFile2
=
IPC_FILE2
;
const
char
*
ipcFile2
=
IPC_FILE2
;
std
::
fopen
(
ipcFile2
,
"a"
);
//zmqpp::context context;
...
...
@@ -138,10 +125,10 @@ void testRequestResponse(zmqpp::context &context)
// create and bind a serverReceive socket
std
::
string
ipcAddress1
=
std
::
string
(
"ipc://"
).
append
(
ipcFile1
);
std
::
string
ipcAddress2
=
std
::
string
(
"ipc://"
).
append
(
ipcFile2
);
zmqpp
::
socket
clientSend
(
context
,
zmqpp
::
socket_type
::
push
);
zmqpp
::
socket
serverReceive
(
context
,
zmqpp
::
socket_type
::
pull
);
zmqpp
::
socket
clientReceive
(
context
,
zmqpp
::
socket_type
::
pull
);
zmqpp
::
socket
serverReply
(
context
,
zmqpp
::
socket_type
::
push
);
zmqpp
::
socket
clientSend
(
context
,
zmqpp
::
socket_type
::
push
);
zmqpp
::
socket
serverReceive
(
context
,
zmqpp
::
socket_type
::
pull
);
zmqpp
::
socket
clientReceive
(
context
,
zmqpp
::
socket_type
::
pull
);
zmqpp
::
socket
serverReply
(
context
,
zmqpp
::
socket_type
::
push
);
clientSend
.
connect
(
ipcAddress1
);
clientReceive
.
bind
(
ipcAddress2
);
...
...
@@ -149,33 +136,34 @@ void testRequestResponse(zmqpp::context &context)
serverReply
.
connect
(
ipcAddress2
);
int
maxSize
=
10000
;
serverReceive
.
set
(
zmqpp
::
socket_option
::
receive_high_water_mark
,
maxSize
);
serverReply
.
set
(
zmqpp
::
socket_option
::
send_high_water_mark
,
maxSize
);
clientReceive
.
set
(
zmqpp
::
socket_option
::
receive_high_water_mark
,
maxSize
);
clientSend
.
set
(
zmqpp
::
socket_option
::
send_high_water_mark
,
maxSize
);
serverReceive
.
set
(
zmqpp
::
socket_option
::
receive_high_water_mark
,
maxSize
);
serverReply
.
set
(
zmqpp
::
socket_option
::
send_high_water_mark
,
maxSize
);
clientReceive
.
set
(
zmqpp
::
socket_option
::
receive_high_water_mark
,
maxSize
);
clientSend
.
set
(
zmqpp
::
socket_option
::
send_high_water_mark
,
maxSize
);
// serverReceive.set(zmqpp::socket_option::max_messsage_size,maxSize);
// serverReply.set(zmqpp::socket_option::max_messsage_size,maxSize);
// clientReceive.set(zmqpp::socket_option::max_messsage_size,maxSize);
// clientSend.set(zmqpp::socket_option::max_messsage_size,maxSize);
auto
p_serverThread
=
new
std
::
thread
(
std
::
bind
([
&
serverReceive
,
&
serverReply
]()
{
auto
p_serverThread
=
new
std
::
thread
(
std
::
bind
([
&
serverReceive
,
&
serverReply
]()
{
bool
keepRunning
=
true
;
flatbuffers
::
FlatBufferBuilder
requestBuilder
(
1024
);
flatbuffers
::
FlatBufferBuilder
respBuilder
(
1024
);
common
::
context
::
RestMsgBuilder
restMsgBuilder
(
requestBuilder
);
while
(
keepRunning
)
{
while
(
keepRunning
)
{
zmqpp
::
message
response
;
serverReceive
.
receive
(
response
);
if
(
response
.
size
(
0
)
>
EXIT_MSG_LEN
)
{
if
(
response
.
size
(
0
)
>
EXIT_MSG_LEN
)
{
respBuilder
.
Clear
();
auto
receiveMsg
=
common
::
context
::
GetRestMsg
(
response
.
raw_data
(
0
));
auto
rcid
=
receiveMsg
->
rcid
();
auto
restResponse
=
common
::
context
::
CreateRestResponseDirect
(
respBuilder
,
rcid
,
receiveMsg
->
content
()
->
c_str
());
auto
restResponse
=
common
::
context
::
CreateRestResponseDirect
(
respBuilder
,
rcid
,
receiveMsg
->
content
()
->
c_str
());
respBuilder
.
Finish
(
restResponse
);
serverReply
.
send_raw
((
const
char
*
)
respBuilder
.
GetBufferPointer
(),
respBuilder
.
GetSize
(),
zmqpp
::
socket
::
dont_wait
);
serverReply
.
send_raw
((
const
char
*
)
respBuilder
.
GetBufferPointer
(),
respBuilder
.
GetSize
(),
zmqpp
::
socket
::
dont_wait
);
// std::cout << receiveMsg->source()->c_str() << std::endl;
}
else
{
}
else
{
auto
msg
=
response
.
get
(
0
);
//std::cout << "Server Received Msg: " << msg << std::endl;
...
...
@@ -192,20 +180,19 @@ void testRequestResponse(zmqpp::context &context)
//std::cout << "Server exit.." << std::endl;
}));
auto
p_clientReceiveThread_
=
new
std
::
thread
(
std
::
bind
([
&
clientReceive
]()
{
auto
p_clientReceiveThread_
=
new
std
::
thread
(
std
::
bind
([
&
clientReceive
]()
{
bool
keepRunning
=
true
;
int
lastNumber
;
uint64_t
rcid
=
0
;
//flatbuffers::FlatBufferBuilder respBuilder(1024);
while
(
keepRunning
)
{
while
(
keepRunning
)
{
zmqpp
::
message
response
;
clientReceive
.
receive
(
response
);
if
(
response
.
size
(
0
)
>
EXIT_MSG_LEN
)
{
if
(
response
.
size
(
0
)
>
EXIT_MSG_LEN
)
{
auto
receiveMsg
=
common
::
context
::
GetRestResponse
(
response
.
raw_data
(
0
));
rcid
=
receiveMsg
->
rcid
();
//std::cout << "Client Received Msg: " << receiveMsg->objectNode()->c_str() << std::endl;
}
else
{
}
else
{
auto
msg
=
response
.
get
(
0
);
//std::cout << "Client Received Msg: " << msg << std::endl;
if
(
msg
.
compare
(
EXIT_MSG
)
==
0
)
...
...
@@ -221,12 +208,14 @@ void testRequestResponse(zmqpp::context &context)
// Send a single message from serverReceive to clientSend
int
size
;
flatbuffers
::
FlatBufferBuilder
builder
(
1024
);
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
builder
.
Clear
();
auto
restMsg
=
common
::
context
::
CreateRestMsgDirect
(
builder
,
i
,
SOURCE_CHANNEL
,
common
::
context
::
CrudMethod_Create
,
URI
,
QUERY_STRING
,
JSON_CONTENT
);
auto
restMsg
=
common
::
context
::
CreateRestMsgDirect
(
builder
,
i
,
SOURCE_CHANNEL
,
common
::
context
::
CrudMethod_Create
,
URI
,
QUERY_STRING
,
JSON_CONTENT
);
builder
.
Finish
(
restMsg
);
//std::cout << builder.GetSize() << std::endl;
clientSend
.
send_raw
((
const
char
*
)
builder
.
GetBufferPointer
(),
builder
.
GetSize
(),
zmqpp
::
socket
::
dont_wait
);
clientSend
.
send_raw
((
const
char
*
)
builder
.
GetBufferPointer
(),
builder
.
GetSize
(),
zmqpp
::
socket
::
dont_wait
);
}
zmqpp
::
message
request
;
request
<<
EXIT_MSG
;
...
...
@@ -237,22 +226,29 @@ void testRequestResponse(zmqpp::context &context)
// std::cout << "Server exited" << std::endl;
p_clientReceiveThread_
->
join
();
// std::cout << "Client exited" << std::endl;
}
}
void
test_msgQ
(
zmqpp
::
context
&
context
)
{
void
test_msgQ
(
zmqpp
::
context
&
context
,
int
iterations
)
{
auto
thr
=
new
std
::
thread
(
test_MsgQueue
,
&
context
);
//test_MsgQueue();
// create and bind a server socket
zmqpp
::
socket
client
(
context
,
zmqpp
::
socket_type
::
push
);
zmqpp
::
socket
client
(
context
,
zmqpp
::
socket_type
::
push
);
//server.bind("tcp://*:9000");
client
.
connect
(
"inproc://maint"
);
for
(
int
i
=
0
;
i
<
iterations
;
i
++
){
zmqpp
::
message
exitmsg
;
exitmsg
<<
JSON_CONTENT
<<
i
;
client
.
send
(
exitmsg
);
}
zmqpp
::
message
exitmsg
;
exitmsg
<<
EXIT_MSG
;
client
.
send
(
exitmsg
);
}
thr
->
join
();
void
test_pubsub
(
zmqpp
::
context
&
context
)
{
}
void
test_pubsub
(
zmqpp
::
context
&
context
)
{
std
::
string
ipcAddress
=
std
::
string
(
"ipc://"
).
append
(
IPC_FILE1
);
zmqpp
::
socket
pub
(
context
,
zmqpp
::
socket_type
::
pub
);
...
...
@@ -262,7 +258,7 @@ void test_pubsub(zmqpp::context &context) {
sub2
.
subscribe
(
"hello"
);
auto
thr
=
new
std
::
thread
(
std
::
bind
([
&
context
,
&
ipcAddress
,
&
sub2
]()
{
auto
thr
=
new
std
::
thread
(
std
::
bind
([
&
context
,
&
ipcAddress
,
&
sub2
]()
{
zmqpp
::
socket
sub
(
context
,
zmqpp
::
socket_type
::
sub
);
sub
.
connect
(
ipcAddress
);
sub
.
subscribe
(
"hello"
);
...
...
@@ -272,15 +268,14 @@ void test_pubsub(zmqpp::context &context) {
poller
.
add
(
sub
);
poller
.
add
(
sub2
);
while
(
poller
.
poll
())
{
if
(
poller
.
has_input
(
sub
)){
while
(
poller
.
poll
())
{
if
(
poller
.
has_input
(
sub
))
{
std
::
string
message
;
sub
.
receive
(
message
);
std
::
cout
<<
"recieved on sub: "
<<
message
<<
'\n'
;
sub
.
unsubscribe
(
"hello"
);
}
if
(
poller
.
has_input
(
sub2
))
{
if
(
poller
.
has_input
(
sub2
))
{
std
::
string
message
;
sub2
.
receive
(
message
);
std
::
cout
<<
"recieved on sub2: "
<<
message
<<
'\n'
;
...
...
@@ -292,7 +287,7 @@ void test_pubsub(zmqpp::context &context) {
pub
.
send
(
"hello"
,
zmqpp
::
socket
::
send_more
);
pub
.
send
(
"hello world!"
);
std
::
cout
<<
"enter message: "
;
while
(
true
)
{
while
(
true
)
{
std
::
cin
>>
input
;
if
(
input
.
compare
(
EXIT_MSG
)
==
0
)
break
;
...
...
@@ -300,21 +295,53 @@ void test_pubsub(zmqpp::context &context) {
sub2
.
subscribe
(
input
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
zmqpp
::
context
context
;
// std::cout << "testing of " << ITERATIONS << " iterations took: " << measure<>::execution(testRequestResponse,context) << " msec" << std::endl;
std
::
cout
<<
"testing of "
<<
ITERATIONS
<<
" iterations took: "
<<
CommonUtils
::
measureFunc
<>
(
testRequestResponse
,
context
)
<<
" msec"
<<
std
::
endl
;
//testRequestResponse(context);
//test_pubsub(context);
//test_Cereal();
//test_msgQ(context);
}
getchar
();
class
TestZMQ
:
public
nsMicroservice_Iface
::
ITest
{
private
:
zmqpp
::
context
context_
;
int
getIterations
(
DequeStringMap
&
queryParams
){
int
iterations
=
ITERATIONS
;
auto
iterator
=
queryParams
.
find
(
"iterations"
);
if
(
iterator
!=
queryParams
.
end
()){
iterations
=
std
::
atoi
(
iterator
->
second
.
begin
()
->
c_str
());
}
return
iterations
;
}
public
:
virtual
void
getAllTests
(
TestsMap
&
testsMap
)
override
{
testsMap
[
"testRequestResponsePerformance"
]
=
[
this
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
int
iterations
=
getIterations
(
queryParams
);
output
<<
"testing of "
<<
iterations
<<
" iterations took: "
<<
CommonUtils
::
measureFunc
<>
(
testRequestResponse
,
context_
,
iterations
)
<<
" msec"
;
return
MSRetStat
();
};
testsMap
[
"testMsgQPerformance"
]
=
[
this
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
int
iterations
=
getIterations
(
queryParams
);
output
<<
"testing of "
<<
iterations
<<
" iterations took: "
<<
CommonUtils
::
measureFunc
<>
(
test_msgQ
,
context_
,
iterations
)
<<
" msec"
;
return
MSRetStat
();
};
testsMap
[
"testCerealPerformance"
]
=
[
this
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
int
iterations
=
getIterations
(
queryParams
);
output
<<
"testing of "
<<
iterations
<<
" iterations took: "
<<
CommonUtils
::
measureFunc
<>
(
test_Cereal
,
iterations
)
<<
" msec"
;
return
MSRetStat
();
};
}
};
}
//
//int main(int argc, char *argv[]) {
//
// zmqpp::context context;
//// std::cout << "testing of " << ITERATIONS << " iterations took: " << measure<>::execution(testRequestResponse,context) << " msec" << std::endl;
// std::cout << "testing of " << ITERATIONS << " iterations took: " << CommonUtils::measureFunc<>(testRequestResponse,context) << " msec" << std::endl;
//
// //testRequestResponse(context);
// //test_pubsub(context);
// //test_Cereal();
// //test_msgQ(context);
//
// getchar();
//
//}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment