hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
main.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <iostream>
3 #include <fstream>
4 #include <iterator>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 
9 #include <Poco/ConsoleChannel.h>
10 #include <Poco/FileChannel.h>
11 #include <Poco/FormattingChannel.h>
12 #include <Poco/PatternFormatter.h>
13 #include <Poco/Logger.h>
14 #include <Poco/AutoPtr.h>
15 
16 #include "SphinxTestPrinter.hpp"
17 
19 
20 #include "SphinxIndexTest.hpp"
21 #include "SphinxSearchTest.hpp"
22 #include "SphinxManageTest.hpp"
24 #include "SphinxStressTest.hpp"
25 
29 
30 #include "SphinxMultiIndexTest.hpp"
32 
33 //-------------------------------------------------------------------
34 //-------------------------------------------------------------------
35 namespace HCE
36 {
37  namespace sphinx
38  {
39  namespace tests
40  {
41  Poco::SharedPtr<SphinxFunctionalObject> pObj = nullptr;
42  std::string homeDir;
45  } // end namespace tests
46  } // end namespace sphinx
47 } // end namespace HCE
48 //-----------------------------------------------------------------------------
49 void printUsageAndExit(const char* appName)
50 {
51  std::cerr << "\nUsage: " << appName << " -S <home_dir> -F <data_file_name> -C <index_count> -D <source_test_dir> -I <index_name> -M <need_make_index> -R <need_remove_index>"
52  << "\n\n<home_dir> - home dir of cluster node (need for all tests)"
53  << "\n<data_file_name> - data file used for create temporary indexes (need for perfomance test)"
54  << "\n<index_count> - number of create temporary indexes (need for perfomance test)"
55  << "\n<source_test_dir> - source dir content data files (need for stress test)"
56  << "\n<index_name> - index name (need for stress test)"
57  << "\n<need_make_index> - flag necessary make index (need for stress test)"
58  << "\n<need_remove_index> - flag necessary remove index (need for stress test)\n"
59  << std::endl;
60  exit(1);
61 }
62 //-------------------------------------------------------------------
63 //-------------------------------------------------------------------
64 
65 int main(int argc, char** argv)
66 {
67  Poco::AutoPtr<Poco::PatternFormatter> pPatternFormatter(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s:%q:%t"));
68  if (pPatternFormatter)
69  {
70  Poco::AutoPtr<Poco::FormattingChannel> pChannel = new Poco::FormattingChannel(pPatternFormatter);
71  if (pChannel)
72  {
73  Poco::AutoPtr<Poco::ConsoleChannel> pCons(new Poco::ConsoleChannel());
74  pChannel->setChannel(pCons);
75  pChannel->open();
76  Poco::Logger::root().setChannel(pChannel);
77  Poco::Logger::root().setLevel("debug");
78  }
79  }
80 
81  HCE::sphinx::tests::homeDir = ".";// "/home/alexander/hce-node-tests";
82 
85 
86  HCE::sphinx::tests::stressTestData.sourceTestDir = "../tests/sphinx_data";
90  try
91  {
92  int rez=0;
93  while((rez = getopt(argc,argv,"hHs:S:f:F:c:C:d:D:i:I:f:F:m:M:r:R:")) != -1)
94  {
95  switch(rez)
96  {
97  case 'h':
98  case 'H': printUsageAndExit(argv[0]);
99  break;
100  case 's':
101  case 'S': HCE::sphinx::tests::homeDir = optarg;
102  break;
103  case 'f':
105  break;
106  case 'c':
107  case 'C': HCE::sphinx::tests::perfomanceData.indexCount = std::stoul(optarg);
108  break;
109  case 'd':
111  break;
112  case 'i':
114  break;
115  case 'm':
116  case 'M': HCE::sphinx::tests::stressTestData.needMakeIndex = static_cast<bool>(std::stoul(optarg));
117  break;
118  case 'r':
119  case 'R': HCE::sphinx::tests::stressTestData.needRemoveIndex = static_cast<bool>(std::stoul(optarg));
120  break;
121  };
122  };
123  }
124  catch(std::exception& e)
125  {
126  std::cerr << "Error: " << e.what() << std::endl;
127  printUsageAndExit(argv[0]);
128  }
129 
130  testing::InitGoogleTest(&argc, argv);
131 
132  // Gets hold of the event listener list.
133  testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners();
134  // Adds a listener to the end. Google Test takes the ownership.
135  listeners.Append(new HCE::sphinx::tests::SphinxTestPrinter);
136 
137  return RUN_ALL_TESTS();
138 }
139 
140 /*
141 int main(void)
142 {
143  HCE::sphinx::tests::homeDir = "/home/alexander/hce-node-tests";
144  HCE::sphinx::SphinxFunctionalObject fObj;
145  fObj.setHomeDir(HCE::sphinx::tests::homeDir);
146 // fObj.setLogStream(std::cout);
149 
150 // HCE::sphinx::tests::SphinxFunctionalObjectTest::fullAdminCommandsTest(fObj);
151 // HCE::sphinx::tests::SphinxFunctionalObjectTest::changeSearchIndexTest(fObj);
152 // HCE::sphinx::tests::SphinxFunctionalObjectTest::autoGettingPortsSearchd(fObj);
154 // HCE::sphinx::tests::SphinxFunctionalObjectTest::fullIndexerTest(fObj);
155 // HCE::sphinx::tests::SphinxFunctionalObjectTest::fullSearcherTest(fObj); // restore implementation
156 // HCE::sphinx::tests::SphinxFunctionalObjectTest::differentFiltersTest(fObj);
158 // bool ret = HCE::sphinx::tests::SphinxFunctionalObjectTest::isUse64Bit(fObj);
159 // std::cout << "Use 64 Bit = " << std::boolalpha << ret << std::endl;
160 
161 // const size_t indexCount = 10;
162 // const std::string dataFileName = "./test1000.dat";
163 // HCE::sphinx::tests::SphinxFunctionalObjectTest::testPerfomance(dataFileName, indexCount);
164 
165 // const std::string sourceTestDir = "../tests/sphinx_data";
166 // const std::string indexName = "i003";
167 // bool needMakeIndex = false;
168 // bool needRemoveIndex = false;
169 
170 // HCE::sphinx::tests::SphinxFunctionalObjectTest::testStressGetBigResult(fObj, sourceTestDir, indexName, needMakeIndex);
171 // HCE::sphinx::tests::SphinxFunctionalObjectTest::testGetResultUseOffset(fObj, sourceTestDir, indexName, needMakeIndex);
172 
173  std::cout << "Done...\n";
174  return 0;
175 }
176 */