hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxStressTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <Poco/SharedPtr.h>
3 #include <fstream>
4 #include <sstream>
5 #include <assert.h>
6 #include <unistd.h>
7 #include <iomanip>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <dirent.h>
11 #include <errno.h>
12 #include <string.h>
13 
14 #include "ProcExec.hpp"
15 #include "SphinxError.hpp"
16 #include "SphinxAdminCommand.hpp"
17 #include "SphinxManageTest.hpp"
18 #include "SphinxStressTest.hpp"
20 
21 namespace HCE
22 {
23 namespace sphinx
24 {
25 namespace tests
26 {
27 extern Poco::SharedPtr<SphinxFunctionalObject> pObj;
28 extern std::string homeDir;
29 extern StressTestData stressTestData;
30 //-----------------------------------------------------------------------------
31 bool SphinxStressTest::makeDataFilesList(const std::string& sourceDir, std::vector<std::string>& files, std::string& error)
32 {
33  bool result = false;
34  files.clear();
35 
36  struct dirent* d = nullptr;
37  DIR* dir = opendir(sourceDir.c_str());
38  if (dir != nullptr)
39  {
40  result = true;
41  std::string fileName;
42  while((d = readdir(dir)))
43  {
44  fileName = d->d_name;
45  if (fileName != "." && fileName != "..")
46  files.push_back(fileName);
47  }
48  if (closedir(dir)==-1)
49  result = false;
50  }
51  else
52  result = false;
53 
54  if (!result)
55  error = strerror(errno);
56 
57  return result;
58 }
59 //-----------------------------------------------------------------------------
60 bool SphinxStressTest::moveDataFiles(const std::string& sourceDir, const std::string& destDir, std::vector<std::string>& files, std::string& error)
61 {
62  bool result = true;
63  std::string fileName, srcFile, dstFile;
64  size_t i=0;
65  for (;i<files.size();++i)
66  {
67  fileName = files[i];
68  srcFile = sourceDir+"/"+fileName;
69  size_t pos = fileName.find_last_of('.');
70  if (pos!=std::string::npos)
71  fileName.resize(pos+1);
72  dstFile = destDir+"/"+fileName+sphinx_admin_command_const::dataFileExtension;
73 
74  std::stringstream outMsg, errMsg;
75  ProcExec procExec("cp "+srcFile+" "+dstFile);
76  if (!procExec.exec(outMsg, errMsg))
77  {
78  error = errMsg.str();
79  result = false;
80  break;
81  }
82  std::cout << "." << std::flush;
83  }
84  std::cout << std::endl << "Copied " << i << " files" << std::endl;
85  return result;
86 }
87 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
89 class StressTest : public ::testing::Test
90 {
91 protected:
92  static void SetUpTestCase(void)
93  {
94  pObj = Poco::SharedPtr<SphinxFunctionalObject>(new SphinxFunctionalObject("node", 456, homeDir));
95  }
96  static void TearDownTestCase(void)
97  {
98  pObj = nullptr;
99  }
100 };
101 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
103 TEST_F(StressTest, Is_Created_SphinxFunctionalObject)
104 {
105  ASSERT_FALSE(pObj.isNull());
106 }
107 //-----------------------------------------------------------------------------
108 TEST_F(StressTest, testStressGetBigResult)
109 {
111 }
112 //-----------------------------------------------------------------------------
113 TEST_F(StressTest, testGetResultUseOffset)
114 {
116 }
117 //-----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
119 } // namespace tests
120 } // namespace sphinx
121 } // namespace HCE