8#include "phoenix_assert.h"
25 phoenix_assert(retrieved.
getId() == 123);
36 daemon.
load(fileName,
"main");
53 PString invalidTomlConfig = R
"(
67 PString invalidYmlConfig = R
"(
81 PString invalidJsonConfig = R
"({
96 PPath tempFile = PPath(
"test_no_daemon_section.toml");
97 PString invalidTomlConfig = R
"(
102 tempFile.saveFileContent(invalidTomlConfig);
109 PPath tempFile = PPath(
"test_no_daemon_section.yml");
110 PString invalidYmlConfig = R
"(
115 tempFile.saveFileContent(invalidYmlConfig);
122 PPath tempFile = PPath(
"test_no_daemon_section.json");
123 PString invalidJsonConfig = R
"({
129 tempFile.saveFileContent(invalidJsonConfig);
139 daemon.
load(fileName,
"main");
152 PString tomlString = fileName.loadFileContent();
165 daemon.
load(fileName,
"main");
180 PString ymlString = fileName.loadFileContent();
193 phoenix_assert(daemon.
load(fileName,
"main"));
208 PString jsonString = fileName.loadFileContent();
221 const char* argv[] = {
223 "--daemonconfig", configFile,
224 "--daemonname", daemonName
226 int argc =
sizeof(argv) /
sizeof(argv[0]);
228 phoenix_assert(daemon.
parseArgument(argc,
const_cast<char**
>(argv)));
243 phoenix_assert(stat.
getMin() == 2.0f);
244 phoenix_assert(stat.
getMax() == 2.0f);
245 phoenix_assert(stat.
getSum() == 2.0f);
250 phoenix_assert(stat.
getMin() == 2.0f);
251 phoenix_assert(stat.
getMax() == 8.0f);
252 phoenix_assert(stat.
getSum() == 10.0f);
282 phoenix_assert(it->second.getNbEvent() == 0lu);
283 for(std::vector<size_t>::const_iterator vit = it->second.getVecHistogram().begin();
284 vit != it->second.getVecHistogram().end(); ++vit) {
285 phoenix_assert(*vit == 0lu);
291 for(MapStatAccumulator::const_iterator it = itMap->second.begin(); it != itMap->second.end(); ++it) {
292 phoenix_assert(it->second.getNbEvent() == 0lu);
293 for(std::vector<size_t>::const_iterator vit = it->second.getVecHistogram().begin();
294 vit != it->second.getVecHistogram().end(); ++vit) {
295 phoenix_assert(*vit == 0lu);
331 time_t startTime = 1000lu;
332 time_t endTime = 2000lu;
335 phoenix_assert(vecStat.
getNbEvent().size() == 1lu);
336 phoenix_assert(vecStat.
getNbEvent()[0] == 4lu);
337 phoenix_assert(vecStat.
getMin().size() == 1lu);
338 phoenix_assert(vecStat.
getMin()[0] == 2.0f);
339 phoenix_assert(vecStat.
getMax().size() == 1lu);
340 phoenix_assert(vecStat.
getMax()[0] == 8.0f);
341 phoenix_assert(vecStat.
getAverage().size() == 1lu);
342 phoenix_assert(vecStat.
getAverage()[0] == 5.0f);
348 phoenix_assert(vecStat.
getRate().size() == 1lu);
363 time_t startTime = 1000lu;
364 time_t endTime = 2000lu;
373int main(
int argc,
char** argv){
void testBaseDaemonGetMessageToConfirm()
Get a BaseDaemon with a message to confirm.
void testBaseDaemonLoadConfigYml(const PPath &fileName)
Test the load configuration of a BaseDaemon.
void testBaseDaemonLoadConfigJson(const PPath &fileName)
Test the load configuration of a BaseDaemon.
void testBaseDaemonMissingDaemonSectionTomlString()
Test BaseDaemon with missing daemon section in TOML string config.
int main(int argc, char **argv)
void testFillVecStat()
Test the fill vector of stats.
void testBaseDaemonParseArgument(const char *configFile, const char *daemonName)
Test the parse argument of a BaseDaemon.
void testUpdateStatAccumulator()
Test the update of a StatAccumulator.
void testFillDaemonStat()
Test the fill of Daemon stats.
void testBaseDaemonMissingDaemonSectionYmlString()
Test BaseDaemon with missing daemon section in YAML string config.
void testBaseDaemonLoadConfigToml(const PPath &fileName)
Test the load configuration of a BaseDaemon.
void testBaseDaemonProcessConfirmedMessage(const PPath &fileName)
Test BaseDaemon with a message to process.
void testBaseDaemonLoadConfigYmlString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a string YAML.
void testBaseDaemonMissingDaemonSectionTomlFile()
Test BaseDaemon with missing daemon section in TOML file.
void testBaseDaemonLoadConfigJsonString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a JSON string.
StatAccumulator createTestStatAccumulator()
Create stat accumulator.
void testBaseDaemonMissingDaemonSectionJsonFile()
Test BaseDaemon with missing daemon section in JSON file.
void testClearStatAccumulator()
Test the clear of StatAccumulator in BaseDaemon.
void testBaseDaemonMissingDaemonSectionJsonString()
Test BaseDaemon with missing daemon section in JSON string config.
void testBaseDaemonMissingDaemonSectionYmlFile()
Test BaseDaemon with missing daemon section in YML file.
void testBaseDaemonLoadConfigTomlString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a string TOML.
Exception for daemon configuration errors.
Exception for configuration errors.
Daemon which help communication between processes and thread.
bool isDaemonExist(const PString &name) const
Say if a neighbour Daemon does exist.
void updateStatAccumulator(StatAccumulator &stat, float value)
Update a computing statistic with a new value.
void addMessageToConfirm(const Swarm::Message &message)
Add a message to confirm.
bool load(const PString &configFileContent, const PString &daemonName, ConfigFormat::ConfigFormat format)
Load the Json configuration which define all BaseDaemons of the Swarm.
DaemonConfig & getConfig()
Get the configuration of the current BaseDaemon.
VecStat fillVecStat(const Swarm::StatAccumulator &accumulator, time_t startTimestamp, time_t endTimestamp)
Fill a VecStat from a StatAccumulator to send to the DamonStat.
void fillDaemonStat(Swarm::Stat &stat, time_t startTimestamp, time_t endTimestamp)
Fill the Stat with the current statistics of the daemon.
bool getMessageToConfirm(Swarm::Message &message, size_t id) const
Get a message to confirm by id if it exists.
void clearStat()
Clear all the statistics of the daemon.
void stop()
Stops the BaseDaemon.
BaseDaemon()
Default constructor of BaseDaemon.
void processConfirmedMessage(size_t id, time_t currentTime)
Process confirmed message.
bool parseArgument(int argc, char **argv)
Parse arguments given to the BaseDaemon with command line.
const Swarm::DaemonStatAccumulator & getDaemonStatAccumulator() const
Gets the daemonStatAccumulator of the DaemonConfig.
const std::map< PString, Swarm::StatAccumulator > & getMapStatComputing() const
Gets the mapStatComputing of the DaemonStatAccumulator.
const std::map< DaemonName, std::map< DataType, Swarm::StatAccumulator > > & getMapStatCommunication() const
Gets the mapStatCommunication of the DaemonStatAccumulator.
Basic Data exchanged in the swarm.
Message exchanged by Daemons.
void setData(const Swarm::Data &data)
Sets the data of the Message.
const std::vector< PString > & getVecRecver() const
Gets the vecRecver of the Message.
void setSendTime(const time_t &sendTime)
Sets the sendTime of the Message.
size_t getId() const
Gets the id of the Message.
void setId(size_t id)
Sets the id of the Message.
Accumulator of event occurence to build swarm statistics over a time period.
void setMin(float min)
Sets the min of the StatAccumulator.
float getSum() const
Gets the sum of the StatAccumulator.
void setVecHistogram(const std::vector< size_t > &vecHistogram)
Sets the vecHistogram of the StatAccumulator.
size_t getNbEvent() const
Gets the nbEvent of the StatAccumulator.
float getMax() const
Gets the max of the StatAccumulator.
size_t getNbEventAboveUpperBound() const
Gets the nbEventAboveUpperBound of the StatAccumulator.
float getMin() const
Gets the min of the StatAccumulator.
void setHistUpperBound(float histUpperBound)
Sets the histUpperBound of the StatAccumulator.
void setMax(float max)
Sets the max of the StatAccumulator.
void setNbEventAboveUpperBound(size_t nbEventAboveUpperBound)
Sets the nbEventAboveUpperBound of the StatAccumulator.
void setHistLowerBound(float histLowerBound)
Sets the histLowerBound of the StatAccumulator.
void setNbEventBelowLowerBound(size_t nbEventBelowLowerBound)
Sets the nbEventBelowLowerBound of the StatAccumulator.
void setSum(float sum)
Sets the sum of the StatAccumulator.
size_t getNbEventBelowLowerBound() const
Gets the nbEventBelowLowerBound of the StatAccumulator.
const std::vector< size_t > & getVecHistogram() const
Gets the vecHistogram of the StatAccumulator.
void setNbEvent(size_t nbEvent)
Sets the nbEvent of the StatAccumulator.
const std::map< DaemonName, std::map< DataType, Swarm::VecStat > > & getMapStatCommunication() const
Gets the mapStatCommunication of the Stat.
const std::map< PString, Swarm::VecStat > & getMapStatComputing() const
Gets the mapStatComputing of the Stat.
General statistics in the swarm.
const std::vector< float > & getMax() const
Gets the max of the VecStat.
const std::vector< time_t > & getEndTimestamp() const
Gets the endTimestamp of the VecStat.
const std::vector< float > & getRate() const
Gets the rate of the VecStat.
const std::vector< time_t > & getStartTimestamp() const
Gets the startTimestamp of the VecStat.
const std::vector< float > & getAverage() const
Gets the average of the VecStat.
const std::vector< float > & getRateEventBelowLowerBound() const
Gets the rateEventBelowLowerBound of the VecStat.
const std::vector< float > & getRateEventAboveUpperBound() const
Gets the rateEventAboveUpperBound of the VecStat.
const std::vector< float > & getMin() const
Gets the min of the VecStat.
const std::vector< size_t > & getNbEvent() const
Gets the nbEvent of the VecStat.
const std::vector< std::vector< float > > & getVecRateQuantile() const
Gets the vecRateQuantile of the VecStat.
VecStat fillVecStat(const Swarm::StatAccumulator &accumulator, time_t startTimestamp, time_t endTimestamp)
Fill a VecStat from a StatAccumulator to send to the DamonStat.
void fillDaemonStat(Swarm::Stat &stat, time_t startTimestamp, time_t endTimestamp)
Fill the Stat with the current statistics of the daemon.