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
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
59 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
...
@@ -57,8 +57,8 @@ add_executable(test_MicroserviceClient test/Microservice_ClientTest.cpp) #EXCLUD
target_link_libraries
(
test_MicroserviceClient Microservice
)
target_link_libraries
(
test_MicroserviceClient Microservice
)
# test_ZMQ
# test_ZMQ
add_executable
(
test_ZMQ test/Microservice_ZMQTest.cpp
)
#EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
#
add_executable(test_ZMQ test/Microservice_ZMQTest.cpp) #EXCLUDE_FROM_ALL ${Microservice_TEST_SOURCES})
target_link_libraries
(
test_ZMQ Microservice
)
#
target_link_libraries (test_ZMQ Microservice)
# install part
# install part
#set (CMAKE_INSTALL_PREFIX ../internals)
#set (CMAKE_INSTALL_PREFIX ../internals)
...
...
doc/todo.txt
View file @
918261ae
- memory leak on performance testing of SendZmqRestRequests
- 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());
});
- upon receiving the response , forward it to a new task to be carried by another thread
- 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";
...
@@ -29,13 +29,14 @@ static const char *const PUBSUBHOST = "zmqpubsub";
using
namespace
std
;
using
namespace
std
;
void
pubsubtest
(
cMicroservice_Client
*
p_Client
);
void
pubsubtest
(
cMicroservice_Client
*
p_Client
);
void
performance
(
cMicroservice_Client
*
p_Client
);
void
performance
(
cMicroservice_Client
*
p_Client
);
void
testRapidJson
();
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
()
void
runTest
()
{
{
...
@@ -335,6 +336,8 @@ void runRestZmqTest(){
...
@@ -335,6 +336,8 @@ void runRestZmqTest(){
std
::
string
appName
(
"myZmqService"
);
std
::
string
appName
(
"myZmqService"
);
Microservice_App
msApp
(
appName
.
c_str
());
Microservice_App
msApp
(
appName
.
c_str
());
/**
/**
* Start server
* Start server
*/
*/
...
@@ -343,11 +346,17 @@ void runRestZmqTest(){
...
@@ -343,11 +346,17 @@ void runRestZmqTest(){
.
withMonitoring
()
// need to add reload
.
withMonitoring
()
// need to add reload
.
withPubSub
(
NULL
)
.
withPubSub
(
NULL
)
.
withServiceDiscovery
(
NULL
)
.
withServiceDiscovery
(
NULL
)
.
addClient
(
ClientFactory
::
createZmqCommandImpl
(
appName
,
"clientApp"
,
0
,
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerCivetWebImpl
(
""
,
50010
,
1
))
.
addServer
(
ServerFactory
::
createIRestServerCivetWebImpl
(
""
,
50010
,
1
))
.
addServer
(
ServerFactory
::
createIRestServerZmqImpl
(
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerZmqImpl
(
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addTest
(
"SendZmqRestRequests"
,
[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
.
addTest
(
"SendZmqRestRequests"
,
[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
auto
p_zmqClient
=
ClientFactory
::
createZmqCommandImpl
(
appName
,
"clientApp"
,
0
,
"serverApp"
,
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
);
auto
p_zmqClient
=
msApp
.
GetMSClient
(
appName
);
output
<<
" Testing "
<<
ITERATIONS
<<
" SendZmqRestRequests took: "
<<
CommonUtils
::
measureFunc
<>
(
SendZmqRestRequests
,
msApp
,
p_zmqClient
)
<<
"msec"
<<
'\n'
;
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
();
return
MSRetStat
();
})
})
.
addTest
(
"testCaches"
,[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
.
addTest
(
"testCaches"
,[
&
msApp
,
&
appName
](
std
::
stringstream
&
output
,
DequeStringMap
&
queryParams
)
->
MSRetStat
{
...
@@ -366,9 +375,9 @@ void runRestZmqTest(){
...
@@ -366,9 +375,9 @@ void runRestZmqTest(){
getchar
();
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
();
auto
p_logger
=
msApp
.
GetLogger
();
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
ClientAsyncTaskParamsPtr
clientAsyncTaskParamsPtr
=
ClientAsyncTaskParamsPtr
clientAsyncTaskParamsPtr
=
ClientAsyncTaskParamsFactory
::
CreateCommndParamsAsyncTask
(
nullptr
,
nullptr
);
ClientAsyncTaskParamsFactory
::
CreateCommndParamsAsyncTask
(
nullptr
,
nullptr
);
clientAsyncTaskParamsPtr
->
p_command_params_
->
WithEntity
(
""
)
clientAsyncTaskParamsPtr
->
p_command_params_
->
WithEntity
(
""
)
...
@@ -386,11 +395,6 @@ void SendZmqRestRequests(const Microservice_App &msApp, cMicroservice_Client *p_
...
@@ -386,11 +395,6 @@ void SendZmqRestRequests(const Microservice_App &msApp, cMicroservice_Client *p_
if
(
i
!=
p_rr
->
getCommandId
())
if
(
i
!=
p_rr
->
getCommandId
())
cerr
<<
"CommandId mismatch"
<<
endl
;
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
{
else
{
p_logger
->
error
(
"%s, failed on %s, Cmnd Id: %u"
,
__PRETTY_FUNCTION__
,
retStat
.
GetError
().
c_str
(),
i
);
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 @@
...
@@ -26,6 +26,7 @@
#include <common/Microservice_RestResponse.h>
#include <common/Microservice_RestResponse.h>
#include <utils/ServerFactory.h>
#include <utils/ServerFactory.h>
#include <utils/ClientFactory.h>
#include <utils/ClientFactory.h>
#include "Microservice_ZMQTest.cpp"
static
const
char
*
const
START
=
"Start"
;
static
const
char
*
const
START
=
"Start"
;
static
const
char
*
const
STOP
=
"Stop"
;
static
const
char
*
const
STOP
=
"Stop"
;
...
@@ -288,30 +289,8 @@ public:
...
@@ -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
(){
void
testCache
(){
using
CacheClient
=
nsMicroservice_Iface
::
ICacheClient
;
using
CacheClient
=
nsMicroservice_Iface
::
ICacheClient
<
std
::
string
,
std
::
string
>
;
using
Str
=
std
::
string
;
using
Str
=
std
::
string
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
retKeyValue
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
retKeyValue
;
Str
key
=
"keytest"
;
Str
key
=
"keytest"
;
...
@@ -385,18 +364,23 @@ void test_timers()
...
@@ -385,18 +364,23 @@ void test_timers()
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
// testCache();
cMicroservice_BaseClientParams
clientParams
(
"other-service"
,
true
,
10
,
false
,
"localhost"
,
32010
,
"localhost:6379"
);
//TO to2 = testDocs();
zmqtest
::
TestZMQ
testZMQ
;
// test_timers();
runNewMS
();
if
(
argc
<
6
)
{
printf
(
"Usage: Test_Microservice app-name host port handler-prefix get-returned-string
\n
"
);
return
0
;
}
//runOldMS(argv);
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
This diff is collapsed.
Click to expand it.
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