-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
dev/test/so_5/message_limits/transform_to_mutable_msg/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(UNITTEST _unit.test.message_limits.transform_to_mutable_msg) | ||
include(${CMAKE_SOURCE_DIR}/cmake/unittest.cmake) |
115 changes: 115 additions & 0 deletions
115
dev/test/so_5/message_limits/transform_to_mutable_msg/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* A test for trasformation of an immutable message into a mutable message. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <map> | ||
#include <exception> | ||
#include <stdexcept> | ||
#include <cstdlib> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
#include <so_5/all.hpp> | ||
|
||
#include <test/3rd_party/various_helpers/time_limited_execution.hpp> | ||
|
||
struct msg_initial_message final : public so_5::message_t | ||
{ | ||
const std::string m_msg; | ||
|
||
msg_initial_message( std::string msg ) : m_msg{ std::move(msg) } | ||
{} | ||
}; | ||
|
||
struct msg_transformed_message final : public so_5::message_t | ||
{ | ||
std::string m_msg; | ||
|
||
msg_transformed_message( std::string msg ) : m_msg{ std::move(msg) } | ||
{} | ||
}; | ||
|
||
class agent_with_limit_t final : public so_5::agent_t | ||
{ | ||
public : | ||
agent_with_limit_t( | ||
context_t ctx ) | ||
: so_5::agent_t{ ctx | ||
+ limit_then_transform( 1u, | ||
[this]( const msg_initial_message & msg ) { | ||
return make_transformed< | ||
so_5::mutable_msg< msg_transformed_message > >( | ||
so_direct_mbox(), | ||
"<" + msg.m_msg + ">" ); | ||
} ) | ||
+ limit_then_abort< so_5::mutable_msg< msg_transformed_message > >( 1u ) | ||
} | ||
{} | ||
|
||
void | ||
so_define_agent() override | ||
{ | ||
so_subscribe_self() | ||
.event( [this]( mhood_t<msg_initial_message> cmd ) { | ||
m_received += "[initial:" + cmd->m_msg + "]"; | ||
} ) | ||
.event( [this]( mutable_mhood_t<msg_transformed_message> cmd ) { | ||
m_received += "[transformed:" + cmd->m_msg + "]"; | ||
|
||
const std::string expected = | ||
"[initial:hello][transformed:<bye>]"; | ||
|
||
if( expected != m_received ) | ||
throw std::runtime_error( expected + " != " + m_received ); | ||
else | ||
so_deregister_agent_coop_normally(); | ||
} ) | ||
; | ||
} | ||
|
||
virtual void | ||
so_evt_start() override | ||
{ | ||
so_5::send< msg_initial_message >( *this, "hello" ); | ||
so_5::send< msg_initial_message >( *this, "bye" ); | ||
} | ||
|
||
private : | ||
std::string m_received; | ||
}; | ||
|
||
void | ||
init( so_5::environment_t & env ) | ||
{ | ||
env.introduce_coop( | ||
[]( so_5::coop_t & coop ) { | ||
coop.make_agent< agent_with_limit_t >(); | ||
} ); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
try | ||
{ | ||
run_with_time_limit( | ||
[]() | ||
{ | ||
so_5::launch( &init, | ||
[](so_5::environment_params_t & params) { | ||
params.message_delivery_tracer( | ||
so_5::msg_tracing::std_cout_tracer() ); | ||
} ); | ||
}, | ||
5 ); | ||
} | ||
catch( const std::exception & ex ) | ||
{ | ||
std::cerr << "Error: " << ex.what() << std::endl; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
dev/test/so_5/message_limits/transform_to_mutable_msg/prj.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'mxx_ru/cpp' | ||
|
||
MxxRu::Cpp::exe_target { | ||
|
||
required_prj 'so_5/prj.rb' | ||
|
||
target '_unit.test.message_limits.transform_to_mutable_msg' | ||
|
||
cpp_source 'main.cpp' | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
dev/test/so_5/message_limits/transform_to_mutable_msg/prj.ut.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'mxx_ru/binary_unittest' | ||
|
||
path = 'test/so_5/message_limits/transform_to_mutable_msg' | ||
|
||
MxxRu::setup_target( | ||
MxxRu::BinaryUnittestTarget.new( | ||
"#{path}/prj.ut.rb", | ||
"#{path}/prj.rb" ) | ||
) |
2 changes: 2 additions & 0 deletions
2
dev/test/so_5/message_limits/transform_to_mutable_msg_2/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set(UNITTEST _unit.test.message_limits.transform_to_mutable_msg_2) | ||
include(${CMAKE_SOURCE_DIR}/cmake/unittest.cmake) |
116 changes: 116 additions & 0 deletions
116
dev/test/so_5/message_limits/transform_to_mutable_msg_2/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* A test for trasformation of an immutable message into a mutable message. | ||
* Messages that not derived from so_5::message_t are used. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <map> | ||
#include <exception> | ||
#include <stdexcept> | ||
#include <cstdlib> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
#include <so_5/all.hpp> | ||
|
||
#include <test/3rd_party/various_helpers/time_limited_execution.hpp> | ||
|
||
struct msg_initial_message | ||
{ | ||
const std::string m_msg; | ||
|
||
msg_initial_message( std::string msg ) : m_msg{ std::move(msg) } | ||
{} | ||
}; | ||
|
||
struct msg_transformed_message | ||
{ | ||
std::string m_msg; | ||
|
||
msg_transformed_message( std::string msg ) : m_msg{ std::move(msg) } | ||
{} | ||
}; | ||
|
||
class agent_with_limit_t final : public so_5::agent_t | ||
{ | ||
public : | ||
agent_with_limit_t( | ||
context_t ctx ) | ||
: so_5::agent_t{ ctx | ||
+ limit_then_transform( 1u, | ||
[this]( const msg_initial_message & msg ) { | ||
return make_transformed< | ||
so_5::mutable_msg< msg_transformed_message > >( | ||
so_direct_mbox(), | ||
"<" + msg.m_msg + ">" ); | ||
} ) | ||
+ limit_then_abort< so_5::mutable_msg< msg_transformed_message > >( 1u ) | ||
} | ||
{} | ||
|
||
void | ||
so_define_agent() override | ||
{ | ||
so_subscribe_self() | ||
.event( [this]( mhood_t<msg_initial_message> cmd ) { | ||
m_received += "[initial:" + cmd->m_msg + "]"; | ||
} ) | ||
.event( [this]( mutable_mhood_t<msg_transformed_message> cmd ) { | ||
m_received += "[transformed:" + cmd->m_msg + "]"; | ||
|
||
const std::string expected = | ||
"[initial:hello][transformed:<bye>]"; | ||
|
||
if( expected != m_received ) | ||
throw std::runtime_error( expected + " != " + m_received ); | ||
else | ||
so_deregister_agent_coop_normally(); | ||
} ) | ||
; | ||
} | ||
|
||
virtual void | ||
so_evt_start() override | ||
{ | ||
so_5::send< msg_initial_message >( *this, "hello" ); | ||
so_5::send< msg_initial_message >( *this, "bye" ); | ||
} | ||
|
||
private : | ||
std::string m_received; | ||
}; | ||
|
||
void | ||
init( so_5::environment_t & env ) | ||
{ | ||
env.introduce_coop( | ||
[]( so_5::coop_t & coop ) { | ||
coop.make_agent< agent_with_limit_t >(); | ||
} ); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
try | ||
{ | ||
run_with_time_limit( | ||
[]() | ||
{ | ||
so_5::launch( &init, | ||
[](so_5::environment_params_t & params) { | ||
params.message_delivery_tracer( | ||
so_5::msg_tracing::std_cout_tracer() ); | ||
} ); | ||
}, | ||
5 ); | ||
} | ||
catch( const std::exception & ex ) | ||
{ | ||
std::cerr << "Error: " << ex.what() << std::endl; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
dev/test/so_5/message_limits/transform_to_mutable_msg_2/prj.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'mxx_ru/cpp' | ||
|
||
MxxRu::Cpp::exe_target { | ||
|
||
required_prj 'so_5/prj.rb' | ||
|
||
target '_unit.test.message_limits.transform_to_mutable_msg_2' | ||
|
||
cpp_source 'main.cpp' | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
dev/test/so_5/message_limits/transform_to_mutable_msg_2/prj.ut.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'mxx_ru/binary_unittest' | ||
|
||
path = 'test/so_5/message_limits/transform_to_mutable_msg_2' | ||
|
||
MxxRu::setup_target( | ||
MxxRu::BinaryUnittestTarget.new( | ||
"#{path}/prj.ut.rb", | ||
"#{path}/prj.rb" ) | ||
) |