Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
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
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-incubator
Commits
4fd393da
Commit
4fd393da
authored
Aug 29, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add testcase in transport_worker_dispatcher
parent
ea102198
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
47 deletions
+62
-47
libcaf_net/test/transport_worker_dispatcher.cpp
libcaf_net/test/transport_worker_dispatcher.cpp
+62
-47
No files found.
libcaf_net/test/transport_worker_dispatcher.cpp
View file @
4fd393da
...
...
@@ -24,6 +24,8 @@
#include "host_fixture.hpp"
#include "caf/make_actor.hpp"
#include "caf/monitorable_actor.hpp"
#include "caf/node_id.hpp"
#include "caf/uri.hpp"
...
...
@@ -32,6 +34,16 @@ using namespace caf::net;
namespace
{
struct
dummy_actor
:
public
monitorable_actor
{
dummy_actor
(
actor_config
&
cfg
)
:
monitorable_actor
(
cfg
)
{
// nop
}
void
enqueue
(
mailbox_element_ptr
,
execution_unit
*
)
override
{
// nop
}
};
class
dummy_application
{
public:
dummy_application
(
std
::
shared_ptr
<
std
::
vector
<
byte
>>
rec_buf
,
uint8_t
id
)
...
...
@@ -102,12 +114,12 @@ private:
struct
testdata
{
testdata
(
uint8_t
worker_id
,
node_id
id
,
ip_endpoint
ep
)
:
worker_id
(
worker_id
),
id
(
id
),
ep
(
ep
)
{
:
worker_id
(
worker_id
),
n
id
(
id
),
ep
(
ep
)
{
// nop
}
uint8_t
worker_id
;
node_id
id
;
node_id
n
id
;
ip_endpoint
ep
;
};
...
...
@@ -136,18 +148,53 @@ uri operator"" _u(const char* cstr, size_t cstr_len) {
}
struct
fixture
:
host_fixture
{
fixture
()
{
using
dispatcher_type
=
transport_worker_dispatcher
<
dummy_application_factory
,
ip_endpoint
>
;
fixture
()
:
buf
{
std
::
make_shared
<
std
::
vector
<
byte
>>
()},
dispatcher
{
dummy_application_factory
{
buf
}}
{
// nop
}
std
::
unique_ptr
<
net
::
endpoint_manager
::
message
>
make_dummy_message
(
node_id
nid
)
{
actor_id
aid
=
42
;
actor_config
cfg
;
auto
p
=
make_actor
<
dummy_actor
,
strong_actor_ptr
>
(
aid
,
nid
,
&
sys
,
cfg
);
std
::
vector
<
byte
>
payload
;
auto
strong_actor
=
actor_cast
<
strong_actor_ptr
>
(
p
);
mailbox_element
::
forwarding_stack
stack
;
auto
elem
=
make_mailbox_element
(
std
::
move
(
strong_actor
),
make_message_id
(
12345
),
std
::
move
(
stack
),
make_message
());
return
detail
::
make_unique
<
endpoint_manager
::
message
>
(
std
::
move
(
elem
),
payload
);
}
template
<
class
Application
,
class
IdType
>
void
add_new_workers
(
transport_worker_dispatcher
<
Application
,
IdType
>&
dispatcher
)
{
for
(
auto
&
data
:
test_data
)
{
dispatcher
.
add_new_worker
(
data
.
id
,
data
.
ep
);
dispatcher
.
add_new_worker
(
data
.
n
id
,
data
.
ep
);
}
}
void
test_write_message
(
testdata
&
testcase
)
{
auto
msg
=
make_dummy_message
(
testcase
.
nid
);
if
(
!
msg
->
msg
->
sender
)
CAF_FAIL
(
"sender is null"
);
dispatcher
.
add_new_worker
(
testcase
.
nid
,
"[::1]:1"
_ep
);
dispatcher
.
write_message
(
dummy
,
std
::
move
(
msg
));
}
actor_system_config
cfg
{};
actor_system
sys
{
cfg
};
std
::
shared_ptr
<
std
::
vector
<
byte
>>
buf
;
dispatcher_type
dispatcher
;
dummy
dummy
;
std
::
vector
<
testdata
>
test_data
{
{
0
,
make_node_id
(
"http:file"
_u
),
"[::1]:1"
_ep
},
{
1
,
make_node_id
(
"http:file?a=1&b=2"
_u
),
"[fe80::2:34]:12345"
_ep
},
...
...
@@ -156,66 +203,34 @@ struct fixture : host_fixture {
};
};
std
::
unique_ptr
<
net
::
endpoint_manager
::
message
>
make_dummy_message
()
{
actor
act
;
std
::
vector
<
byte
>
payload
;
auto
strong_actor
=
actor_cast
<
strong_actor_ptr
>
(
act
);
mailbox_element
::
forwarding_stack
stack
;
auto
elem
=
make_mailbox_element
(
std
::
move
(
strong_actor
),
make_message_id
(
12345
),
std
::
move
(
stack
),
make_message
());
return
detail
::
make_unique
<
endpoint_manager
::
message
>
(
std
::
move
(
elem
),
payload
);
}
#define CHECK_HANDLE_DATA(dispatcher, dummy, testcase, buf) \
dispatcher.handle_data(dummy, span<byte>{}, testcase.ep); \
CAF_CHECK_EQUAL(buf->size(), 1u); \
CAF_CHECK_EQUAL(static_cast<byte>(testcase.worker_id), buf->at(0)); \
buf->clear();
#define CHECK_WRITE_MESSAGE(dispatcher, dummy, worker_id, buf) \
{ \
auto msg = make_dummy_message(); \
if (!msg->msg->sender) \
CAF_FAIL("sender is null"); \
auto nid = msg->msg->sender->node(); \
dispatcher.add_new_worker(nid, "[::1]:1"_ep); \
dispatcher.write_message(dummy, std::move(msg)); \
CAF_CHECK_EQUAL(buf->size(), 1u); \
CAF_CHECK_EQUAL(static_cast<byte>(worker_id), buf->at(0)); \
buf->clear(); \
}
#define CHECK_WRITE_MESSAGE(dispatcher, dummy, testcase, buf) \
test_write_message(testcase); \
CAF_CHECK_EQUAL(buf->size(), 1u); \
CAF_CHECK_EQUAL(static_cast<byte>(testcase.worker_id), buf->at(0)); \
buf->clear();
}
// namespace
CAF_TEST_FIXTURE_SCOPE
(
transport_worker_dispatcher_test
,
fixture
)
CAF_TEST
(
handle_data
)
{
auto
buf
=
std
::
make_shared
<
std
::
vector
<
byte
>>
();
using
dispatcher_type
=
transport_worker_dispatcher
<
dummy_application_factory
,
ip_endpoint
>
;
dispatcher_type
dispatcher
{
dummy_application_factory
{
buf
}};
add_new_workers
(
dispatcher
);
dummy
dummy
{};
CHECK_HANDLE_DATA
(
dispatcher
,
dummy
,
test_data
.
at
(
0
),
buf
);
CHECK_HANDLE_DATA
(
dispatcher
,
dummy
,
test_data
.
at
(
1
),
buf
);
CHECK_HANDLE_DATA
(
dispatcher
,
dummy
,
test_data
.
at
(
2
),
buf
);
CHECK_HANDLE_DATA
(
dispatcher
,
dummy
,
test_data
.
at
(
3
),
buf
);
}
// TODO: figure out how to set node_id in messages/ create messages with passed
// node_ids
/*CAF_TEST(write_message) {
auto buf = std::make_shared<std::vector<byte>>();
using dispatcher_type = transport_worker_dispatcher<dummy_application_factory,
ip_endpoint>;
dispatcher_type dispatcher{dummy_application_factory{buf}};
dummy dummy{};
CHECK_WRITE_MESSAGE(dispatcher, dummy, 0, buf);
CHECK_WRITE_MESSAGE(dispatcher, dummy, 1, buf);
CHECK_WRITE_MESSAGE(dispatcher, dummy, 2, buf);
CHECK_WRITE_MESSAGE(dispatcher, dummy, 3, buf);
}*/
CAF_TEST
(
write_message
)
{
CHECK_WRITE_MESSAGE
(
dispatcher
,
dummy
,
test_data
.
at
(
0
),
buf
);
CHECK_WRITE_MESSAGE
(
dispatcher
,
dummy
,
test_data
.
at
(
1
),
buf
);
CHECK_WRITE_MESSAGE
(
dispatcher
,
dummy
,
test_data
.
at
(
2
),
buf
);
CHECK_WRITE_MESSAGE
(
dispatcher
,
dummy
,
test_data
.
at
(
3
),
buf
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
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