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#include "swarm_mock_daemon.h"
9
10/*---------------------------------------------------------------------------------------
11Configuration:
12- localhost:3390 is the Recv mock file to stop the Daemon
13- localhost:3391 is the Send mock file to test the Daemon
14
15Workflow :
161. We mock the fact that the 'test' daemon sends two data (a Shadok and a Gibis) to the 'main' Daemon using the mock file 'main_localhost_3390'.
172. The main daemon is configured to have callable functions to process Shadok and Gibis data.
18So as we read a data from the mock file, it deserializes it and process it using the appropriate type.
193. The main daemon has also an extraLoopProcessing function that checks if the data received have the expected type (here one Shadok and one Gibis).
204. THen in the mock file 'main_localhost_3391', we mock the fact that the 'main' Daemon has sent a confirmation message for each data received.
215. Finally, the 'main' Daemon is stopped by a STOP message from another daemon
22
23+----------------+ +-----------------------------------+ +---------------------------------------+
24| main daemon | | Mock file (main_localhost_3390) | | Mock file (main_localhost_3391) |
25+----------------+ +-----------------------------------+ +---------------------------------------+
26 | | |
27 | <--- RESULT_DATA (Shadok)--------------| |
28 | | |
29 | --- MESSAGE_CONFIRMATION (Shadok) -----------------------------------------> |
30 | | |
31 | <--- RESULT_DATA (Gibis) --------------| |
32 | | |
33 | --- MESSAGE_CONFIRMATION (Gibis) ------------------------------------------> |
34 | | |
35 | <--- STOP message --------------- | |
36 | | |
37-----------------------------------------------------------------------------------------*/
38
40
44void createMockFileMainSend(const PString & hostName, size_t port, const PString & prefix){
45 PMockSocketGenerator::Socket mock;
46 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
47 PVecMockMessage vecOutput;
48 //At time 0, whe receive a confiramtion for the Shadok message sent
49 Message confirmationShadok;
50 confirmationShadok.setSendTime(0lu);
51 confirmationShadok.setId(1lu);
52 confirmationShadok.setSender("main");
53 confirmationShadok.setType(MessageType::MESSAGE_CONFIRMATION);
54 confirmationShadok.getVecRecver().push_back("test");
55 mock.sendData(confirmationShadok);
56
57 //At time 1, we receive a confirmation for the Gibis message sent
58 Message confirmationGibis;
59 confirmationGibis.setSendTime(1lu);
60 confirmationGibis.setId(2lu);
61 confirmationGibis.setSender("main");
62 confirmationGibis.setType(MessageType::MESSAGE_CONFIRMATION);
63 confirmationGibis.getVecRecver().push_back("test");
64 mock.sendData(confirmationGibis);
65}
66
68
70void createMockFileMainRecv(const PString & hostName, size_t port, const PString & prefix){
71 PMockSocketGenerator::Socket mock;
72 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
73
74 //We receive a Shadok message
75 Message shadokMsg;
76 shadokMsg.setId(1lu);
77 shadokMsg.setSendTime(0lu);
78 shadokMsg.setIsConfirmationNeeded(true);
79 shadokMsg.setType(MessageType::RESULT_DATA);
80 shadokMsg.setSender("test");
81 Shadok shadok("Bob", 42);
82 shadokMsg.setData(phoenix_createData(shadok));
83 shadokMsg.getVecRecver().push_back("main");
84 mock.sendData(shadokMsg);
85
86 //We receive a Gibis message
87 Message gibisMsg;
88 gibisMsg.setId(2lu);
89 gibisMsg.setSendTime(1lu);
90 gibisMsg.setIsConfirmationNeeded(true);
91 gibisMsg.setType(MessageType::RESULT_DATA);
92 gibisMsg.setSender("test");
93 Gibis gibis("Red", 100);
94 gibisMsg.setData(phoenix_createData(gibis));
95 gibisMsg.getVecRecver().push_back("main");
96 mock.sendData(gibisMsg);
97
98 //Finally we stop the Daemon
99 Message messageStop;
100 messageStop.setId(3lu);
101 messageStop.setType(MessageType::STOP);
102 mock.sendData(messageStop);
103}
104
106
109void createDaemon(const PPath & fileName, const PString & daemonName){
110 RecvDataDaemon daemon;
111 daemon.setSocketMode(PSocketMode::MOCK);
112 daemon.setClockMode(PClockMode::MOCK);
113 phoenix_assert(daemon.load(fileName, daemonName));
114 phoenix_assert(daemon.run());
115}
116
118
120void testMonitoring(const PPath & fileName){
121 phoenix_createClockMock("main_", 4lu);
122 createMockFileMainSend("localhost", 3391lu, "main_");
123 createMockFileMainRecv("localhost", 3390, "main_");
124 createDaemon(fileName, "main");
125}
126
127int main(int argc, char** argv){
128 testMonitoring(PPath(DAEMON_CONFIG_OK));
129 return 0;
130}
131
132
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 testMonitoring(const PPath &fileName)
Test a simple Daemon stat manager.
Definition main.cpp:120
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
@ MESSAGE_CONFIRMATION
Definition MessageType.h:20
Swarm::Data phoenix_createData(const T &value)
Create a Data from a value.