PhoenixSwarm  5.1.1
Library to ease communication between daemons
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include <iostream>
8
9#include "swarm_mock_daemon.h"
10
12
16/*-----------------------------------
17Configuration:
18- localhost:3390 is the Recv mock file to stop the Daemon
19- localhost:3391 is the Send mock file to test the Daemon
20
21Workflow :
221. The 'main' SendDataDaemon sends an INT data to the 'test' Daemon.
232. As we are in mock mode, we check that the sent data are correctly serialized in the mock file.
243. The 'main' Daemon receives the data and process it (here we do nothing with it).
254. Finally, the 'main' Daemon is stopped by a STOP message from another daemon.
26
27+----------------+ +-----------------------------------+
28| main daemon |--- RESULT_DATA (INT=42)-->| Mock file (main_localhost_3391) |
29+----------------+ +-----------------------------------+
30 |
31 | <--- STOP message ---------------
32 |
33------------------------------------*/
34void createMockFileMainSend(const PString & hostName, size_t port, const PString & prefix){
35 PMockSocketGenerator::Socket mock;
36 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
37// PVecMockMessage vecOutput;
38 //Let's say, the main Daemon wants to call a function on test
39 Message message;
40 message.setId(1lu); //Anwser of the INT message
41 message.setSendTime(1lu);
42 message.setIsConfirmationNeeded(true);
43 message.setType(MessageType::RESULT_DATA);
44 message.setSender("main");
45 int data(42);
46 message.setData(phoenix_createData(data));
47 message.getVecRecver().push_back("test");
48 mock.sendData(message);
49}
50
52
56void createMockFileMainRecv(const PString & hostName, size_t port, const PString & prefix){
57 PMockSocketGenerator::Socket mock;
58 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
59
60 //Finally we stop the Daemon
61 Message messageStop;
62 messageStop.setId(2lu);
63 messageStop.setType(MessageType::STOP);
64 mock.sendData(messageStop);
65}
66
68
71void createDaemon(const PPath & fileName, const PString & daemonName){
72 //Let's create and start the Daemon
73 SendDataDaemon daemon;
74 daemon.setSocketMode(PSocketMode::MOCK);
75 daemon.setClockMode(PClockMode::MOCK);
76 daemon.getLog().setFileName(PPath("Daemon.log"));
77 daemon.load(fileName, daemonName);
78 phoenix_assert(daemon.run());
79}
80
82
84void testBaseDaemonLoadConfig(const PPath & fileName){
85 //Let's create the mock file
86 phoenix_createClockMock("main_", 4lu);
87 createMockFileMainRecv("localhost", 3390, "main_");
88 //No need to check the output of the messages sent by the Daemon, because the PMockSocketGenerator already does it for us
89 createMockFileMainSend("localhost", 3391, "main_");
90 //Let's create and start the Daemon
91 createDaemon(fileName, "main");
92}
93
94int main(int argc, char** argv){
95 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_TOML));
96 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_YAML));
97 return 0;
98}
99
100
void createDaemon(const PPath &fileName, const PString &daemonName)
Create a simple Daemon stat manager.
Definition main.cpp:109
int main(int argc, char **argv)
Definition main.cpp:127
void createMockFileMainRecv(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:70
void createMockFileMainSend(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:44
void testBaseDaemonLoadConfig(const PPath &fileName)
Test the load configuration of a Daemon.
Definition main.cpp:84
Swarm::Data phoenix_createData(const T &value)
Create a Data from a value.