1 #include <gtest/gtest.h>
29 FileItem files[SZ] = {{
"file1",
"data1", 2},{
"file2",
"data2", 4},{
"file3",
"data3", 8}};
36 for (
size_t i=0;i<SZ;++i)
39 resultData.
addDataItem(std::forward<DRCEResultDataItem>(resultDataItem));
44 ASSERT_TRUE(ret) <<
printError(resultSerializator);
50 for (
size_t i=0;i<itemsCount;++i)
58 ASSERT_TRUE(ret) <<
printError(resultSerializator);
61 ASSERT_EQ(itemsCount, 1);
65 ASSERT_EQ(filesCount, SZ);
67 for (
size_t i=0;i<SZ;++i)
73 printSuccess(
"Test ResultDataSerializator");
78 std::stringstream sourceJson, restoreJson;
82 sessionOptions.
sessionType = SessionOptions::SessionType::stSsh;
87 sessionOptions.
port = 22;
90 sessionOptions.
environments.push_back(std::make_pair(
"PATH",
"../"));
91 sessionOptions.
environments.push_back(std::make_pair(
"LD_PATH",
"./"));
93 taskRequestSetExecute.
setSessionOptions(std::forward<SessionOptions>(sessionOptions));
109 sourceJson << sourceMessage;
113 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
114 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
115 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
116 printSuccess(
"DRCEInputJsonMessage serialize");
118 sourceJson >> restoreMessage;
120 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
121 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
122 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
123 printSuccess(
"DRCEInputJsonMessage unserialize");
125 restoreJson << restoreMessage;
126 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
130 ASSERT_EQ(sourceMessage.getRequestType(), restoreMessage.getRequestType());
131 ASSERT_EQ(sourceMessage.getRequestData(), restoreMessage.getRequestData());
132 ASSERT_EQ(sourceMessage.getRequestId(), restoreMessage.getRequestId());
133 ASSERT_EQ(sourceJson.str(), restoreJson.str());
134 printSuccess(
"Test InputJsonMessage");
139 std::stringstream sourceJson, restoreJson;
143 sessionOptions.
sessionType = SessionOptions::SessionType::stSsh;
148 sessionOptions.
port = 22;
151 sessionOptions.
environments.push_back(std::make_pair(
"PATH",
"../"));
152 sessionOptions.
environments.push_back(std::make_pair(
"LD_PATH",
"./"));
160 sourceJson << sourceMessage;
162 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
163 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
164 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
165 printSuccess(
"DRCETaskRequestSetExecute serialize");
167 sourceJson >> restoreMessage;
169 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
170 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
171 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
172 printSuccess(
"DRCETaskRequestSetExecute unserialize");
174 restoreJson << restoreMessage;
175 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
179 ASSERT_EQ(sourceMessage.getSessionOptions().sessionType, restoreMessage.getSessionOptions().sessionType);
180 ASSERT_EQ(sourceMessage.getSessionOptions().port, restoreMessage.getSessionOptions().port);
181 ASSERT_EQ(sourceMessage.getSessionOptions().userName, restoreMessage.getSessionOptions().userName);
182 ASSERT_EQ(sourceMessage.getSessionOptions().userPassword, restoreMessage.getSessionOptions().userPassword);
183 ASSERT_EQ(sourceMessage.getSessionOptions().shellName, restoreMessage.getSessionOptions().shellName);
184 ASSERT_EQ(sourceMessage.getSessionOptions().homeDir, restoreMessage.getSessionOptions().homeDir);
185 ASSERT_EQ(sourceMessage.getSessionOptions().timeout, restoreMessage.getSessionOptions().timeout);
186 ASSERT_EQ(sourceMessage.getSessionOptions().tmode, restoreMessage.getSessionOptions().tmode);
187 ASSERT_EQ(sourceMessage.getSessionOptions().environments.size(), restoreMessage.getSessionOptions().environments.size());
189 ASSERT_EQ(sourceMessage.getCommandLine(), restoreMessage.getCommandLine());
190 ASSERT_EQ(sourceMessage.getInputStream(), restoreMessage.getInputStream());
191 ASSERT_EQ(sourceMessage.getFilesCount(), restoreMessage.getFilesCount());
192 const size_t filesCount = sourceMessage.getFilesCount();
193 for (
size_t i=0;i<filesCount;++i)
195 ASSERT_EQ(sourceMessage.getFileItem(i).name, restoreMessage.getFileItem(i).name);
196 ASSERT_EQ(sourceMessage.getFileItem(i).data, restoreMessage.getFileItem(i).data);
197 ASSERT_EQ(sourceMessage.getFileItem(i).actionType, restoreMessage.getFileItem(i).actionType);
199 ASSERT_EQ(sourceJson.str(), restoreJson.str());
200 printSuccess(
"Test DRCETaskRequestSetExecute");
205 std::stringstream sourceJson, restoreJson;
214 resultDataItem.
setRequestType(DRCETaskRequest::RequestType::rtTerminateTask);
218 resultDataItem.
setPid(10101);
223 resultData.
addDataItem(std::forward<DRCEResultDataItem>(resultDataItem));
228 ASSERT_TRUE(ret) <<
printError(sourceMessage);
232 printSuccess(
"DRCEOutputJsonMessage serialize");
234 sourceJson.str(json);
235 sourceJson >> restoreMessage;
237 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
238 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
239 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
240 printSuccess(
"DRCEOutputJsonMessage unserialize");
242 restoreJson << restoreMessage;
243 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
270 ASSERT_EQ(sourceJson.str(), restoreJson.str());
271 printSuccess(
"Test OutputJsonMessage");
278 std::stringstream sourceJson;
280 sourceOptions.
sessionType = SessionOptions::SessionType::stSsh;
281 sourceOptions.
port = 22;
289 sourceOptions.
environments.push_back(std::make_pair(
"PATH",
"./"));
290 sourceOptions.
environments.push_back(std::make_pair(
"LD_PATH",
"../"));
294 sourceJson << sourceMessage;
296 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
297 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
298 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
299 printSuccess(
"DRCETaskRequestSetExecute serialize");
301 sourceJson >> restoreMessage;
303 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
304 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
305 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
306 printSuccess(
"DRCETaskRequestSetExecute unserialize");
308 ASSERT_EQ(restoreMessage.getSessionOptions().sessionType, SessionOptions::SessionType::stSsh);
309 ASSERT_EQ(restoreMessage.getSessionOptions().port, 22);
310 ASSERT_EQ(restoreMessage.getSessionOptions().userName,
"user");
311 ASSERT_EQ(restoreMessage.getSessionOptions().userPassword,
"123");
312 ASSERT_EQ(restoreMessage.getSessionOptions().shellName,
"Shell");
313 ASSERT_EQ(restoreMessage.getSessionOptions().homeDir,
".");
314 ASSERT_EQ(restoreMessage.getSessionOptions().timeout, 43);
316 ASSERT_EQ(restoreMessage.getSessionOptions().timeMax, 500);
317 ASSERT_EQ(restoreMessage.getSessionOptions().environments.size(), 2);
318 ASSERT_EQ(restoreMessage.getSessionOptions().environments[0].first,
"PATH");
319 ASSERT_EQ(restoreMessage.getSessionOptions().environments[0].second,
"./");
320 ASSERT_EQ(restoreMessage.getSessionOptions().environments[1].first,
"LD_PATH");
321 ASSERT_EQ(restoreMessage.getSessionOptions().environments[1].second,
"../");
323 printSuccess(
"Test SessionOptions");
330 std::stringstream sourceJson;
343 sourceJson << sourceMessage;
345 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
346 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
347 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
348 printSuccess(
"DRCETaskRequestSetExecute serialize");
350 sourceJson >> restoreMessage;
352 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
353 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
354 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
355 printSuccess(
"DRCETaskRequestSetExecute unserialize");
357 ASSERT_EQ(restoreMessage.getResourceLimits().procMax, 4);
358 ASSERT_EQ(restoreMessage.getResourceLimits().threadsMax, 3);
359 ASSERT_EQ(restoreMessage.getResourceLimits().cpuMax, 2);
360 ASSERT_EQ(restoreMessage.getResourceLimits().vramFree, 125000);
361 ASSERT_EQ(restoreMessage.getResourceLimits().vramFreeMin, 75);
362 ASSERT_EQ(restoreMessage.getResourceLimits().rramFree, 512000);
363 ASSERT_EQ(restoreMessage.getResourceLimits().rramFreeMin, 25);
364 ASSERT_EQ(restoreMessage.getResourceLimits().diskFree, 1024000);
365 ASSERT_EQ(restoreMessage.getResourceLimits().diskFreeMin, 50);
367 printSuccess(
"Test ResourceLimits");}
373 std::stringstream sourceJson;
386 sourceJson << sourceMessage;
388 ASSERT_FALSE(sourceMessage.isError()) <<
printError(sourceMessage);
389 ASSERT_EQ(sourceMessage.getErrorCode(),
NO_ERROR);
390 ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
391 printSuccess(
"DRCETaskRequestSetExecute serialize");
393 sourceJson >> restoreMessage;
395 ASSERT_FALSE(restoreMessage.isError()) <<
printError(restoreMessage);
396 ASSERT_EQ(restoreMessage.getErrorCode(),
NO_ERROR);
397 ASSERT_TRUE(restoreMessage.getErrorMsg().empty());
398 printSuccess(
"DRCETaskRequestSetExecute unserialize");
400 ASSERT_EQ(restoreMessage.getFilesCount(), 4);
401 ASSERT_EQ(restoreMessage.getFileItem(0).name,
"name1");
402 ASSERT_EQ(restoreMessage.getFileItem(0).data,
"data1");
405 ASSERT_EQ(restoreMessage.getFileItem(1).name,
"name2");
406 ASSERT_EQ(restoreMessage.getFileItem(1).data,
"data2");
409 ASSERT_EQ(restoreMessage.getFileItem(2).name,
"name3");
410 ASSERT_EQ(restoreMessage.getFileItem(2).data,
"data3");
414 ASSERT_EQ(restoreMessage.getFileItem(3).name,
"name4");
415 ASSERT_EQ(restoreMessage.getFileItem(3).data,
"data4");
419 printSuccess(
"Test FilesItemList");