hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxAdminCommandTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <iomanip>
3 #include <sstream>
4 #include <fstream>
5 #include <set>
6 
7 #include <Poco/SharedPtr.h>
8 #include "SphinxTestPrinter.hpp"
9 
10 #include "EncodeDecodeBase64.hpp"
11 #include "SphinxError.hpp"
12 #include "SphinxManageTest.hpp"
17 #include "SphinxPrintStatus.hpp"
18 
19 namespace HCE
20 {
21 namespace sphinx
22 {
23 namespace tests
24 {
25 extern std::string homeDir;
26 extern Poco::SharedPtr<HCE::sphinx::SphinxFunctionalObject> pObj;
27 
28 const std::string nodeName = "test_node";
29 const std::string defaultIndex = "i001";
30 const std::string indexName = "i003";
31 const std::string copyIndexName = "i004";
32 const std::string renameIndexName = "i005";
33 //-----------------------------------------------------------------------------
34 TEST(SphinxAdminCommand, notLoadConfigInConstructor)
35 {
37  ASSERT_FALSE(fObject.isLoadedConfig());
38  ASSERT_FALSE(fObject.isActiveSearchd());
39 }
40 //-----------------------------------------------------------------------------
41 TEST(SphinxAdminCommand, loadConfigInConstructor)
42 {
44  ASSERT_NE(pObj, nullptr);
45 
47  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
48  delete pObj;
49 
51  ASSERT_NE(pObject, nullptr);
52  pObject->setLogStream(std::cout);
53  ASSERT_TRUE(pObject->isLoadedConfig());
54  ASSERT_TRUE(pObject->isActiveSearchd());
55  delete pObject;
56 
58  ASSERT_NE(pObj, nullptr);
60  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
61  delete pObj;
62 }
63 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
65 class SphinxAdminCommandTest : public ::testing::Test
66 {
67 protected:
68  static void SetUpTestCase(void)
69  {
70  pObj = Poco::SharedPtr<HCE::sphinx::SphinxFunctionalObject>(new HCE::sphinx::SphinxFunctionalObject(nodeName, 234, homeDir));
71 // pObj->setLogStream(std::cout);
72  }
73  // cppcheck-suppress unusedFunction
74  static void TearDownTestCase(void)
75  {
76  pObj = nullptr;
77  }
78 };
79 
80 std::vector<std::string> branches;
81 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 TEST_F(SphinxAdminCommandTest, isCreatedSphinxFunctionalObject)
84 {
85  ASSERT_FALSE(pObj.isNull());
86 }
87 //-----------------------------------------------------------------------------
89 {
90  ASSERT_FALSE(pObj->isActiveSearchd());
91 }
92 //-----------------------------------------------------------------------------
93 TEST_F(SphinxAdminCommandTest, isNotLoadedConfig)
94 {
95  ASSERT_FALSE(pObj->isLoadedConfig());
96 }
97 //-----------------------------------------------------------------------------
98 TEST_F(SphinxAdminCommandTest, testIndexCreateRemove)
99 {
101  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
103  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
104 }
105 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 TEST_F(SphinxAdminCommandTest, testIndexCheckExist)
108 {
110  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
112  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CHECK_INDEX) << printError(*pObj);
114  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
115 }
116 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
118 TEST_F(SphinxAdminCommandTest, testIndexCheckNotExist)
119 {
120  SphinxManageTest::testIndexCheck(*pObj, "branch_0006", false);
121  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CHECK_INDEX) << printError(*pObj);
122 }
123 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
125 TEST_F(SphinxAdminCommandTest, testIndexStoreDataFile)
126 {
128  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
129  branches.clear();
130  branches.push_back("branch_0005");
131  branches.push_back("branch_0006");
132  branches.push_back("branch_0007");
133  for (size_t i=0;i<branches.size();++i)
134  {
137  }
138  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
140  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
141 }
142 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 TEST_F(SphinxAdminCommandTest, testIndexStoreSchemaFile)
145 {
147  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
150  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
152  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
153 }
154 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
156 TEST_F(SphinxAdminCommandTest, testIndexMaxDocId)
157 {
159  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
160  branches.clear();
161  branches.push_back("branch_0005");
162  for (size_t i=0;i<branches.size();++i)
167  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
169  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
170 }
171 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
173 TEST_F(SphinxAdminCommandTest, testIndexMaxDocIdExtended)
174 {
176  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
177  branches.clear();
178  branches.push_back("branch_0005");
179  branches.push_back("branch_0006");
180  for (size_t i=0;i<branches.size();++i)
185  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
187  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
188 }
189 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
191 TEST_F(SphinxAdminCommandTest, testIndexRebuild)
192 {
194  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
196  branches.clear();
197  branches.push_back("branch_0005");
198  branches.push_back("branch_0006");
199  branches.push_back("branch_0007");
200  for (size_t i=0;i<branches.size();++i)
202  branches.push_back("branch_0008");
203  branches.push_back("branch_0009");
205 
206  branches.clear();
207  branches.push_back("*");
209  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
211  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
212 }
213 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
215 TEST_F(SphinxAdminCommandTest, testIndexMergeStart)
216 {
218  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
220  branches.clear();
221  branches.push_back("branch_0005");
222  branches.push_back("branch_0006");
223  branches.push_back("branch_0007");
224  for (size_t i=0;i<branches.size();++i)
229  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
231  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
232 }
233 //-----------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------
235 TEST_F(SphinxAdminCommandTest, testIndexDeleteDataFile)
236 {
238  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
239  branches.clear();
240  branches.push_back("branch_0005");
241  for (size_t i=0;i<branches.size();++i)
244  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
246  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
247 }
248 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
250 TEST_F(SphinxAdminCommandTest, testIndexRebuildMergeStart)
251 {
253  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
255  branches.clear();
256  branches.push_back("branch_0005");
257  branches.push_back("branch_0006");
258  branches.push_back("branch_0007");
259  for (size_t i=0;i<branches.size();++i)
261  branches.clear();
262  branches.push_back("*");
266  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
268  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
269 }
270 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
272 TEST_F(SphinxAdminCommandTest, testIndexMergeNotExist)
273 {
275  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
277  branches.clear();
278  branches.push_back("branch_0005");
279  branches.push_back("branch_0006");
280  branches.push_back("branch_0007");
281  for (size_t i=0;i<branches.size();++i)
285  branches.push_back("branch_0008"); // not exists
286  branches.push_back("branch_0009"); // not exists
288  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
290  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
291 }
292 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
294 TEST_F(SphinxAdminCommandTest, testIndexStartStopStart)
295 {
297  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
299  branches.clear();
300  branches.push_back("branch_0005");
301  for (size_t i=0;i<branches.size();++i)
308  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
310  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
311 }
312 //-----------------------------------------------------------------------------
313 TEST_F(SphinxAdminCommandTest, testIndexDeleteDataFileAndDeleteSchemaFile)
314 {
316  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
318  branches.clear();
319  branches.push_back("branch_0005");
320  branches.push_back("branch_0006");
321  branches.push_back("branch_0007");
322  for (size_t i=0;i<branches.size();++i)
325  for (size_t i=0;i<branches.size();++i)
327  branches.clear();
328  branches.push_back("*");
331  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
333  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
334 }
335 //-----------------------------------------------------------------------------
336 //-----------------------------------------------------------------------------
337 TEST_F(SphinxAdminCommandTest, testIndexAppendDataFile)
338 {
340  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
342  branches.clear();
343  branches.push_back("branch_0005");
344  branches.push_back("branch_0006");
345  branches.push_back("branch_0007");
346  for (size_t i=0;i<branches.size();++i)
351  branches.clear();
352  branches.push_back("branch_0005");
353  branches.push_back("branch_0006");
354  for (size_t i=0;i<branches.size();++i)
357  for (size_t i=0;i<branches.size();++i)
359  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
361  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
362 }
363 //-----------------------------------------------------------------------------
364 //-----------------------------------------------------------------------------
365 TEST_F(SphinxAdminCommandTest, testIndexDeleteDoc)
366 {
368  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
370  branches.clear();
371  branches.push_back("branch_0005");
372  branches.push_back("branch_0006");
373  branches.push_back("branch_0007");
374  for (size_t i=0;i<branches.size();++i)
378 
379  std::vector<unsigned long long> ids = { 123456789012, 123456789023, 123456789034, 123456789045, 123456789056, 123456789067, 123456789078, 123456789089, 123456789090, 1234567890101};
382  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
384  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
385 }
386 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
388 TEST_F(SphinxAdminCommandTest, testIndexPackDocData)
389 {
391  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
393  branches.clear();
394  branches.push_back("branch_0005");
395  branches.push_back("branch_0006");
396  branches.push_back("branch_0007");
397  for (size_t i=0;i<branches.size();++i)
399 
402 
405  branches.clear();
406  branches.push_back("*");
409  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
411  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
412 }
413 //-----------------------------------------------------------------------------
414 //-----------------------------------------------------------------------------
416 {
418  ASSERT_TRUE(pObj->getErrorCode()==NO_ERROR || pObj->getErrorCode()==ERROR_CREATE_INDEX) << printError(*pObj);
421  ASSERT_TRUE(pObj->isError());
422 }
423 //-----------------------------------------------------------------------------
424 //-----------------------------------------------------------------------------
426 {
427  // prepare for next copy index
430  branches.clear();
431  branches.push_back("branch_0005");
432  branches.push_back("branch_0006");
433  branches.push_back("branch_0007");
434  for (size_t i=0;i<branches.size();++i)
439  // make copy index
445  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
447  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
449  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
450 }
451 //-----------------------------------------------------------------------------
452 //-----------------------------------------------------------------------------
454 {
455  // prepare for next copy index
458  branches.clear();
459  branches.push_back("branch_0005");
460  branches.push_back("branch_0006");
461  branches.push_back("branch_0007");
462  for (size_t i=0;i<branches.size();++i)
468 
469  // make rename index
471  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
473  pObj->resetError();
476  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
477 }
478 //-----------------------------------------------------------------------------
479 //-----------------------------------------------------------------------------
480 TEST_F(SphinxAdminCommandTest, testIndexSetConfigVarGetConfigVar)
481 {
482  std::cout << "HOME DIR: " << pObj->getHomeDir() << std::endl;
483 
486  branches.clear();
487  branches.push_back("branch_0005");
488  branches.push_back("branch_0006");
489  branches.push_back("branch_0007");
490  for (size_t i=0;i<branches.size();++i)
495 
497  // make remove index
500 
502  branches.clear();
503  branches.push_back("branch_0005");
504  for (size_t i=0;i<branches.size();++i)
509 
510  // set config property value
511  SphinxManageTest::testIndexSetConfigVar(*pObj, indexName, "", "searchd", "test_param", "test_value1");
512  SphinxManageTest::testIndexSetConfigVar(*pObj, indexName, "", "index branch_0001", "test_param", "test_value2");
513  SphinxManageTest::testIndexSetConfigVar(*pObj, indexName, "branch_0005", "searchd", "test_param", "test_value1");
514  SphinxManageTest::testIndexSetConfigVar(*pObj, indexName, "branch_0005", "index branch_0001", "test_param", "test_value2");
515  // get config property value
516  std::string paramValue;
517  SphinxManageTest::testIndexGetConfigVar(*pObj, indexName, "", "searchd", "test_param", paramValue);
518  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
519  ASSERT_EQ(paramValue, "test_value1");
520  SphinxManageTest::testIndexGetConfigVar(*pObj, indexName, "", "index branch_0001", "test_param", paramValue);
521  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
522  ASSERT_EQ(paramValue, "test_value2");
523  SphinxManageTest::testIndexGetConfigVar(*pObj, indexName, "branch_0005", "searchd", "test_param", paramValue);
524  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
525  ASSERT_EQ(paramValue, "test_value1");
526  SphinxManageTest::testIndexGetConfigVar(*pObj, indexName, "branch_0005", "index branch_0001", "test_param", paramValue);
527  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
528  ASSERT_EQ(paramValue, "test_value2");
529  // check validation of schema data and save in index if valid
531 
534  branches.clear();
535  branches.push_back("branch_0005");
536  for (size_t i=0;i<branches.size();++i)
542  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
544  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
545 }
546 //-----------------------------------------------------------------------------
547 //-----------------------------------------------------------------------------
548 TEST_F(SphinxAdminCommandTest, testIndexCheckSchema)
549 {
553  ASSERT_FALSE(pObj->isError());
555  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
556 }
557 //-----------------------------------------------------------------------------
558 //-----------------------------------------------------------------------------
559 TEST_F(SphinxAdminCommandTest, testIndexStatusSearchd)
560 {
563  branches.clear();
564  branches.push_back("branch_0005");
565  for (size_t i=0;i<branches.size();++i)
570  // make copy index
573  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
575  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
576 }
577 //-----------------------------------------------------------------------------
578 //-----------------------------------------------------------------------------
580 {
583  branches.clear();
584  branches.push_back("branch_0005");
585  for (size_t i=0;i<branches.size();++i)
590  // make copy index
593  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
595  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
596 }
597 //-----------------------------------------------------------------------------
598 //-----------------------------------------------------------------------------
599 TEST_F(SphinxAdminCommandTest, testIndexDataList)
600 {
603  branches.clear();
604  branches.push_back("branch_0005");
605  for (size_t i=0;i<branches.size();++i)
610  // make copy index
613  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
615  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
616 }
617 //-----------------------------------------------------------------------------
618 //-----------------------------------------------------------------------------
619 TEST_F(SphinxAdminCommandTest, testIndexBranchesList)
620 {
623  branches.clear();
624  branches.push_back("branch_0005");
625  for (size_t i=0;i<branches.size();++i)
630  // make copy index
633  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
635  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
636 }
637 //-----------------------------------------------------------------------------
638 //-----------------------------------------------------------------------------
639 TEST_F(SphinxAdminCommandTest, testIndexBranchesInfo)
640 {
643  branches.clear();
644  branches.push_back("branch_0005");
645  for (size_t i=0;i<branches.size();++i)
650  // make copy index
653  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
655  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
656 }
657 //-----------------------------------------------------------------------------
658 //-----------------------------------------------------------------------------
659 TEST_F(SphinxAdminCommandTest, testIndexBranchesStatus)
660 {
663  branches.clear();
664  branches.push_back("branch_0005");
665  for (size_t i=0;i<branches.size();++i)
672  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
674  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
675 }
676 //-----------------------------------------------------------------------------
677 //-----------------------------------------------------------------------------
678 TEST_F(SphinxAdminCommandTest, testIndexConnectDisconnect)
679 {
682  branches.clear();
683  branches.push_back("branch_0005");
684  for (size_t i=0;i<branches.size();++i)
693  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
695  ASSERT_TRUE(pObj->isError());
696 }
697 //-----------------------------------------------------------------------------
698 //-----------------------------------------------------------------------------
699 TEST_F(SphinxAdminCommandTest, fullAdminCommandsTest)
700 {
702  ASSERT_FALSE(pObj->isError()) << printError(*pObj);
703 }
704 //-----------------------------------------------------------------------------
705 //-----------------------------------------------------------------------------
706 } // end namespace tests
707 } // end namespace sphinx
708 } // end namespace HCE
709 
710 
711