Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
a17c62e9
Commit
a17c62e9
authored
May 02, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix counting issue in composable_behavior test
parent
e79d76e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
+24
-5
libcaf_core/test/composable_behavior.cpp
libcaf_core/test/composable_behavior.cpp
+24
-5
No files found.
libcaf_core/test/composable_behavior.cpp
View file @
a17c62e9
...
@@ -152,9 +152,12 @@ namespace {
...
@@ -152,9 +152,12 @@ namespace {
using
add_atom
=
atom_constant
<
atom
(
"add"
)
>
;
using
add_atom
=
atom_constant
<
atom
(
"add"
)
>
;
using
get_name_atom
=
atom_constant
<
atom
(
"getName"
)
>
;
using
get_name_atom
=
atom_constant
<
atom
(
"getName"
)
>
;
using
ping_atom
=
atom_constant
<
atom
(
"ping"
)
>
;
using
pong_atom
=
atom_constant
<
atom
(
"pong"
)
>
;
// "base" interface
// "base" interface
using
named_actor
=
typed_actor
<
replies_to
<
get_name_atom
>::
with
<
counting_string
>>
;
using
named_actor
=
typed_actor
<
replies_to
<
get_name_atom
>::
with
<
counting_string
>
,
replies_to
<
ping_atom
>::
with
<
pong_atom
>>
;
// a simple dictionary
// a simple dictionary
using
dict
=
named_actor
::
extend
<
replies_to
<
get_atom
,
counting_string
>::
with
<
counting_string
>
,
using
dict
=
named_actor
::
extend
<
replies_to
<
get_atom
,
counting_string
>::
with
<
counting_string
>
,
...
@@ -166,6 +169,10 @@ public:
...
@@ -166,6 +169,10 @@ public:
return
"dictionary"
;
return
"dictionary"
;
}
}
result
<
pong_atom
>
operator
()(
ping_atom
)
override
{
return
pong_atom
::
value
;
}
result
<
counting_string
>
operator
()(
get_atom
,
param
<
counting_string
>
key
)
override
{
result
<
counting_string
>
operator
()(
get_atom
,
param
<
counting_string
>
key
)
override
{
auto
i
=
values_
.
find
(
key
);
auto
i
=
values_
.
find
(
key
);
if
(
i
==
values_
.
end
())
if
(
i
==
values_
.
end
())
...
@@ -215,6 +222,14 @@ CAF_TEST(composition) {
...
@@ -215,6 +222,14 @@ CAF_TEST(composition) {
CAF_TEST
(
param_detaching
)
{
CAF_TEST
(
param_detaching
)
{
auto
dict
=
actor_cast
<
actor
>
(
system
.
spawn
<
dict_state
>
());
auto
dict
=
actor_cast
<
actor
>
(
system
.
spawn
<
dict_state
>
());
scoped_actor
self
{
system
};
scoped_actor
self
{
system
};
// this ping-pong makes sure that dict has cleaned up all state related
// to a test before moving to the second test; otherwise, reference counts
// can diverge from what we expect
auto
ping_pong
=
[
&
]
{
self
->
request
(
dict
,
infinite
,
ping_atom
::
value
).
receive
([](
pong_atom
)
{
// nop
});
};
// Using CAF is the key to success!
// Using CAF is the key to success!
counting_string
key
=
"CAF"
;
counting_string
key
=
"CAF"
;
counting_string
value
=
"success"
;
counting_string
value
=
"success"
;
...
@@ -229,7 +244,8 @@ CAF_TEST(param_detaching) {
...
@@ -229,7 +244,8 @@ CAF_TEST(param_detaching) {
CAF_CHECK_EQUAL
(
counting_strings_destroyed
.
load
(),
0
);
CAF_CHECK_EQUAL
(
counting_strings_destroyed
.
load
(),
0
);
// send put message to dictionary
// send put message to dictionary
self
->
request
(
dict
,
infinite
,
put_msg
).
receive
(
self
->
request
(
dict
,
infinite
,
put_msg
).
receive
(
[]
{
[
&
]
{
ping_pong
();
// the handler of put_atom calls .move() on key and value,
// the handler of put_atom calls .move() on key and value,
// both causing to detach + move into the map
// both causing to detach + move into the map
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
9
);
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
9
);
...
@@ -239,7 +255,8 @@ CAF_TEST(param_detaching) {
...
@@ -239,7 +255,8 @@ CAF_TEST(param_detaching) {
);
);
// send put message to dictionary again
// send put message to dictionary again
self
->
request
(
dict
,
infinite
,
put_msg
).
receive
(
self
->
request
(
dict
,
infinite
,
put_msg
).
receive
(
[]
{
[
&
]
{
ping_pong
();
// the handler checks whether key already exists -> no copies
// the handler checks whether key already exists -> no copies
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
9
);
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
9
);
CAF_CHECK_EQUAL
(
counting_strings_moved
.
load
(),
2
);
CAF_CHECK_EQUAL
(
counting_strings_moved
.
load
(),
2
);
...
@@ -251,7 +268,8 @@ CAF_TEST(param_detaching) {
...
@@ -251,7 +268,8 @@ CAF_TEST(param_detaching) {
put_msg
.
get_as_mutable
<
counting_string
>
(
2
)
=
"CAF"
;
put_msg
.
get_as_mutable
<
counting_string
>
(
2
)
=
"CAF"
;
// send put message to dictionary
// send put message to dictionary
self
->
request
(
dict
,
infinite
,
std
::
move
(
put_msg
)).
receive
(
self
->
request
(
dict
,
infinite
,
std
::
move
(
put_msg
)).
receive
(
[]
{
[
&
]
{
ping_pong
();
// the handler of put_atom calls .move() on key and value,
// the handler of put_atom calls .move() on key and value,
// but no detaching occurs this time (unique access) -> move into the map
// but no detaching occurs this time (unique access) -> move into the map
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
11
);
CAF_CHECK_EQUAL
(
counting_strings_created
.
load
(),
11
);
...
@@ -261,7 +279,8 @@ CAF_TEST(param_detaching) {
...
@@ -261,7 +279,8 @@ CAF_TEST(param_detaching) {
);
);
// finally, check for original key
// finally, check for original key
self
->
request
(
dict
,
infinite
,
std
::
move
(
get_msg
)).
receive
(
self
->
request
(
dict
,
infinite
,
std
::
move
(
get_msg
)).
receive
(
[](
const
counting_string
&
str
)
{
[
&
](
const
counting_string
&
str
)
{
ping_pong
();
// we receive a copy of the value, which is copied out of the map and
// we receive a copy of the value, which is copied out of the map and
// then moved into the result message;
// then moved into the result message;
// the string from our get_msg is destroyed
// the string from our get_msg is destroyed
...
...
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