hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCETaskRequestsTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include "DRCEError.hpp"
4 #include "DRCEPrintStatus.hpp"
10 #include "DRCETaskRequestsTest.hpp"
13 
14 namespace HCE
15 {
16 namespace drce
17 {
18 namespace tests
19 {
20 //-----------------------------------------------------------------------------
22 {
23  std::string json = "{\"session\":{\"type\":5,\"tmode\":1,\"time_max\":750,\"port\":8080,\"user\":\"admin\",\"password\":\"42\",\"shell\":\"bash\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"sort\",\"input\":\"def\\nabc\\n123\\n\",\"files\":[{\"name\":\"file1\",\"data\":\"test content of file1\\n\",\"action\":13},{\"name\":\"file2\",\"data\":\"test content of file2\\n\",\"action\":1}]}";
24 
25  DRCETaskRequestSetExecute taskRequestSetExecute(json);
26  ASSERT_FALSE(taskRequestSetExecute.isError());
27  ASSERT_EQ(taskRequestSetExecute.getErrorCode(), NO_ERROR);
28  ASSERT_TRUE(taskRequestSetExecute.getErrorMsg().empty());
29  ASSERT_EQ(taskRequestSetExecute.getCommandLine(), "sort");
30  ASSERT_EQ(taskRequestSetExecute.getInputStream(), "def\nabc\n123\n");
31  ASSERT_EQ(static_cast<unsigned int>(taskRequestSetExecute.getSessionOptions().sessionType), 5);
32  ASSERT_EQ(static_cast<unsigned int>(taskRequestSetExecute.getSessionOptions().tmode), 1);
33  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().port, 8080);
34  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().userName, "admin");
35  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().userPassword, "42");
36  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().shellName, "bash");
37  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().timeMax, 750);
38  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().environments.size(), 2);
39  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().environments[0].first, "HOSTNAME");
40  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().environments[0].second, "node22");
41  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().environments[1].first, "LINES");
42  ASSERT_EQ(taskRequestSetExecute.getSessionOptions().environments[1].second, "80");
43  ASSERT_EQ(taskRequestSetExecute.getFilesCount(), 2);
44  ASSERT_EQ(taskRequestSetExecute.getFileItem(0).actionType, 13);
45  ASSERT_EQ(taskRequestSetExecute.getFileItem(0).name, "file1");
46  ASSERT_EQ(taskRequestSetExecute.getFileItem(0).data, "test content of file1\n");
47  ASSERT_EQ(taskRequestSetExecute.getFileItem(1).actionType, 1);
48  ASSERT_EQ(taskRequestSetExecute.getFileItem(1).name, "file2");
49  ASSERT_EQ(taskRequestSetExecute.getFileItem(1).data, "test content of file2\n");
50  printSuccess("Unserialize DRCETaskRequestSetExecute");
51 
52  std::string newJson;
53  ASSERT_TRUE(taskRequestSetExecute.serialize(newJson));
54  ASSERT_FALSE(taskRequestSetExecute.isError());
55  ASSERT_EQ(taskRequestSetExecute.getErrorCode(), NO_ERROR);
56  ASSERT_TRUE(taskRequestSetExecute.getErrorMsg().empty());
57  printSuccess("Serialize DRCETaskRequestSetExecute");
58 
59  DRCETaskRequestSetExecute taskRequestSetExecuteRes(newJson);
60  ASSERT_FALSE(taskRequestSetExecuteRes.isError());
61  ASSERT_EQ(taskRequestSetExecuteRes.getErrorCode(), NO_ERROR);
62  ASSERT_TRUE(taskRequestSetExecuteRes.getErrorMsg().empty());
63  ASSERT_EQ(taskRequestSetExecuteRes.getCommandLine(), "sort");
64  ASSERT_EQ(taskRequestSetExecuteRes.getInputStream(), "def\nabc\n123\n");
65  ASSERT_EQ(static_cast<unsigned int>(taskRequestSetExecuteRes.getSessionOptions().sessionType), 5);
66  ASSERT_EQ(static_cast<unsigned int>(taskRequestSetExecuteRes.getSessionOptions().tmode), 1);
67  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().port, 8080);
68  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().userName, "admin");
69  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().userPassword, "42");
70  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().shellName, "bash");
71  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().timeMax, 750);
72  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().environments.size(), 2);
73  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().environments[0].first, "HOSTNAME");
74  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().environments[0].second, "node22");
75  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().environments[1].first, "LINES");
76  ASSERT_EQ(taskRequestSetExecuteRes.getSessionOptions().environments[1].second, "80");
77  ASSERT_EQ(taskRequestSetExecuteRes.getFilesCount(), 2);
78  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(0).actionType, 13);
79  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(0).name, "file1");
80  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(0).data, "test content of file1\n");
81  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(1).actionType, 1);
82  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(1).name, "file2");
83  ASSERT_EQ(taskRequestSetExecuteRes.getFileItem(1).data, "test content of file2\n");
84  printSuccess("Test Serialize/Unserialize SetTaskToExecuteRequest");
85 }
86 //-----------------------------------------------------------------------------
88 {
89  std::string json;
90  DRCETaskRequestCheckState taskRequestCheckState;
91  taskRequestCheckState.setCheckType(DRCETaskRequestCheckState::CheckType::ctExtended);
92  ASSERT_TRUE(taskRequestCheckState.serialize(json));
93  ASSERT_FALSE(taskRequestCheckState.isError());
94  ASSERT_EQ(taskRequestCheckState.getErrorCode(), NO_ERROR);
95  ASSERT_TRUE(taskRequestCheckState.getErrorMsg().empty());
96  printSuccess("DRCETaskRequestCheckState serialize");
97 
98  DRCETaskRequestCheckState taskRequestCheckStateRes(json);
99  ASSERT_FALSE(taskRequestCheckStateRes.isError());
100  ASSERT_EQ(taskRequestCheckStateRes.getErrorCode(), NO_ERROR);
101  ASSERT_TRUE(taskRequestCheckStateRes.getErrorMsg().empty());
102  printSuccess("DRCETaskRequestCheckState unserialize");
103 
104  ASSERT_EQ(taskRequestCheckState.getCheckType(), taskRequestCheckStateRes.getCheckType());
105  printSuccess("Test Serialize/Unserialize DRCETaskRequestSetExecute");
106 }
107 //-----------------------------------------------------------------------------
109 {
110  std::string json;
111  DRCETaskRequestGetData taskRequestGetData;
112  taskRequestGetData.setFetchType(DRCETaskRequestGetData::FetchType::ftNotDeleteDataAfterFetch);
113  ASSERT_TRUE(taskRequestGetData.serialize(json));
114  ASSERT_FALSE(taskRequestGetData.isError());
115  ASSERT_EQ(taskRequestGetData.getErrorCode(), NO_ERROR);
116  ASSERT_TRUE(taskRequestGetData.getErrorMsg().empty());
117  printSuccess("DRCETaskRequestGetData serialize");
118 
119  DRCETaskRequestGetData taskRequestGetDataRes(json);
120  ASSERT_FALSE(taskRequestGetDataRes.isError());
121  ASSERT_EQ(taskRequestGetDataRes.getErrorCode(), NO_ERROR);
122  ASSERT_TRUE(taskRequestGetDataRes.getErrorMsg().empty());
123  printSuccess("DRCETaskRequestGetData unserialize");
124 
125  ASSERT_EQ(taskRequestGetData.getFetchType(), taskRequestGetDataRes.getFetchType());
126  printSuccess("Test Serialize/Unserialize DRCETaskRequestGetData");
127 }
128 //-----------------------------------------------------------------------------
130 {
131  std::string json;
132  DRCETaskRequestTerminate taskRequestTerminate;
133  taskRequestTerminate.setAlgorithmType(DRCETaskRequestTerminate::AlgorithmType::atDefault);
134  taskRequestTerminate.setDelayValue(500);
135  taskRequestTerminate.setRepeatValue(5);
136  taskRequestTerminate.setSignalValue(15);
137  ASSERT_TRUE(taskRequestTerminate.serialize(json));
138  ASSERT_FALSE(taskRequestTerminate.isError());
139  ASSERT_EQ(taskRequestTerminate.getErrorCode(), NO_ERROR);
140  ASSERT_TRUE(taskRequestTerminate.getErrorMsg().empty());
141  printSuccess("DRCETaskRequestTerminate serialize");
142 
143 // std::cout << "JSON: " << json << std::endl;
144 
145  DRCETaskRequestTerminate taskRequestTerminateRes(json);
146  ASSERT_FALSE(taskRequestTerminateRes.isError());
147  ASSERT_EQ(taskRequestTerminateRes.getErrorCode(), NO_ERROR);
148  ASSERT_TRUE(taskRequestTerminateRes.getErrorMsg().empty());
149  printSuccess("DRCETaskRequestTerminate unserialize");
150 
151  ASSERT_EQ(static_cast<unsigned int>(taskRequestTerminate.getAlgorithmType()), static_cast<unsigned int>(taskRequestTerminateRes.getAlgorithmType()));
152  ASSERT_EQ(taskRequestTerminate.getDelayValue(), taskRequestTerminateRes.getDelayValue());
153  ASSERT_EQ(taskRequestTerminate.getRepeatValue(), taskRequestTerminateRes.getRepeatValue());
154  ASSERT_EQ(taskRequestTerminate.getSignalValue(), taskRequestTerminateRes.getSignalValue());
155  printSuccess("Test Serialize/Unserialize DRCETaskRequestTerminate");
156 }
157 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 } // namespace tests
160 } // end namespace drce
161 } // end namespace HCE