PhoenixSwarm  5.1.1
Library to ease communication between daemons
Loading...
Searching...
No Matches
main.cpp File Reference
#include <iostream>
#include "phoenix_assert.h"
#include "BaseDaemon.h"
#include "Representation.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

class  TestBaseDaemon
 Test Daemon. More...
 

Functions

StatAccumulator createTestStatAccumulator ()
 Create stat accumulator.
 
int main (int argc, char **argv)
 
void testBaseDaemonGetMessageToConfirm ()
 Get a BaseDaemon with a message to confirm.
 
void testBaseDaemonLoadConfigJson (const PPath &fileName)
 Test the load configuration of a BaseDaemon.
 
void testBaseDaemonLoadConfigJsonString (const PPath &fileName)
 Test the load configuration of a BaseDaemon from a JSON string.
 
void testBaseDaemonLoadConfigToml (const PPath &fileName)
 Test the load configuration of a BaseDaemon.
 
void testBaseDaemonLoadConfigTomlString (const PPath &fileName)
 Test the load configuration of a BaseDaemon from a string TOML.
 
void testBaseDaemonLoadConfigYml (const PPath &fileName)
 Test the load configuration of a BaseDaemon.
 
void testBaseDaemonLoadConfigYmlString (const PPath &fileName)
 Test the load configuration of a BaseDaemon from a string YAML.
 
void testBaseDaemonMissingDaemonSectionJsonFile ()
 Test BaseDaemon with missing daemon section in JSON file.
 
void testBaseDaemonMissingDaemonSectionJsonString ()
 Test BaseDaemon with missing daemon section in JSON string config.
 
void testBaseDaemonMissingDaemonSectionTomlFile ()
 Test BaseDaemon with missing daemon section in TOML file.
 
void testBaseDaemonMissingDaemonSectionTomlString ()
 Test BaseDaemon with missing daemon section in TOML string config.
 
void testBaseDaemonMissingDaemonSectionYmlFile ()
 Test BaseDaemon with missing daemon section in YML file.
 
void testBaseDaemonMissingDaemonSectionYmlString ()
 Test BaseDaemon with missing daemon section in YAML string config.
 
void testBaseDaemonParseArgument (const char *configFile, const char *daemonName)
 Test the parse argument of a BaseDaemon.
 
void testBaseDaemonProcessConfirmedMessage (const PPath &fileName)
 Test BaseDaemon with a message to process.
 
void testClearStatAccumulator ()
 Test the clear of StatAccumulator in BaseDaemon.
 
void testFillDaemonStat ()
 Test the fill of Daemon stats.
 
void testFillVecStat ()
 Test the fill vector of stats.
 
void testUpdateStatAccumulator ()
 Test the update of a StatAccumulator.
 

Function Documentation

◆ createTestStatAccumulator()

StatAccumulator createTestStatAccumulator ( )

Create stat accumulator.

Returns
StatAccumulator

Definition at line 304 of file main.cpp.

304 {
305 StatAccumulator stat;
306 stat.setNbEvent(4lu);
307 stat.setMin(2.0f);
308 stat.setMax(8.0f);
309 stat.setSum(20.0f);
312 stat.setHistLowerBound(0.0f);
313 stat.setHistUpperBound(10.0f);
314 stat.setVecHistogram(std::vector<size_t>(5, 0lu));
315 stat.getVecHistogram()[1] = 1lu; //bin for 2.0
316 stat.getVecHistogram()[4] = 1lu; //bin for 8.0
317 return stat;
318}
Accumulator of event occurence to build swarm statistics over a time period.
void setMin(float min)
Sets the min of the StatAccumulator.
void setVecHistogram(const std::vector< size_t > &vecHistogram)
Sets the vecHistogram 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.
const std::vector< size_t > & getVecHistogram() const
Gets the vecHistogram of the StatAccumulator.
void setNbEvent(size_t nbEvent)
Sets the nbEvent of the StatAccumulator.

References Swarm::StatAccumulator::getVecHistogram(), Swarm::StatAccumulator::setHistLowerBound(), Swarm::StatAccumulator::setHistUpperBound(), Swarm::StatAccumulator::setMax(), Swarm::StatAccumulator::setMin(), Swarm::StatAccumulator::setNbEvent(), Swarm::StatAccumulator::setNbEventAboveUpperBound(), Swarm::StatAccumulator::setNbEventBelowLowerBound(), Swarm::StatAccumulator::setSum(), and Swarm::StatAccumulator::setVecHistogram().

Referenced by testFillDaemonStat(), and testFillVecStat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 373 of file main.cpp.

373 {
374
378
382
383 testBaseDaemonLoadConfigToml(PPath(DAEMON_CONFIG_OK_TOML));
384 testBaseDaemonLoadConfigTomlString(PPath(DAEMON_CONFIG_OK_TOML));
385 testBaseDaemonLoadConfigYml(PPath(DAEMON_CONFIG_OK_YAML));
386 testBaseDaemonLoadConfigYmlString(PPath(DAEMON_CONFIG_OK_YAML));
387 testBaseDaemonLoadConfigJson(PPath(DAEMON_CONFIG_OK_JSON));
388 testBaseDaemonLoadConfigJsonString(PPath(DAEMON_CONFIG_OK_JSON));
389 testBaseDaemonParseArgument(DAEMON_CONFIG_OK_TOML, "main");
390 testBaseDaemonProcessConfirmedMessage(PPath(DAEMON_CONFIG_OK_TOML));
396 return 0;
397}
void testBaseDaemonGetMessageToConfirm()
Get a BaseDaemon with a message to confirm.
Definition main.cpp:15
void testBaseDaemonLoadConfigYml(const PPath &fileName)
Test the load configuration of a BaseDaemon.
Definition main.cpp:163
void testBaseDaemonLoadConfigJson(const PPath &fileName)
Test the load configuration of a BaseDaemon.
Definition main.cpp:191
void testBaseDaemonMissingDaemonSectionTomlString()
Test BaseDaemon with missing daemon section in TOML string config.
Definition main.cpp:52
void testFillVecStat()
Test the fill vector of stats.
Definition main.cpp:328
void testBaseDaemonParseArgument(const char *configFile, const char *daemonName)
Test the parse argument of a BaseDaemon.
Definition main.cpp:220
void testUpdateStatAccumulator()
Test the update of a StatAccumulator.
Definition main.cpp:234
void testFillDaemonStat()
Test the fill of Daemon stats.
Definition main.cpp:355
void testBaseDaemonMissingDaemonSectionYmlString()
Test BaseDaemon with missing daemon section in YAML string config.
Definition main.cpp:66
void testBaseDaemonLoadConfigToml(const PPath &fileName)
Test the load configuration of a BaseDaemon.
Definition main.cpp:137
void testBaseDaemonProcessConfirmedMessage(const PPath &fileName)
Test BaseDaemon with a message to process.
Definition main.cpp:34
void testBaseDaemonLoadConfigYmlString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a string YAML.
Definition main.cpp:178
void testBaseDaemonMissingDaemonSectionTomlFile()
Test BaseDaemon with missing daemon section in TOML file.
Definition main.cpp:95
void testBaseDaemonLoadConfigJsonString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a JSON string.
Definition main.cpp:206
void testBaseDaemonMissingDaemonSectionJsonFile()
Test BaseDaemon with missing daemon section in JSON file.
Definition main.cpp:121
void testClearStatAccumulator()
Test the clear of StatAccumulator in BaseDaemon.
Definition main.cpp:265
void testBaseDaemonMissingDaemonSectionJsonString()
Test BaseDaemon with missing daemon section in JSON string config.
Definition main.cpp:80
void testBaseDaemonMissingDaemonSectionYmlFile()
Test BaseDaemon with missing daemon section in YML file.
Definition main.cpp:108
void testBaseDaemonLoadConfigTomlString(const PPath &fileName)
Test the load configuration of a BaseDaemon from a string TOML.
Definition main.cpp:150

References testBaseDaemonGetMessageToConfirm(), testBaseDaemonLoadConfigJson(), testBaseDaemonLoadConfigJsonString(), testBaseDaemonLoadConfigToml(), testBaseDaemonLoadConfigTomlString(), testBaseDaemonLoadConfigYml(), testBaseDaemonLoadConfigYmlString(), testBaseDaemonMissingDaemonSectionJsonFile(), testBaseDaemonMissingDaemonSectionJsonString(), testBaseDaemonMissingDaemonSectionTomlFile(), testBaseDaemonMissingDaemonSectionTomlString(), testBaseDaemonMissingDaemonSectionYmlFile(), testBaseDaemonMissingDaemonSectionYmlString(), testBaseDaemonParseArgument(), testBaseDaemonProcessConfirmedMessage(), testClearStatAccumulator(), testFillDaemonStat(), testFillVecStat(), and testUpdateStatAccumulator().

+ Here is the call graph for this function:

◆ testBaseDaemonGetMessageToConfirm()

void testBaseDaemonGetMessageToConfirm ( )

Get a BaseDaemon with a message to confirm.

Definition at line 15 of file main.cpp.

15 {
16 BaseDaemon daemon;
17 Message msg;
18 msg.setId(123);
19 msg.setSendTime(time(nullptr));
20 msg.getVecRecver().push_back("receiver1");
21 daemon.addMessageToConfirm(msg);
22
23 Message retrieved;
24 phoenix_assert(daemon.getMessageToConfirm(retrieved, 123));
25 phoenix_assert(retrieved.getId() == 123);
26
27 Message notFound;
28 phoenix_assert(!daemon.getMessageToConfirm(notFound, 999));
29}
Daemon which help communication between processes and thread.
Definition BaseDaemon.h:54
void addMessageToConfirm(const Swarm::Message &message)
Add a message to confirm.
bool getMessageToConfirm(Swarm::Message &message, size_t id) const
Get a message to confirm by id if it exists.
Message exchanged by Daemons.
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.

References Swarm::BaseDaemon::addMessageToConfirm(), Swarm::Message::getId(), Swarm::BaseDaemon::getMessageToConfirm(), Swarm::Message::getVecRecver(), Swarm::Message::setId(), and Swarm::Message::setSendTime().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigJson()

void testBaseDaemonLoadConfigJson ( const PPath & fileName)

Test the load configuration of a BaseDaemon.

Parameters
fileName: name of the configuration json file

Definition at line 191 of file main.cpp.

191 {
192 BaseDaemon daemon;
193 phoenix_assert(daemon.load(fileName, "main"));
194 phoenix_assert(daemon.isDaemonExist("other"));
195 BaseDaemon daemon2;
196 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(fileName, "not_in_in_the_list"));
197 BaseDaemon daemon3;
198 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ParserException, daemon3.load(PPath("unexisting_config.json"), "main"));
199 BaseDaemon daemon4;
200 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ParserException, daemon4.load(PPath("file.nonextension"), "main"));
201}
Exception for daemon configuration errors.
Exception for configuration errors.
bool isDaemonExist(const PString &name) const
Say if a neighbour Daemon does exist.
bool load(const PString &configFileContent, const PString &daemonName, ConfigFormat::ConfigFormat format)
Load the Json configuration which define all BaseDaemons of the Swarm.

References Swarm::BaseDaemon::isDaemonExist(), and Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigJsonString()

void testBaseDaemonLoadConfigJsonString ( const PPath & fileName)

Test the load configuration of a BaseDaemon from a JSON string.

Parameters
fileName: nom du fichier de configuration JSON

Definition at line 206 of file main.cpp.

206 {
207 // Read json file in a string
208 PString jsonString = fileName.loadFileContent();
209 BaseDaemon daemon;
210 daemon.load(jsonString, "main", ConfigFormat::JSON);
211 phoenix_assert(daemon.isDaemonExist("other"));
212 BaseDaemon daemon2;
213 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(jsonString, "not_in_in_the_list", ConfigFormat::JSON));
214}

References Swarm::BaseDaemon::isDaemonExist(), ConfigFormat::JSON, and Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigToml()

void testBaseDaemonLoadConfigToml ( const PPath & fileName)

Test the load configuration of a BaseDaemon.

Parameters
fileName: name of the configuration toml file

Definition at line 137 of file main.cpp.

137 {
138 BaseDaemon daemon;
139 daemon.load(fileName, "main");
140 phoenix_assert(daemon.isDaemonExist("other"));
141 BaseDaemon daemon2;
142 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(fileName, "not_in_in_the_list"));
143 BaseDaemon daemon3;
144 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ParserException, daemon3.load(PPath("unexisting_config.toml"), "main"));
145}

References Swarm::BaseDaemon::isDaemonExist(), and Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigTomlString()

void testBaseDaemonLoadConfigTomlString ( const PPath & fileName)

Test the load configuration of a BaseDaemon from a string TOML.

Parameters
fileName: name of the configuration TOML file

Definition at line 150 of file main.cpp.

150 {
151 // Read toml file in a string
152 PString tomlString = fileName.loadFileContent();
153 BaseDaemon daemon;
154 daemon.load(tomlString, "main", ConfigFormat::TOML);
155 phoenix_assert(daemon.isDaemonExist("other"));
156 BaseDaemon daemon2;
157 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(tomlString, "not_in_in_the_list", ConfigFormat::TOML));
158}

References Swarm::BaseDaemon::isDaemonExist(), Swarm::BaseDaemon::load(), and ConfigFormat::TOML.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigYml()

void testBaseDaemonLoadConfigYml ( const PPath & fileName)

Test the load configuration of a BaseDaemon.

Parameters
fileName: name of the configuration yml file

Definition at line 163 of file main.cpp.

163 {
164 BaseDaemon daemon;
165 daemon.load(fileName, "main");
166 phoenix_assert(daemon.isDaemonExist("other"));
167 BaseDaemon daemon2;
168 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(fileName, "not_in_in_the_list"));
169 BaseDaemon daemon3;
170 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ParserException, daemon3.load(PPath("unexisting_config.yml"), "main"));
171 BaseDaemon daemon4;
172 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ParserException, daemon4.load(PPath("file.nonextension"), "main"));
173}

References Swarm::BaseDaemon::isDaemonExist(), and Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonLoadConfigYmlString()

void testBaseDaemonLoadConfigYmlString ( const PPath & fileName)

Test the load configuration of a BaseDaemon from a string YAML.

Parameters
fileName: name of the configuration YAML file

Definition at line 178 of file main.cpp.

178 {
179 // Read yaml file in a string
180 PString ymlString = fileName.loadFileContent();
181 BaseDaemon daemon;
182 daemon.load(ymlString, "main", ConfigFormat::YAML);
183 phoenix_assert(daemon.isDaemonExist("other"));
184 BaseDaemon daemon2;
185 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon2.load(ymlString, "not_in_in_the_list", ConfigFormat::YAML));
186}

References Swarm::BaseDaemon::isDaemonExist(), Swarm::BaseDaemon::load(), and ConfigFormat::YAML.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionJsonFile()

void testBaseDaemonMissingDaemonSectionJsonFile ( )

Test BaseDaemon with missing daemon section in JSON file.

Definition at line 121 of file main.cpp.

121 {
122 PPath tempFile = PPath("test_no_daemon_section.json");
123 PString invalidJsonConfig = R"({
124"other_section": {
125 "name": "test",
126 "value": 42
127}
128})";
129 tempFile.saveFileContent(invalidJsonConfig);
130 BaseDaemon daemon;
131 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(tempFile, "main"));
132}

References Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionJsonString()

void testBaseDaemonMissingDaemonSectionJsonString ( )

Test BaseDaemon with missing daemon section in JSON string config.

Definition at line 80 of file main.cpp.

80 {
81 PString invalidJsonConfig = R"({
82"other_section": {
83 "name": "test",
84 "value": 42
85},
86"another_section": {
87 "host": "localhost"
88}
89})";
90 BaseDaemon daemon;
91 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(invalidJsonConfig, "main", ConfigFormat::JSON));
92}

References ConfigFormat::JSON, and Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionTomlFile()

void testBaseDaemonMissingDaemonSectionTomlFile ( )

Test BaseDaemon with missing daemon section in TOML file.

Definition at line 95 of file main.cpp.

95 {
96 PPath tempFile = PPath("test_no_daemon_section.toml");
97 PString invalidTomlConfig = R"(
98[other_section]
99name = "test"
100value = 42
101)";
102 tempFile.saveFileContent(invalidTomlConfig);
103 BaseDaemon daemon;
104 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(tempFile, "main"));
105}

References Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionTomlString()

void testBaseDaemonMissingDaemonSectionTomlString ( )

Test BaseDaemon with missing daemon section in TOML string config.

Definition at line 52 of file main.cpp.

52 {
53 PString invalidTomlConfig = R"(
54[other_section]
55name = "test"
56value = 42
57
58[another_section]
59host = "localhost"
60)";
61 BaseDaemon daemon;
62 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(invalidTomlConfig, "main", ConfigFormat::TOML));
63}

References Swarm::BaseDaemon::load(), and ConfigFormat::TOML.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionYmlFile()

void testBaseDaemonMissingDaemonSectionYmlFile ( )

Test BaseDaemon with missing daemon section in YML file.

Definition at line 108 of file main.cpp.

108 {
109 PPath tempFile = PPath("test_no_daemon_section.yml");
110 PString invalidYmlConfig = R"(
111other_section:
112 name: "test"
113 value: 42
114)";
115 tempFile.saveFileContent(invalidYmlConfig);
116 BaseDaemon daemon;
117 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(tempFile, "main"));
118}

References Swarm::BaseDaemon::load().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonMissingDaemonSectionYmlString()

void testBaseDaemonMissingDaemonSectionYmlString ( )

Test BaseDaemon with missing daemon section in YAML string config.

Definition at line 66 of file main.cpp.

66 {
67 PString invalidYmlConfig = R"(
68other_section:
69 name: "test"
70 value: 42
71
72another_section:
73 host: "localhost"
74)";
75 BaseDaemon daemon;
76 PHOENIX_EXCEPTION_TYPE_ASSERT(Phoenix::ConfigException, daemon.load(invalidYmlConfig, "main", ConfigFormat::YAML));
77}

References Swarm::BaseDaemon::load(), and ConfigFormat::YAML.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonParseArgument()

void testBaseDaemonParseArgument ( const char * configFile,
const char * daemonName )

Test the parse argument of a BaseDaemon.

Parameters
configFile: name of the configuration file
daemonName: name of the daemon to load

Definition at line 220 of file main.cpp.

220 {
221 const char* argv[] = {
222 "phoenix_daemon",
223 "--daemonconfig", configFile,
224 "--daemonname", daemonName
225 };
226 int argc = sizeof(argv) / sizeof(argv[0]);
227 BaseDaemon daemon;
228 phoenix_assert(daemon.parseArgument(argc, const_cast<char**>(argv)));
229 daemon.stop();
230 phoenix_assert(daemon.isDaemonExist("other"));
231}
void stop()
Stops the BaseDaemon.
bool parseArgument(int argc, char **argv)
Parse arguments given to the BaseDaemon with command line.

References Swarm::BaseDaemon::isDaemonExist(), Swarm::BaseDaemon::parseArgument(), and Swarm::BaseDaemon::stop().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBaseDaemonProcessConfirmedMessage()

void testBaseDaemonProcessConfirmedMessage ( const PPath & fileName)

Test BaseDaemon with a message to process.

Parameters
fileName: configuration of the Daemon

Definition at line 34 of file main.cpp.

34 {
35 BaseDaemon daemon;
36 daemon.load(fileName, "main");
37
38 Message msg;
39 msg.setId(456);
40 msg.setSendTime(3lu);
41 msg.setData(Data());
42 msg.getVecRecver().push_back("receiver2");
43 daemon.addMessageToConfirm(msg);
44
45 // Confirm the message
46 daemon.processConfirmedMessage(456, 5lu);
47 Message shouldNotExist;
48 phoenix_assert(!daemon.getMessageToConfirm(shouldNotExist, 456));
49}
void processConfirmedMessage(size_t id, time_t currentTime)
Process confirmed message.
Basic Data exchanged in the swarm.
void setData(const Swarm::Data &data)
Sets the data of the Message.

References Swarm::BaseDaemon::addMessageToConfirm(), Swarm::BaseDaemon::getMessageToConfirm(), Swarm::Message::getVecRecver(), Swarm::BaseDaemon::load(), Swarm::BaseDaemon::processConfirmedMessage(), Swarm::Message::setData(), Swarm::Message::setId(), and Swarm::Message::setSendTime().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testClearStatAccumulator()

void testClearStatAccumulator ( )

Test the clear of StatAccumulator in BaseDaemon.

Definition at line 265 of file main.cpp.

265 {
266 BaseDaemon daemon;
267 StatAccumulator stat;
268 stat.setHistLowerBound(0.0f);
269 stat.setHistUpperBound(10.0f);
270 stat.setVecHistogram(std::vector<size_t>(5, 0lu)); //5 bins
271
272 daemon.getConfig().getDaemonStatAccumulator().getMapStatComputing()["stat_name"] = stat;
273 daemon.getConfig().getDaemonStatAccumulator().getMapStatCommunication()["daemon_name"]["stat_name"] = stat;
274
275 phoenix_assert(!daemon.getConfig().getDaemonStatAccumulator().getMapStatComputing().empty());
276 phoenix_assert(!daemon.getConfig().getDaemonStatAccumulator().getMapStatCommunication().empty());
277
278 daemon.clearStat();
279 for(MapStatAccumulator::const_iterator it = daemon.getConfig().getDaemonStatAccumulator().getMapStatComputing().begin();
280 it != daemon.getConfig().getDaemonStatAccumulator().getMapStatComputing().end(); ++it)
281 {
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);
286 }
287 }
288 for(MapDaemonStatAccumulator::const_iterator itMap = daemon.getConfig().getDaemonStatAccumulator().getMapStatCommunication().begin();
289 itMap != daemon.getConfig().getDaemonStatAccumulator().getMapStatCommunication().end(); ++itMap)
290 {
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);
296 }
297 }
298 }
299}
DaemonConfig & getConfig()
Get the configuration of the current BaseDaemon.
void clearStat()
Clear all the statistics of the daemon.
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.

References Swarm::BaseDaemon::clearStat(), Swarm::BaseDaemon::getConfig(), Swarm::DaemonConfig::getDaemonStatAccumulator(), Swarm::DaemonStatAccumulator::getMapStatCommunication(), Swarm::DaemonStatAccumulator::getMapStatComputing(), Swarm::StatAccumulator::setHistLowerBound(), Swarm::StatAccumulator::setHistUpperBound(), and Swarm::StatAccumulator::setVecHistogram().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testFillDaemonStat()

void testFillDaemonStat ( )

Test the fill of Daemon stats.

Definition at line 355 of file main.cpp.

355 {
356 TestBaseDaemon daemon;
358 daemon.getConfig().getDaemonStatAccumulator().getMapStatComputing()["stat1"] = stat1;
360 daemon.getConfig().getDaemonStatAccumulator().getMapStatCommunication()["other"]["stat2"] = stat2;
361
362 Stat daemonStat;
363 time_t startTime = 1000lu;
364 time_t endTime = 2000lu;
365 daemon.fillDaemonStat(daemonStat, startTime, endTime);
366
367 phoenix_assert(daemonStat.getMapStatComputing().find("stat1") != daemonStat.getMapStatComputing().end());
368 phoenix_assert(daemonStat.getMapStatCommunication().find("other") != daemonStat.getMapStatCommunication().end());
369 phoenix_assert(daemonStat.getMapStatCommunication()["other"].find("stat2") != daemonStat.getMapStatCommunication()["other"].end());
370 phoenix_assert(daemonStat.getMapStatComputing().find("bad_stat") == daemonStat.getMapStatComputing().end());
371}
StatAccumulator createTestStatAccumulator()
Create stat accumulator.
Definition main.cpp:304
Statistics of a Daemon.
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.
Test Daemon.
Definition main.cpp:321
void fillDaemonStat(Swarm::Stat &stat, time_t startTimestamp, time_t endTimestamp)
Fill the Stat with the current statistics of the daemon.

References createTestStatAccumulator(), TestBaseDaemon::fillDaemonStat(), Swarm::BaseDaemon::getConfig(), Swarm::DaemonConfig::getDaemonStatAccumulator(), Swarm::DaemonStatAccumulator::getMapStatCommunication(), Swarm::Stat::getMapStatCommunication(), Swarm::DaemonStatAccumulator::getMapStatComputing(), and Swarm::Stat::getMapStatComputing().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testFillVecStat()

void testFillVecStat ( )

Test the fill vector of stats.

Definition at line 328 of file main.cpp.

328 {
329 TestBaseDaemon daemon;
331 time_t startTime = 1000lu;
332 time_t endTime = 2000lu;
333
334 VecStat vecStat = daemon.fillVecStat(stat, startTime, endTime);
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); //20.0 / 4
343
344 phoenix_assert(vecStat.getStartTimestamp().size() == 1lu);
345 phoenix_assert(vecStat.getStartTimestamp()[0] == startTime);
346 phoenix_assert(vecStat.getEndTimestamp().size() == 1lu);
347 phoenix_assert(vecStat.getEndTimestamp()[0] == endTime);
348 phoenix_assert(vecStat.getRate().size() == 1lu);
349 phoenix_assert(vecStat.getRateEventBelowLowerBound().size() == 1lu);
350 phoenix_assert(vecStat.getRateEventAboveUpperBound().size() == 1lu);
351 phoenix_assert(vecStat.getVecRateQuantile().size() == 5lu);
352}
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.

References createTestStatAccumulator(), TestBaseDaemon::fillVecStat(), Swarm::VecStat::getAverage(), Swarm::VecStat::getEndTimestamp(), Swarm::VecStat::getMax(), Swarm::VecStat::getMin(), Swarm::VecStat::getNbEvent(), Swarm::VecStat::getRate(), Swarm::VecStat::getRateEventAboveUpperBound(), Swarm::VecStat::getRateEventBelowLowerBound(), Swarm::VecStat::getStartTimestamp(), and Swarm::VecStat::getVecRateQuantile().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testUpdateStatAccumulator()

void testUpdateStatAccumulator ( )

Test the update of a StatAccumulator.

Definition at line 234 of file main.cpp.

234 {
235 BaseDaemon daemon;
236 StatAccumulator stat;
237 stat.setHistLowerBound(0.0f);
238 stat.setHistUpperBound(10.0f);
239 stat.setVecHistogram(std::vector<size_t>(5, 0lu)); //5 bins
240
241 daemon.updateStatAccumulator(stat, 2.0f);
242 phoenix_assert(stat.getNbEvent() == 1lu);
243 phoenix_assert(stat.getMin() == 2.0f);
244 phoenix_assert(stat.getMax() == 2.0f);
245 phoenix_assert(stat.getSum() == 2.0f);
246 phoenix_assert(stat.getVecHistogram()[1] == 1lu); //bin size = 2.0, so 2.0 goes to bin 1
247
248 daemon.updateStatAccumulator(stat, 8.0f);
249 phoenix_assert(stat.getNbEvent() == 2lu);
250 phoenix_assert(stat.getMin() == 2.0f);
251 phoenix_assert(stat.getMax() == 8.0f);
252 phoenix_assert(stat.getSum() == 10.0f);
253 phoenix_assert(stat.getVecHistogram()[4] == 1lu); //8.0 goes to bin 4
254
255 daemon.updateStatAccumulator(stat, -1.0f); //below lower bound
256 phoenix_assert(stat.getNbEvent() == 3lu);
257 phoenix_assert(stat.getNbEventBelowLowerBound() == 1lu);
258
259 daemon.updateStatAccumulator(stat, 12.0f); //above upper bound
260 phoenix_assert(stat.getNbEvent() == 4lu);
261 phoenix_assert(stat.getNbEventAboveUpperBound() == 1lu);
262}
void updateStatAccumulator(StatAccumulator &stat, float value)
Update a computing statistic with a new value.
float getSum() const
Gets the sum 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.
size_t getNbEventBelowLowerBound() const
Gets the nbEventBelowLowerBound of the StatAccumulator.

References Swarm::StatAccumulator::getMax(), Swarm::StatAccumulator::getMin(), Swarm::StatAccumulator::getNbEvent(), Swarm::StatAccumulator::getNbEventAboveUpperBound(), Swarm::StatAccumulator::getNbEventBelowLowerBound(), Swarm::StatAccumulator::getSum(), Swarm::StatAccumulator::getVecHistogram(), Swarm::StatAccumulator::setHistLowerBound(), Swarm::StatAccumulator::setHistUpperBound(), Swarm::StatAccumulator::setVecHistogram(), and Swarm::BaseDaemon::updateStatAccumulator().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: