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
ce505d29
authored
Mar 30, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
todo
parent
f7e1966d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
25 deletions
doc/todo.txt
test/Microservice_ClientTest.cpp
doc/todo.txt
View file @
ce505d29
...
...
@@ -4,3 +4,5 @@
the server receives the msg with the source(client pull channel) address to reply to,
checks in the hash for already connected and uses this channel to send a reply.
we can use zmqpp::socket::send_more to send source address and then the actual msg
- Test FlatBuffer as serialyzer for rest over zmq
\ No newline at end of file
test/Microservice_ClientTest.cpp
View file @
ce505d29
...
...
@@ -24,6 +24,7 @@
#include "impl/Microservices_ILoggerLog4cppImpl.h"
#include <utils/ClientFactory.h>
#include <utils/CommonUtils.h>
static
const
char
*
const
PUBSUBHOST
=
"zmqpubsub"
;
...
...
@@ -197,21 +198,67 @@ using json = nlohmann::json;
static
const
int
ITERATIONS
=
1000000
;
static
const
char
*
const
JSON_CONTENT
=
"{
\n
"
"
\"
success
\"
: true,
\n
"
"
\"
error
\"
: null,
\n
"
"
\"
objectNode
\"
: {
\n
"
"
\"
success
\"
: true,
\n
"
"
\"
error
\"
: null,
\n
"
"
\"
objectNode
\"
: {
\n
"
"
\"
num_results
\"
: 6,
\n
"
"
\"
query
\"
:
\"
base
\"
,
\n
"
"
\"
results
\"
: [
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-no-db
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-ui
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-db
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-ims
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-resin
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-microservice-java
\"\n
"
" }
\n
"
" ]
\n
"
" }
\n
"
" }
\n
"
"}"
;
static
const
char
*
const
SOURCE_CHANNEL
=
"ipc:///tmp/some-file.ipc"
;
static
const
char
*
const
URI
=
"/xxx/resource/subResource"
;
static
const
char
*
const
QUERY_STRING
=
"a=b&c=d&abba=sabba"
;
void
testRapidJson
()
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
json
;
rapidjson
::
Document
rpj_Doc
;
// Null
rapidjson
::
Document
::
AllocatorType
&
rpj_Alloc
=
rpj_Doc
.
GetAllocator
();
rpj_Doc
.
SetObject
();
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status"
),
true
,
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello1"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number1"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status1"
),
true
,
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello2"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number2"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status2"
),
true
,
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"source"
),
rapidjson
::
StringRef
(
SOURCE_CHANNEL
),
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("uri"), rapidjson::Value(i), rpj_Alloc);
//rpj_Doc.AddMember(rapidjson::StringRef("status"), true, rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"uri"
),
rapidjson
::
StringRef
(
URI
),
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("number1"), rapidjson::Value(i), rpj_Alloc);
//rpj_Doc.AddMember(rapidjson::StringRef("status1"), true, rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"queryString"
),
rapidjson
::
StringRef
(
QUERY_STRING
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"content"
),
rapidjson
::
StringRef
(
JSON_CONTENT
),
rpj_Alloc
);
// rpj_Doc.AddMember(rapidjson::StringRef("number2"), rapidjson::Value(i), rpj_Alloc);
// rpj_Doc.AddMember(rapidjson::StringRef("status2"), true, rpj_Alloc);
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
rpj_Doc
.
Accept
(
writer
);
...
...
@@ -223,31 +270,53 @@ void testNlohmanJson() {
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
jsonStr
;
json
j
;
j
.
emplace
(
"hello"
,
"world"
);
j
.
emplace
(
"number"
,
i
);
j
.
emplace
(
"status"
,
true
);
j
[
"hello1"
]
=
"world"
;
j
[
"number1"
]
=
i
;
j
[
"status1"
]
=
true
;
j
.
emplace
(
"hello2"
,
"world"
);
j
.
emplace
(
"number2"
,
i
);
j
.
emplace
(
"status2"
,
true
);
j
.
emplace
(
"source"
,
SOURCE_CHANNEL
);
j
.
emplace
(
"uri"
,
URI
);
j
.
emplace
(
"queryString"
,
QUERY_STRING
);
j
[
"content"
]
=
JSON_CONTENT
;
jsonStr
=
j
.
dump
();
}
}
#define MAKE_STRING_PAIR(s1,s2) std::make_pair<std::string,std::string>(s1,s2)
void
testSerializations
()
{
using
ParamsMap
=
std
::
map
<
std
::
string
,
std
::
string
>
;
ParamsMap
paramsMap
;
const
char
*
strBuff
;
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"source"
,
SOURCE_CHANNEL
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"uri"
,
URI
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"queryString"
,
QUERY_STRING
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"content"
,
JSON_CONTENT
));
rapidjson
::
Document
doc
;
// Null
rapidjson
::
Document
::
AllocatorType
&
allocator
=
doc
.
GetAllocator
();
doc
.
SetObject
();
for
(
auto
&
pair
:
paramsMap
)
doc
.
AddMember
(
rapidjson
::
StringRef
(
pair
.
first
.
c_str
()),
rapidjson
::
StringRef
(
pair
.
second
.
c_str
()),
allocator
);
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
doc
.
Accept
(
writer
);
strBuff
=
buffer
.
GetString
();
}
}
void
testJsons
()
{
std
::
time_t
now
=
std
::
time
(
nullptr
)
;
testRapidJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with rapid json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\n'
;
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with map serialization json took: "
<<
CommonUtils
::
measureFunc
<>
(
testSerializations
)
<<
"msec"
<<
'\n'
;
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with rapid json took: "
<<
CommonUtils
::
measureFunc
<>
(
testRapidJson
)
<<
"msec"
<<
'\n'
;
if
(
false
or
not
true
){
}
// test json-nlohman
now
=
std
::
time
(
nullptr
);
testNlohmanJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with nlohman json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\n'
;
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with nlohman json took: "
<<
CommonUtils
::
measureFunc
<>
(
testNlohmanJson
)
<<
"msec"
<<
'\n'
;
}
...
...
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