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
8468cd1b
authored
Jun 26, 2018
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
testing Evpp client and server async
parent
88a45474
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
4 deletions
src/Microservice_Client.h
src/impl/servers/Microservice_IRestServerEvppImpl.h
test/Microservice_Test.cpp
src/Microservice_Client.h
View file @
8468cd1b
...
@@ -89,6 +89,7 @@ struct ClientAsyncTaskParamsFactory
...
@@ -89,6 +89,7 @@ struct ClientAsyncTaskParamsFactory
static
ClientAsyncTaskParamsPtr
CreateMsgQAsyncTask
(
IResponse
*
p_IResponse
,
IContainer
*
p_IContainer
)
{
static
ClientAsyncTaskParamsPtr
CreateMsgQAsyncTask
(
IResponse
*
p_IResponse
,
IContainer
*
p_IContainer
)
{
return
std
::
make_shared
<
ClientAsyncTaskParams
>
(
p_IResponse
,
p_IContainer
,
ClientAsyncTaskParams
::
eMsgQ
);
return
std
::
make_shared
<
ClientAsyncTaskParams
>
(
p_IResponse
,
p_IContainer
,
ClientAsyncTaskParams
::
eMsgQ
);
}
}
};
};
class
cMicroservice_Client
{
class
cMicroservice_Client
{
...
...
src/impl/servers/Microservice_IRestServerEvppImpl.h
View file @
8468cd1b
...
@@ -8,8 +8,8 @@
...
@@ -8,8 +8,8 @@
#include <evpp/http/http_server.h>
#include <evpp/http/http_server.h>
struct
EvppConnParams
{
struct
EvppConnParams
{
const
evpp
::
http
::
ContextPtr
&
ctx_
;
const
evpp
::
http
::
ContextPtr
ctx_
;
const
evpp
::
http
::
HTTPSendResponseCallback
&
cb_
;
const
evpp
::
http
::
HTTPSendResponseCallback
cb_
;
EvppConnParams
(
const
evpp
::
http
::
ContextPtr
&
ctx
,
const
evpp
::
http
::
HTTPSendResponseCallback
&
cb
)
:
EvppConnParams
(
const
evpp
::
http
::
ContextPtr
&
ctx
,
const
evpp
::
http
::
HTTPSendResponseCallback
&
cb
)
:
ctx_
(
ctx
),
cb_
(
cb
)
{}
ctx_
(
ctx
),
cb_
(
cb
)
{}
...
...
test/Microservice_Test.cpp
View file @
8468cd1b
...
@@ -109,14 +109,47 @@ public:
...
@@ -109,14 +109,47 @@ public:
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
it
->
first
.
c_str
()),
rapidjson
::
StringRef
(
dequeIt
->
c_str
()),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
it
->
first
.
c_str
()),
rapidjson
::
StringRef
(
dequeIt
->
c_str
()),
rpj_Alloc
);
}
}
}
}
ReadSync
(
pc_reqCtx
);
ReadAsyncEvpp
(
pc_reqCtx
);
//ReadSync(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
//
this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
//
this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// add metric
// add metric
long
value
=
rand
()
%
1000
+
1
;
long
value
=
rand
()
%
1000
+
1
;
p_histo
->
update
(
value
);
p_histo
->
update
(
value
);
}
}
void
ReadAsyncEvpp
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
std
::
string
body
=
"This is expected to be sent back as part of response body."
;
auto
p_msClient
=
ClientFactory
::
createEvppCommandImpl
(
"evpp-test"
);
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"
;
auto
clientAsyncTaskParamsPtr
=
ClientAsyncTaskParamsFactory
::
CreateCommndParamsAsyncTask
(
pc_reqCtx
->
mpti_Response
,
pc_reqCtx
->
mpti_Container
);
MSCommandParams
msCmndParams
;
msCmndParams
.
WithEntity
(
uri
)
.
WithRequestParams
(
"q=base"
)
.
WithHeadersMap
(
&
headers
)
.
WithContent
(
body
);
msCmndParams
.
WithParamsString
(
"post"
);
p_msClient
->
AsyncCreate
(
&
msCmndParams
,
[
clientAsyncTaskParamsPtr
](
cMicroservice_BaseRestResponse
*
p_baseRestResponse
){
if
(
p_baseRestResponse
->
IsSuccess
()){
clientAsyncTaskParamsPtr
->
p_IContainer_
->
WriteObjectToResponse
(
clientAsyncTaskParamsPtr
->
p_IResponse_
.
get
(),
p_baseRestResponse
->
GetObjectNode
());
}
else
{
clientAsyncTaskParamsPtr
->
p_IContainer_
->
SendErrorResp
(
clientAsyncTaskParamsPtr
->
p_IResponse_
.
get
(),
p_baseRestResponse
->
GetError
());
}
});
}
void
ReadSync
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
void
ReadSync
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
Microservice_RestResponse
rest_response
;
Microservice_RestResponse
rest_response
;
std
::
map
<
std
::
string
,
std
::
string
>
headers
;
std
::
map
<
std
::
string
,
std
::
string
>
headers
;
...
...
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