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
88a45474
authored
Jun 26, 2018
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add more tests
parent
89ee2b31
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
8 deletions
test/Microservice_ClientTest.cpp
test/Microservice_ClientTest.cpp
View file @
88a45474
...
...
@@ -167,7 +167,7 @@ void pubsubtest(cMicroservice_Client *p_Client) {
// for convenience
using
json
=
nlohmann
::
json
;
static
const
int
ITERATIONS
=
2
;
static
const
int
ITERATIONS
=
10
;
static
const
char
*
const
JSON_CONTENT
=
"{
\n
"
...
...
@@ -513,37 +513,102 @@ void runEvppRequestsTest(){
t
.
Stop
(
true
);
}
void
printObjectDoc
(
rapidjson
::
Document
&
t_ObjectDoc
){
std
::
ostringstream
c_OutputStream
;
if
(
!
t_ObjectDoc
.
IsNull
())
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
t_ObjectDoc
.
Accept
(
writer
);
c_OutputStream
<<
nsMicroservice_Constants
::
SUCCESS_REST_RESPONSE_TEMPLATE
<<
buffer
.
GetString
()
<<
'}'
;
}
else
{
c_OutputStream
<<
nsMicroservice_Constants
::
SUCCESS_NULL_REST_RESPONSE_TEMPLATE
<<
'}'
;
}
std
::
cout
<<
c_OutputStream
.
str
().
c_str
()
<<
std
::
endl
;
}
void
runMSClientEvppTest
(){
std
::
string
body
=
"This is expected to be sent back as part of response body."
;
auto
p_msClient
=
ClientFactory
::
createEvppCommandImpl
(
"evpp-test"
);
std
::
atomic_int
testPassedNumber
(
0
);
std
::
map
<
std
::
string
,
std
::
string
>
headers
;
headers
[
"Content-Type"
]
=
"application/json"
;
//std::string uri = "http://echo.jpillora.com";
std
::
string
uri
=
"https://postman-echo.com"
;
MSCommandParams
msCmndParams
;
msCmndParams
.
WithEntity
(
uri
)
.
With
ParamsString
(
"post
"
)
//.WithRequestParams("q=base"
)
.
With
RequestParams
(
"q=base
"
)
.
WithHeadersMap
(
&
headers
)
.
WithContent
(
body
);
p_msClient
->
AsyncCreate
(
&
msCmndParams
,
[
&
testPassedNumber
](
cMicroservice_BaseRestResponse
*
p_baseRestResponse
){
auto
f
=
[
&
testPassedNumber
](
cMicroservice_BaseRestResponse
*
p_baseRestResponse
){
if
(
p_baseRestResponse
->
IsSuccess
()){
std
::
cout
<<
__PRETTY_FUNCTION__
<<
": Success"
<<
std
::
endl
;
std
::
cout
<<
__PRETTY_FUNCTION__
<<
": Success, Object =>"
<<
std
::
endl
;
printObjectDoc
(
p_baseRestResponse
->
GetObjectNode
());
testPassedNumber
++
;
}
else
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
": Error"
<<
std
::
endl
;
}
testPassedNumber
++
;
});
};
while
(
testPassedNumber
<
1
)
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
msCmndParams
.
WithParamsString
(
"post"
);
p_msClient
->
AsyncCreate
(
&
msCmndParams
,
f
);
msCmndParams
.
WithParamsString
(
"get"
);
p_msClient
->
AsyncRead
(
&
msCmndParams
,
f
);
msCmndParams
.
WithParamsString
(
"put"
);
p_msClient
->
AsyncUpdate
(
&
msCmndParams
,
f
);
msCmndParams
.
WithParamsString
(
"delete"
);
p_msClient
->
AsyncDelete
(
&
msCmndParams
,
f
);
}
while
(
testPassedNumber
<
4
*
ITERATIONS
)
{
usleep
(
1
);
}
}
static
int
responsed
=
0
;
static
void
HandleHTTPResponse
(
const
std
::
shared_ptr
<
evpp
::
httpc
::
EvppResponse
>&
response
,
evpp
::
httpc
::
PostEvppRequest
*
request
)
{
LOG_INFO
<<
"http_code="
<<
response
->
http_code
()
<<
" URL=http://"
<<
request
->
host
()
<<
request
->
uri
()
<<
" BODY = ["
<<
response
->
body
().
ToString
()
<<
"]"
;
const
char
*
header
=
response
->
FindHeader
(
"Connection"
);
if
(
header
)
{
LOG_INFO
<<
"HTTP HEADER Connection="
<<
header
;
}
responsed
++
;
assert
(
request
==
response
->
request
());
delete
request
;
// The request MUST BE deleted in EventLoop thread.
}
void
test_evpp
(){
evpp
::
EventLoopThread
t
;
string
url
=
"https://postman-echo.com/post"
;
t
.
Start
(
true
);
evpp
::
httpc
::
PostEvppRequest
*
r
=
new
evpp
::
httpc
::
PostEvppRequest
(
t
.
loop
(),
url
,
evpp
::
Duration
(
3.0
));
r
->
Execute
(
std
::
bind
(
&
HandleHTTPResponse
,
std
::
placeholders
::
_1
,
r
));
r
=
new
evpp
::
httpc
::
PostEvppRequest
(
t
.
loop
(),
url
,
evpp
::
Duration
(
3.0
));
r
->
Execute
(
std
::
bind
(
&
HandleHTTPResponse
,
std
::
placeholders
::
_1
,
r
));
r
=
new
evpp
::
httpc
::
PostEvppRequest
(
t
.
loop
(),
url
,
evpp
::
Duration
(
3.0
));
r
->
Execute
(
std
::
bind
(
&
HandleHTTPResponse
,
std
::
placeholders
::
_1
,
r
));
r
=
new
evpp
::
httpc
::
PostEvppRequest
(
t
.
loop
(),
url
,
evpp
::
Duration
(
3.0
));
r
->
Execute
(
std
::
bind
(
&
HandleHTTPResponse
,
std
::
placeholders
::
_1
,
r
));
while
(
responsed
!=
4
)
{
usleep
(
1
);
}
t
.
Stop
(
true
);
LOG_INFO
<<
"EventLoopThread stopped."
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
//auto duration = CommonUtils::measureFunc<>(runEvppRequestsTest);
auto
duration
=
CommonUtils
::
measureFunc
<>
(
runMSClientEvppTest
);
// auto duration = CommonUtils::measureFunc<>(test_evpp);
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with map serialization json took: "
<<
duration
<<
"msec"
<<
'\n'
;
//runRestZmqTest();
...
...
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