mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Tests for MQ examples
This commit is contained in:
@@ -6,12 +6,11 @@
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/2-sampler-processor-sink/ex2-sampler-processor-sink.json
|
||||
${CMAKE_BINARY_DIR}/bin/config/ex2-sampler-processor-sink.json)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/2-sampler-processor-sink/startMQEx2.sh.in
|
||||
${CMAKE_BINARY_DIR}/bin/examples/MQ/2-sampler-processor-sink/startMQEx2.sh)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/2-sampler-processor-sink/ex2-sampler-processor-sink.json ${CMAKE_BINARY_DIR}/bin/config/ex2-sampler-processor-sink.json)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/2-sampler-processor-sink/startMQEx2.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/2-sampler-processor-sink/startMQEx2.sh)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/2-sampler-processor-sink/testMQEx2.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/2-sampler-processor-sink/testMQEx2.sh)
|
||||
|
||||
Set(INCLUDE_DIRECTORIES
|
||||
set(INCLUDE_DIRECTORIES
|
||||
${CMAKE_SOURCE_DIR}/fairmq
|
||||
${CMAKE_SOURCE_DIR}/fairmq/devices
|
||||
${CMAKE_SOURCE_DIR}/fairmq/tools
|
||||
@@ -20,42 +19,42 @@ Set(INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
Set(SYSTEM_INCLUDE_DIRECTORIES
|
||||
set(SYSTEM_INCLUDE_DIRECTORIES
|
||||
${Boost_INCLUDE_DIR}
|
||||
${ZeroMQ_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
Include_Directories(${INCLUDE_DIRECTORIES})
|
||||
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
|
||||
include_directories(${INCLUDE_DIRECTORIES})
|
||||
include_directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
|
||||
|
||||
Set(LINK_DIRECTORIES
|
||||
set(LINK_DIRECTORIES
|
||||
${Boost_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
Link_Directories(${LINK_DIRECTORIES})
|
||||
link_directories(${LINK_DIRECTORIES})
|
||||
|
||||
Set(SRCS
|
||||
set(SRCS
|
||||
"FairMQExample2Sampler.cxx"
|
||||
"FairMQExample2Processor.cxx"
|
||||
"FairMQExample2Sink.cxx"
|
||||
)
|
||||
|
||||
Set(DEPENDENCIES
|
||||
set(DEPENDENCIES
|
||||
${DEPENDENCIES}
|
||||
FairMQ
|
||||
)
|
||||
|
||||
Set(LIBRARY_NAME FairMQExample2)
|
||||
set(LIBRARY_NAME FairMQExample2)
|
||||
|
||||
GENERATE_LIBRARY()
|
||||
|
||||
Set(Exe_Names
|
||||
set(Exe_Names
|
||||
ex2-sampler
|
||||
ex2-processor
|
||||
ex2-sink
|
||||
)
|
||||
|
||||
Set(Exe_Source
|
||||
set(Exe_Source
|
||||
runExample2Sampler.cxx
|
||||
runExample2Processor.cxx
|
||||
runExample2Sink.cxx
|
||||
@@ -67,16 +66,21 @@ math(EXPR _length ${_length}-1)
|
||||
set(BIN_DESTINATION share/fairbase/examples/MQ/2-sampler-processor-sink/bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/examples/MQ/2-sampler-processor-sink")
|
||||
|
||||
ForEach(_file RANGE 0 ${_length})
|
||||
foreach(_file RANGE 0 ${_length})
|
||||
list(GET Exe_Names ${_file} _name)
|
||||
list(GET Exe_Source ${_file} _src)
|
||||
Set(EXE_NAME ${_name})
|
||||
Set(SRCS ${_src})
|
||||
Set(DEPENDENCIES FairMQExample2)
|
||||
set(EXE_NAME ${_name})
|
||||
set(SRCS ${_src})
|
||||
set(DEPENDENCIES FairMQExample2)
|
||||
GENERATE_EXECUTABLE()
|
||||
EndForEach(_file RANGE 0 ${_length})
|
||||
endforeach(_file RANGE 0 ${_length})
|
||||
|
||||
Install(
|
||||
add_test(NAME MQ.ex2-sampler-processor-sink COMMAND ${CMAKE_BINARY_DIR}/bin/examples/MQ/2-sampler-processor-sink/testMQEx2.sh)
|
||||
set_tests_properties(MQ.ex2-sampler-processor-sink PROPERTIES TIMEOUT "30")
|
||||
set_tests_properties(MQ.ex2-sampler-processor-sink PROPERTIES RUN_SERIAL true)
|
||||
set_tests_properties(MQ.ex2-sampler-processor-sink PROPERTIES PASS_REGULAR_EXPRESSION "Received: ")
|
||||
|
||||
install(
|
||||
FILES ex2-sampler-processor-sink.json
|
||||
DESTINATION share/fairbase/examples/MQ/2-sampler-processor-sink/config/
|
||||
)
|
||||
|
@@ -23,19 +23,20 @@ using namespace std;
|
||||
|
||||
FairMQExample2Sampler::FairMQExample2Sampler()
|
||||
: fText()
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQExample2Sampler::InitTask()
|
||||
{
|
||||
// Get the fText value from the command line option (via fConfig)
|
||||
// Get the fText and fMaxIterations values from the command line options (via fConfig)
|
||||
fText = fConfig->GetValue<string>("text");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
bool FairMQExample2Sampler::ConditionalRun()
|
||||
{
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
// Initializing message with NewStaticMessage will avoid copy
|
||||
// but won't delete the data after the sending is completed.
|
||||
FairMQMessagePtr msg(NewStaticMessage(fText));
|
||||
@@ -48,6 +49,13 @@ bool FairMQExample2Sampler::ConditionalRun()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
return false;
|
||||
}
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@ class FairMQExample2Sampler : public FairMQDevice
|
||||
|
||||
protected:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
|
||||
virtual void InitTask();
|
||||
virtual bool ConditionalRun();
|
||||
|
@@ -14,21 +14,36 @@
|
||||
|
||||
#include "FairMQExample2Sink.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h" // device->fConfig
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQExample2Sink::FairMQExample2Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
// register a handler for data arriving on "data2" channel
|
||||
OnData("data2", &FairMQExample2Sink::HandleData);
|
||||
}
|
||||
|
||||
void FairMQExample2Sink::InitTask()
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
// handler is called whenever a message arrives on "data2", with a reference to the message and a sub-channel index (here 0)
|
||||
bool FairMQExample2Sink::HandleData(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
|
||||
// return true if want to be called again (otherwise go to IDLE state)
|
||||
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// return true if want to be called again (otherwise return false go to IDLE state)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,12 @@ class FairMQExample2Sink : public FairMQDevice
|
||||
virtual ~FairMQExample2Sink();
|
||||
|
||||
protected:
|
||||
virtual void InitTask();
|
||||
bool HandleData(FairMQMessagePtr&, int);
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQEXAMPLE2SINK_H_ */
|
||||
|
@@ -14,7 +14,8 @@ namespace bpo = boost::program_options;
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("text", bpo::value<std::string>()->default_value("Hello"), "Text to send out");
|
||||
("text", bpo::value<std::string>()->default_value("Hello"), "Text to send out")
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -11,8 +11,10 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
void addCustomOptions(bpo::options_description& /*options*/)
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
50
examples/MQ/2-sampler-processor-sink/testMQEx2.sh.in
Executable file
50
examples/MQ/2-sampler-processor-sink/testMQEx2.sh.in
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
ex2config="@CMAKE_BINARY_DIR@/bin/config/ex2-sampler-processor-sink.json"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; kill -TERM $PROCESSOR1_PID; kill -TERM $PROCESSOR2_PID; wait $SAMPLER_PID; wait $SINK_PID; wait $PROCESSOR1_PID; wait $PROCESSOR2_PID;' TERM
|
||||
|
||||
SAMPLER="ex2-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --control static --log-color false"
|
||||
SAMPLER+=" --max-iterations 2"
|
||||
SAMPLER+=" --mq-config $ex2config"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/2-sampler-processor-sink/$SAMPLER &
|
||||
SAMPLER_PID=$!
|
||||
|
||||
PROCESSOR1="ex2-processor"
|
||||
PROCESSOR1+=" --id processor1"
|
||||
PROCESSOR1+=" --control static --log-color false"
|
||||
PROCESSOR1+=" --mq-config $ex2config"
|
||||
PROCESSOR1+=" --config-key processor"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/2-sampler-processor-sink/$PROCESSOR1 &
|
||||
PROCESSOR1_PID=$!
|
||||
|
||||
PROCESSOR2="ex2-processor"
|
||||
PROCESSOR2+=" --id processor2"
|
||||
PROCESSOR2+=" --control static --log-color false"
|
||||
PROCESSOR2+=" --mq-config $ex2config"
|
||||
PROCESSOR2+=" --config-key processor"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/2-sampler-processor-sink/$PROCESSOR2 &
|
||||
PROCESSOR2_PID=$!
|
||||
|
||||
SINK="ex2-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --control static --log-color false"
|
||||
SINK+=" --max-iterations 2"
|
||||
SINK+=" --mq-config $ex2config"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/2-sampler-processor-sink/$SINK &
|
||||
SINK_PID=$!
|
||||
|
||||
# wait for sampler and sink to finish
|
||||
wait $SAMPLER_PID
|
||||
wait $SINK_PID
|
||||
|
||||
# stop processors
|
||||
kill -SIGINT $PROCESSOR1_PID
|
||||
kill -SIGINT $PROCESSOR2_PID
|
||||
|
||||
# wait for everything to finish
|
||||
wait $PROCESSOR1_PID
|
||||
wait $PROCESSOR2_PID
|
Reference in New Issue
Block a user