hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxManageTest.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 "EncodeDecodeBase64.hpp"
8 #include "SphinxError.hpp"
9 #include "SphinxManageTest.hpp"
12 //#include "SphinxFunctionalObject.hpp"
13 #include "SphinxAdminCommand.hpp"
15 #include "SphinxPrintStatus.hpp"
16 
17 namespace HCE
18 {
19 namespace sphinx
20 {
21 namespace tests
22 {
23 //-----------------------------------------------------------------------------
25 {
26  std::string json;
27  IndexCreate indexCreate(fObj);
28  indexCreate.setIndexName(indexName);
29  ASSERT_TRUE(indexCreate.serialize(json));
30  printSuccess("Serialize IndexCreate");
31 
32  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
33  msgManage->setCommandString("INDEX_CREATE");
34  msgManage->setCommandOptionsString(json);
35  ASSERT_TRUE(msgManage->serialize(json));
36  printSuccess("Serialize SphinxInputJsonMessageManage");
37 
38  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
39  handler.setData(json);
40 
41  std::stringstream str;
42  str << handler;
43 
44  std::string ret = fObj.Process(str.str());
45  std::cout << "ret: '" << ret << "'\n";
46 
47  EXPECT_FALSE(ret.empty());
48  EXPECT_TRUE(fObj.getErrorCode()==NO_ERROR || fObj.getErrorCode()==ERROR_CREATE_INDEX) << "ErrorCode: " << fObj.getErrorCode() << std::endl;
49 
50  SphinxOutputJsonMessage outputJsonMessage(ret);
51  ASSERT_FALSE(outputJsonMessage.isError());
52  ASSERT_TRUE(outputJsonMessage.getData().empty());
53  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR || outputJsonMessage.getErrorCode()==ERROR_CREATE_INDEX);
54  printSuccess("Test command INDEX_CREATE");
55 }
56 //-----------------------------------------------------------------------------
58 {
59  std::string json;
60  IndexCheck indexCheck(fObj);
61  indexCheck.setIndexName(indexName);
62  ASSERT_TRUE(indexCheck.serialize(json));
63  printSuccess("Serialize IndexCheck");
64 
65  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
66  msgManage->setCommandString("INDEX_CHECK");
67  msgManage->setCommandOptionsString(json);
68  ASSERT_TRUE(msgManage->serialize(json));
69  printSuccess("Serialize SphinxInputJsonMessageManage");
70 
71  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
72  handler.setData(json);
73 
74  std::stringstream str;
75  str << handler;
76 
77  std::string ret = fObj.Process(str.str());
78  std::cout << "ret: '" << ret << "'\n";
79 
80  EXPECT_FALSE(ret.empty());
81  EXPECT_TRUE(fObj.getErrorCode()==NO_ERROR || fObj.getErrorCode()==ERROR_CHECK_INDEX) << "ErrorCode: " << fObj.getErrorCode() << std::endl;
82 
83  SphinxOutputJsonMessage outputJsonMessage(ret);
84  ASSERT_FALSE(outputJsonMessage.isError());
85  fObj.log(HCE::LoggerStream::PRIO_INFORMATION) << "outputJsonMessage.getData(): '" << outputJsonMessage.getData() << "'\n";
86  ASSERT_TRUE(outputJsonMessage.getData()==((existed)?"1":"0"));
87  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR || outputJsonMessage.getErrorCode()==ERROR_CHECK_INDEX);
88  printSuccess("Test command INDEX_CHECK");
89 }
90 //-----------------------------------------------------------------------------
92 {
93  std::stringstream dataContent;
94  dataContent << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"123\">\n"
95  << "<title><![CDATA[[- Information interchange - Representation of dates and times. A discussion of ISO 8601 has been written by Markus Kuhn. ISO 8601 describes a large number of date/time formats. For example it defines Basic Format, without punctuation, and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.]]></title>\n"
96  << "<h><![CDATA[[time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions. The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the \"T\" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>\n"
97  << "<cdate>123</cdate>\n"
98  << "</sphinx:document>\n"
99  << "\n<sphinx:document id=\"53\">\n"
100  << "<title><![CDATA[[- Information interchange - ISO 8601 describes a large , and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.]]></title>\n"
101  << "<h><![CDATA[[time, so this profile defines six levels. omparing two dates with different precisions. The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the \"T\" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>\n"
102  << "<cdate>53</cdate>\n"
103  << "</sphinx:document>\n"
104  << "\n<sphinx:document id=\"133\">\n"
105  << "<title><![CDATA[[ There are more differences between 'gcc' and 'g++' than only the standard libraries, so gcc -lstdc++ will still not get you the same behavior as g++. We put all of that language-specific behavior into its own driver .]]></title>\n"
106  << "<h><![CDATA[[There are more differences between 'gcc' and 'g++' than only the standard libraries, so gcc -lstdc++ will still not get you the same behavior as g++. We put all of that language-specific behavior into its own driver ]]></h>\n"
107  << "<cdate>133</cdate>\n"
108  << "</sphinx:document>\n</sphinx:docset>";
109 
110  testIndexStoreDataFile(fObj, indexName, branchName, dataContent.str());
111 }
112 //-----------------------------------------------------------------------------
113 void SphinxManageTest::testIndexStoreDataFile(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, const std::string& branchName, const std::string& dataContent)
114 {
115  std::string json;
116  IndexStoreDataFile indexStoreDataFile(fObj);
117  indexStoreDataFile.setIndexName(indexName);
118  indexStoreDataFile.setBranchName(branchName);
119  indexStoreDataFile.setDataContent(HCE::encodeBase64(dataContent));
120  ASSERT_TRUE(indexStoreDataFile.serialize(json));
121  printSuccess("Serialize IndexStoreDataFile");
122 
123  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
124  msgManage->setCommandString("INDEX_STORE_DATA_FILE");
125  msgManage->setCommandOptionsString(json);
126  ASSERT_TRUE(msgManage->serialize(json));
127  printSuccess("Serialize SphinxInputJsonMessageManage");
128 
129  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
130  handler.setData(json);
131 
132  std::stringstream str;
133  str << handler;
134 
135  std::string ret = fObj.Process(str.str());
136  std::cout << "ret: '" << ret << "'\n";
137 
138 // if (!fObj.getErrorMsg().empty() || fObj.getErrorCode())
139 // std::cout << "ErrorMsg: " << fObj.getErrorMsg() << " ErrorCode = " << fObj.getErrorCode() << std::endl;
140 
141  if (!dataContent.empty())
142  {
143  ASSERT_TRUE(fObj.getErrorMsg().empty());
144  ASSERT_TRUE(fObj.getErrorCode()==NO_ERROR);
145 
146  const std::string file = fObj.getDataDir()+"/"+indexName+"/"+sphinx_admin_command_const::dataDir+"/"+branchName+".dat";
147  std::ifstream ifs(file.c_str());
148  ASSERT_TRUE(ifs.is_open());
149 
150  std::stringstream fileContent;
151  fileContent << ifs.rdbuf();
152  ifs.close();
153 
154  if (fObj.getPackIncomingDocuments()==false)
155  ASSERT_TRUE(dataContent == fileContent.str());
156 
157  SphinxOutputJsonMessage outputJsonMessage(ret);
158  ASSERT_FALSE(outputJsonMessage.isError());
159  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
160  }
161  else
162  {
163  ASSERT_FALSE(fObj.getErrorMsg().empty());
164  ASSERT_TRUE(fObj.getErrorCode()!=NO_ERROR);
165  SphinxOutputJsonMessage outputJsonMessage(ret);
166  ASSERT_TRUE(!outputJsonMessage.isError());
167  ASSERT_TRUE(outputJsonMessage.getErrorCode()!=NO_ERROR);
168  }
169  printSuccess("Test command INDEX_STORE_DATA_FILE");
170 }
171 //-----------------------------------------------------------------------------
173 {
174  std::string dataContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:schema>\n<sphinx:field name=\"title\"/>\n<sphinx:field name=\"h\"/>\n<sphinx:attr name=\"cdate\" type=\"timestamp\"/>\n</sphinx:schema>\n</sphinx:docset>";
175  testIndexStoreSchemaFile(fObj, indexName, dataContent);
176 }
177 //-----------------------------------------------------------------------------
179 {
180  std::string json;
181  IndexStoreSchemaFile indexStoreSchemaFile(fObj);
182  indexStoreSchemaFile.setIndexName(indexName);
183  indexStoreSchemaFile.setSchemaContent(HCE::encodeBase64(dataContent));
184  ASSERT_TRUE(indexStoreSchemaFile.serialize(json));
185  printSuccess("Serialize IndexStoreSchemaFile");
186 
187  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
188  msgManage->setCommandString("INDEX_STORE_SCHEMA_FILE");
189  msgManage->setCommandOptionsString(json);
190  ASSERT_TRUE(msgManage->serialize(json));
191  printSuccess("Serialize SphinxInputJsonMessageManage");
192 
193  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
194  handler.setData(json);
195 
196  std::stringstream str;
197  str << handler;
198 
199  std::string ret = fObj.Process(str.str());
200  std::cout << "ret: '" << ret << "'\n";
201 
202 // if (!fObj.getErrorMsg().empty() || fObj.getErrorCode())
203 // std::cout << "ErrorMsg: " << fObj.getErrorMsg() << " ErrorCode = " << fObj.getErrorCode() << std::endl;
204 
205  if (!dataContent.empty())
206  {
207  const std::string file = fObj.getDataDir()+"/"+indexName+"/"+sphinx_search_const::sphinxSchemaFile;
208  std::ifstream ifs(file.c_str());
209  ASSERT_TRUE(ifs.is_open());
210 
211  std::stringstream fileContent;
212  fileContent << ifs.rdbuf();
213  ifs.close();
214 
215  ASSERT_TRUE(dataContent == fileContent.str());
216  }
217  SphinxOutputJsonMessage outputJsonMessage(ret);
218  ASSERT_TRUE(!outputJsonMessage.isError());
219  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR || outputJsonMessage.getErrorCode()==ERROR_STORE_SCHEMA_FILE);
220  printSuccess("Test command INDEX_STORE_SCHEMA_FILE");
221 }
222 //-----------------------------------------------------------------------------
223 void SphinxManageTest::testIndexRebuild(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<std::string>& branches)
224 {
225  std::string json;
226  IndexRebuild indexRebuild(fObj);
227  indexRebuild.setIndexName(indexName);
228 
229  for (size_t i=0;i<branches.size();++i)
230  indexRebuild.addBranch(branches[i]);
231 
232  ASSERT_TRUE(indexRebuild.serialize(json));
233 
234 // std::cout << "indexRebuild json: '" << json << "'\n";
235 
236  printSuccess("Serialize IndexRebuild");
237 
238  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
239  msgManage->setCommandString("INDEX_REBUILD");
240  msgManage->setCommandOptionsString(json);
241  ASSERT_TRUE(msgManage->serialize(json));
242  printSuccess("Serialize SphinxInputJsonMessageManage");
243 
244  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
245  handler.setData(json);
246 
247  std::stringstream str;
248  str << handler;
249 
250  std::string ret = fObj.Process(str.str());
251  std::cout << "ret: '" << ret << "'\n";
252  if (!fObj.getErrorMsg().empty())
253  std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
254 
255  SphinxOutputJsonMessage outputJsonMessage(ret);
256  ASSERT_TRUE(!outputJsonMessage.isError());
257  if (!outputJsonMessage.getData().empty())
258  std::cout << "outputJsonMessage.getData(): '" << outputJsonMessage.getData() << "'\n";
259  ASSERT_TRUE(outputJsonMessage.getData().empty());
260  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
261  printSuccess("Test command INDEX_REBUILD");
262 }
263 //-----------------------------------------------------------------------------
264 // cppcheck-suppress unusedFunction
266 {
267  std::string json;
268  IndexSetDataDir indexSetDataDir(fObj);
269 // indexSetDataDir.setIndexName(indexName); //TODO now it reserved
270 
271  ASSERT_TRUE(indexSetDataDir.serialize(json));
272  printSuccess("Serialize IndexSetDataDir");
273 
274  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
275  msgManage->setCommandString("INDEX_SET_DATA_DIR");
276  msgManage->setCommandOptionsString(json);
277  ASSERT_TRUE(msgManage->serialize(json));
278  printSuccess("Serialize SphinxInputJsonMessageManage");
279 
280  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
281  handler.setData(json);
282 
283  std::stringstream str;
284  str << handler;
285 
286  std::string ret = fObj.Process(str.str());
287  std::cout << "ret: '" << ret << "'\n";
288 // if (!fObj.getErrorMsg().empty())
289 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
290 
291  SphinxOutputJsonMessage outputJsonMessage(ret);
292  ASSERT_TRUE(!outputJsonMessage.isError());
293  ASSERT_TRUE(outputJsonMessage.getData().empty());
294  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
295  printSuccess("Test command INDEX_SET_DATA_DIR");
296 }
297 //-----------------------------------------------------------------------------
299 {
300  std::string json;
301  IndexStart indexStart(fObj);
302  indexStart.setIndexName(indexName);
303  ASSERT_TRUE(indexStart.serialize(json));
304  printSuccess("Serialize IndexStart");
305 
306  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
307  msgManage->setCommandString("INDEX_START");
308  msgManage->setCommandOptionsString(json);
309  ASSERT_TRUE(msgManage->serialize(json));
310  printSuccess("Serialize SphinxInputJsonMessageManage");
311 
312  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
313  handler.setData(json);
314 
315  std::stringstream str;
316  str << handler;
317 
318  std::string ret = fObj.Process(str.str());
319  std::cout << "ret: '" << ret << "'\n";
320 // if (!fObj.getErrorMsg().empty())
321 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
322 
323  SphinxOutputJsonMessage outputJsonMessage(ret);
324  ASSERT_TRUE(!outputJsonMessage.isError());
325  ASSERT_TRUE(outputJsonMessage.getData().empty());
326  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
327  printSuccess("Test command INDEX_START");
328 }
329 //-----------------------------------------------------------------------------
331 {
332  std::string json;
333  IndexStop indexStop(fObj);
334  indexStop.setIndexName(indexName);
335  ASSERT_TRUE(indexStop.serialize(json));
336  printSuccess("Serialize IndexStop");
337 
338  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
339  msgManage->setCommandString("INDEX_STOP");
340  msgManage->setCommandOptionsString(json);
341  ASSERT_TRUE(msgManage->serialize(json));
342  printSuccess("Serialize SphinxInputJsonMessageManage");
343 
344  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
345  handler.setData(json);
346 
347  std::stringstream str;
348  str << handler;
349 
350  std::string ret = fObj.Process(str.str());
351  std::cout << "ret: '" << ret << "'\n";
352 // if (!fObj.getErrorMsg().empty())
353 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
354 
355  SphinxOutputJsonMessage outputJsonMessage(ret);
356  ASSERT_TRUE(!outputJsonMessage.isError());
357  ASSERT_TRUE(outputJsonMessage.getData().empty());
358  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
359  printSuccess("Test command INDEX_STOP");
360 }
361 //-----------------------------------------------------------------------------
362 void SphinxManageTest::testIndexMerge(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<std::string>& branches)
363 {
364  std::string json;
365  IndexMerge indexMerge(fObj);
366  indexMerge.setIndexName(indexName);
367 
368  for (size_t i=0;i<branches.size();++i)
369  indexMerge.addBranch(branches[i]);
370 
371  ASSERT_TRUE(indexMerge.serialize(json));
372  printSuccess("Serialize IndexMerge");
373 
374  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
375  msgManage->setCommandString("INDEX_MERGE");
376  msgManage->setCommandOptionsString(json);
377  ASSERT_TRUE(msgManage->serialize(json));
378  printSuccess("Serialize SphinxInputJsonMessageManage");
379 
380  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
381  handler.setData(json);
382 
383  std::stringstream str;
384  str << handler;
385 
386  std::string ret = fObj.Process(str.str());
387  std::cout << "ret: '" << ret << "'\n";
388 
389  SphinxOutputJsonMessage outputJsonMessage(ret);
390  ASSERT_TRUE(!outputJsonMessage.isError());
391  if (!outputJsonMessage.getData().empty())
392  std::cout << "getData: '" << outputJsonMessage.getData() << "'\n";
393  ASSERT_TRUE(outputJsonMessage.getData().empty());
394  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
395  printSuccess("Test command INDEX_MERGE");
396 }
397 //-----------------------------------------------------------------------------
398 void SphinxManageTest::testIndexMergeTrunk(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<std::string>& branches)
399 {
400  std::string json;
401  IndexMergeTrunk indexMergeTrunk(fObj);
402  indexMergeTrunk.setIndexName(indexName);
403 
404  for (size_t i=0;i<branches.size();++i)
405  indexMergeTrunk.addBranch(branches[i]);
406 
407  ASSERT_TRUE(indexMergeTrunk.serialize(json));
408  printSuccess("Serialize IndexMergeTrunk");
409 
410  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
411  msgManage->setCommandString("INDEX_MERGE_TRUNK");
412  msgManage->setCommandOptionsString(json);
413  ASSERT_TRUE(msgManage->serialize(json));
414  printSuccess("Serialize SphinxInputJsonMessageManage");
415 
416  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
417  handler.setData(json);
418 
419  std::stringstream str;
420  str << handler;
421 
422  std::string ret = fObj.Process(str.str());
423  std::cout << "ret: '" << ret << "'\n";
424 
425  SphinxOutputJsonMessage outputJsonMessage(ret);
426  ASSERT_TRUE(!outputJsonMessage.isError());
427  if (!outputJsonMessage.getData().empty())
428  std::cout << "getData: '" << outputJsonMessage.getData() << "'\n";
429  ASSERT_TRUE(outputJsonMessage.getData().empty());
430  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
431  printSuccess("Test command INDEX_MERGE_TRUNK");
432 }
433 //-----------------------------------------------------------------------------
435 {
436  std::string json;
437  IndexDeleteDataFile indexDeleteDataFile(fObj);
438  indexDeleteDataFile.setIndexName(indexName);
439 
440  for (size_t i=0;i<branches.size();++i)
441  indexDeleteDataFile.addBranch(branches[i]);
442 
443  ASSERT_TRUE(indexDeleteDataFile.serialize(json));
444  printSuccess("Serialize IndexDeleteDataFile");
445 
446  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
447  msgManage->setCommandString("INDEX_DELETE_DATA_FILE");
448  msgManage->setCommandOptionsString(json);
449  ASSERT_TRUE(msgManage->serialize(json));
450  printSuccess("Serialize SphinxInputJsonMessageManage");
451 
452  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
453  handler.setData(json);
454 
455  std::stringstream str;
456  str << handler;
457 
458  std::string ret = fObj.Process(str.str());
459  std::cout << "ret: '" << ret << "'\n";
460 // if (!fObj.getErrorMsg().empty())
461 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
462 
463  SphinxOutputJsonMessage outputJsonMessage(ret);
464  ASSERT_TRUE(!outputJsonMessage.isError());
465  ASSERT_TRUE(outputJsonMessage.getData().empty());
466  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
467  printSuccess("Test command INDEX_DELETE_DATA_FILE");
468 }
469 //-----------------------------------------------------------------------------
471 {
472  std::string json;
473  IndexDeleteSchemaFile indexDeleteSchemaFile(fObj);
474  indexDeleteSchemaFile.setIndexName(indexName);
475 
476  ASSERT_TRUE(indexDeleteSchemaFile.serialize(json));
477  printSuccess("Serialize IndexDeleteSchemaFile");
478 
479  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
480  msgManage->setCommandString("INDEX_DELETE_SCHEMA_FILE");
481  msgManage->setCommandOptionsString(json);
482  ASSERT_TRUE(msgManage->serialize(json));
483  printSuccess("Serialize SphinxInputJsonMessageManage");
484 
485  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
486  handler.setData(json);
487 
488  std::stringstream str;
489  str << handler;
490 
491  std::string ret = fObj.Process(str.str());
492  std::cout << "ret: '" << ret << "'\n";
493 // if (!fObj.getErrorMsg().empty())
494 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
495 
496  SphinxOutputJsonMessage outputJsonMessage(ret);
497  ASSERT_TRUE(!outputJsonMessage.isError());
498  ASSERT_TRUE(outputJsonMessage.getData().empty());
499  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
500  printSuccess("Test command INDEX_DELETE_SCHEMA_FILE");
501 }
502 //-----------------------------------------------------------------------------
504 {
505  std::string json;
506  std::stringstream dataContent;
507  dataContent << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"123456\">\n"
508  << "<title><![CDATA[[$ fObj --merge main delta --merge-dst-range deleted 0 0]]></title>\n"
509  << "<h><![CDATA[[Any documents marked as deleted (value 1) would be removed from the newly-merged destination index. It can be added several times to the command line, to add successive filters to the merge, all of which must be met in order for a document to become part of the final index.]]></h>\n"
510  << "</sphinx:document>\n<sphinx:document id=\"444\">\n"
511  << "<title><![CDATA[[$ fObj --merge main delta ]]></title>\n"
512  << "<h><![CDATA[[It can be added several times to the command line.]]></h>\n"
513  << "</sphinx:document>\n</sphinx:docset>";
514 
515  IndexAppendDataFile indexAppendDataFile(fObj);
516  indexAppendDataFile.setIndexName(indexName);
517  indexAppendDataFile.setBranchName(branchName);
518  indexAppendDataFile.setDataContent(HCE::encodeBase64(dataContent.str()));
519  ASSERT_TRUE(indexAppendDataFile.serialize(json));
520  printSuccess("Serialize IndexAppendDataFile");
521 
522  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
523  msgManage->setCommandString("INDEX_APPEND_DATA_FILE");
524  msgManage->setCommandOptionsString(json);
525  ASSERT_TRUE(msgManage->serialize(json));
526  printSuccess("Serialize SphinxInputJsonMessageManage");
527 
528  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
529  handler.setData(json);
530 
531  std::stringstream str;
532  str << handler;
533 
534  std::string ret = fObj.Process(str.str());
535  std::cout << "ret: '" << ret << "'\n";
536 
537  ASSERT_TRUE(fObj.getErrorMsg().empty());
538  ASSERT_TRUE(fObj.getErrorCode()==NO_ERROR);
539 
540  const std::string file = fObj.getDataDir()+"/"+indexName+"/"+sphinx_admin_command_const::dataDir+"/"+branchName+".dat";
541  std::ifstream ifs(file.c_str());
542  ASSERT_TRUE(ifs.is_open());
543 
544  bool isFound = false;
545  std::string line;
546  while(getline(ifs, line))
547  {
548  if (line.find("444")!=std::string::npos)
549  {
550  isFound = true;
551  break;
552  }
553  }
554  ifs.close();
555  ASSERT_TRUE(isFound==true);
556 
557  SphinxOutputJsonMessage outputJsonMessage(ret);
558  ASSERT_TRUE(!outputJsonMessage.isError());
559  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
560  printSuccess("Test command INDEX_APPEND_DATA_FILE");
561 }
562 //-----------------------------------------------------------------------------
563 void SphinxManageTest::testIndexDeleteDoc(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<unsigned long long>& ids)
564 {
565  std::string json;
566  IndexDeleteDoc indexDeleteDoc(fObj);
567  indexDeleteDoc.setIndexName(indexName);
568 
569  for (size_t i=0;i<ids.size();++i)
570  indexDeleteDoc.addId(ids[i]);
571 
572  ASSERT_TRUE(indexDeleteDoc.serialize(json));
573  printSuccess("Serialize IndexDeleteDoc");
574 
575  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
576  msgManage->setCommandString("INDEX_DELETE_DOC");
577  msgManage->setCommandOptionsString(json);
578  ASSERT_TRUE(msgManage->serialize(json));
579  printSuccess("Serialize SphinxInputJsonMessageManage");
580 
581  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
582  handler.setData(json);
583 
584  std::stringstream str;
585  str << handler;
586 
587  std::string ret = fObj.Process(str.str());
588  std::cout << "ret: '" << ret << "'\n";
589 // if (!fObj.getErrorMsg().empty())
590 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
591 
592  const std::string file = fObj.getDataDir()+"/"+indexName+"/"+sphinx_admin_command_const::deletedFileName;
593  std::ifstream ifs(file.c_str());
594  ASSERT_TRUE(ifs.is_open());
595 
596  // check wrote data in file
597  std::set<unsigned long long> readIds;
598  std::string line;
599  while(getline(ifs, line))
600  {
601  try
602  {
603  readIds.insert(std::stoull(line));
604  }
605  catch(...)
606  {
607  std::cout << "std::stoull(" << line << ") - BAD param." << std::endl;
608  }
609  }
610  ifs.close();
611 
612  for (size_t i=0;i<ids.size();++i)
613  ASSERT_TRUE(readIds.find(ids[i])!=readIds.end());
614 
615  SphinxOutputJsonMessage outputJsonMessage(ret);
616  ASSERT_TRUE(!outputJsonMessage.isError());
617  ASSERT_TRUE(outputJsonMessage.getData().empty());
618  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
619  printSuccess("Test command INDEX_DELETE_DOC");
620 }
621 //-----------------------------------------------------------------------------
623 {
624  std::string json;
625  IndexDeleteDocNumber indexDeleteDocNumber(fObj);
626  indexDeleteDocNumber.setIndexName(indexName);
627 
628  ASSERT_TRUE(indexDeleteDocNumber.serialize(json));
629  printSuccess("Serialize IndexDeleteDocNumber");
630 
631  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
632  msgManage->setCommandString("INDEX_DELETE_DOC_NUMBER");
633  msgManage->setCommandOptionsString(json);
634  ASSERT_TRUE(msgManage->serialize(json));
635  printSuccess("Serialize SphinxInputJsonMessageManage");
636 
637  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
638  handler.setData(json);
639 
640  std::stringstream str;
641  str << handler;
642 
643  std::string ret = fObj.Process(str.str());
644  std::cout << "ret: '" << ret << "'\n";
645 // if (!fObj.getErrorMsg().empty())
646 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
647 
648  SphinxOutputJsonMessage outputJsonMessage(ret);
649  ASSERT_TRUE(!outputJsonMessage.isError());
650  ASSERT_TRUE(!outputJsonMessage.getData().empty());
651  std::cout << "deleted list count = " << outputJsonMessage.getData() << std::endl;
652 
653  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
654  printSuccess("Test command INDEX_DELETE_DOC_NUMBER");
655 }
656 //-----------------------------------------------------------------------------
657 void SphinxManageTest::testIndexPackDocData(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<std::string>& branches)
658 {
659  std::string json;
660  IndexPackDocData indexPackDocData(fObj);
661  indexPackDocData.setIndexName(indexName);
662 
663  for (size_t i=0;i<branches.size();++i)
664  indexPackDocData.addBranch(branches[i]);
665 
666  ASSERT_TRUE(indexPackDocData.serialize(json));
667  printSuccess("Serialize IndexPackDocData");
668 
669  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
670  msgManage->setCommandString("INDEX_PACK_DOC_DATA");
671  msgManage->setCommandOptionsString(json);
672  ASSERT_TRUE(msgManage->serialize(json));
673  printSuccess("Serialize SphinxInputJsonMessageManage");
674 
675  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
676  handler.setData(json);
677 
678  std::stringstream str;
679  str << handler;
680 
681  std::string ret = fObj.Process(str.str());
682  std::cout << "ret: '" << ret << "'\n";
683 // if (!fObj.getErrorMsg().empty())
684 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
685 
686  SphinxOutputJsonMessage outputJsonMessage(ret);
687  ASSERT_TRUE(!outputJsonMessage.isError());
688  ASSERT_TRUE(!outputJsonMessage.getData().empty());
689  std::cout << "Document count = " << outputJsonMessage.getData() << std::endl;
690  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
691  printSuccess("Test command INDEX_PACK_DOC_DATA");
692 }
693 //-----------------------------------------------------------------------------
694 //-----------------------------------------------------------------------------
696 {
697  fObj.setErrorMsg("");
698 
699  std::string json;
700  IndexRemove indexCreate(fObj);
701  indexCreate.setIndexName(indexName);
702  ASSERT_TRUE(indexCreate.serialize(json));
703  printSuccess("Serialize IndexRemove");
704 
705  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
706  msgManage->setCommandString("INDEX_REMOVE");
707  msgManage->setCommandOptionsString(json);
708  ASSERT_TRUE(msgManage->serialize(json));
709  printSuccess("Serialize SphinxInputJsonMessageManage");
710 
711  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
712  handler.setData(json);
713 
714  std::stringstream str;
715  str << handler;
716 
717  std::string ret = fObj.Process(str.str());
718  std::cout << "ret: '" << ret << "'\n";
719 // if (!fObj.getErrorMsg().empty())
720 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
721 
722  SphinxOutputJsonMessage outputJsonMessage(ret);
723  ASSERT_TRUE(!outputJsonMessage.isError());
724  ASSERT_TRUE(outputJsonMessage.getData().empty());
725  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
726  printSuccess("Test command INDEX_REMOVE");
727 }
728 //-----------------------------------------------------------------------------
729 //-----------------------------------------------------------------------------
731 {
732  std::string json;
733  IndexCopy indexCopy(fObj);
734  indexCopy.setIndexFromName(indexFromName);
735  indexCopy.setIndexToName(indexToName);
736  ASSERT_TRUE(indexCopy.serialize(json));
737  printSuccess("Serialize IndexCopy");
738 
739  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
740  msgManage->setCommandString("INDEX_COPY");
741  msgManage->setCommandOptionsString(json);
742  ASSERT_TRUE(msgManage->serialize(json));
743  printSuccess("Serialize SphinxInputJsonMessageManage");
744 
745  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
746  handler.setData(json);
747 
748  std::stringstream str;
749  str << handler;
750 
751  std::string ret = fObj.Process(str.str());
752  std::cout << "ret: '" << ret << "'\n";
753 // if (!fObj.getErrorMsg().empty())
754 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
755 
756  SphinxOutputJsonMessage outputJsonMessage(ret);
757  ASSERT_TRUE(!outputJsonMessage.isError());
758  ASSERT_TRUE(outputJsonMessage.getData().empty());
759  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
760  printSuccess("Test command INDEX_COPY");
761 }
762 //-----------------------------------------------------------------------------
763 //-----------------------------------------------------------------------------
765 {
766  std::string json;
767  IndexRename indexRename(fObj);
768  indexRename.setIndexFromName(indexFromName);
769  indexRename.setIndexToName(indexToName);
770  ASSERT_TRUE(indexRename.serialize(json));
771  printSuccess("Serialize IndexRename");
772 
773  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
774  msgManage->setCommandString("INDEX_RENAME");
775  msgManage->setCommandOptionsString(json);
776  ASSERT_TRUE(msgManage->serialize(json));
777  printSuccess("Serialize SphinxInputJsonMessageManage");
778 
779  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
780  handler.setData(json);
781 
782  std::stringstream str;
783  str << handler;
784 
785  std::string ret = fObj.Process(str.str());
786  std::cout << "ret: '" << ret << "'\n";
787 // if (!fObj.getErrorMsg().empty())
788 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
789 
790  SphinxOutputJsonMessage outputJsonMessage(ret);
791  ASSERT_TRUE(!outputJsonMessage.isError());
792  ASSERT_TRUE(outputJsonMessage.getData().empty());
793  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
794  printSuccess("Test command INDEX_RENAME");
795 }
796 //-----------------------------------------------------------------------------
797 //-----------------------------------------------------------------------------
798 void SphinxManageTest::testIndexSetConfigVar(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, const std::string& branchName, const std::string& sectionName,
799  const std::string& parameterName, const std::string& parameterValue)
800 {
801  std::string json;
802  IndexSetConfigVar indexSetConfigVar(fObj);
803  indexSetConfigVar.setIndexName(indexName);
804  indexSetConfigVar.setBranchName(branchName);
805  indexSetConfigVar.setSectionName(sectionName);
806  indexSetConfigVar.setParameterName(parameterName);
807  indexSetConfigVar.setParameterValue(parameterValue);
808  ASSERT_TRUE(indexSetConfigVar.serialize(json));
809  printSuccess("Serialize IndexSetConfigVar");
810 
811  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
812  msgManage->setCommandString("INDEX_SET_CONFIG_VAR");
813  msgManage->setCommandOptionsString(json);
814  ASSERT_TRUE(msgManage->serialize(json));
815  printSuccess("Serialize SphinxInputJsonMessageManage");
816 
817  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
818  handler.setData(json);
819 
820  std::stringstream str;
821  str << handler;
822 
823  std::string ret = fObj.Process(str.str());
824  std::cout << "ret: '" << ret << "'\n";
825 
826  SphinxOutputJsonMessage outputJsonMessage(ret);
827  ASSERT_TRUE(!outputJsonMessage.isError());
828  ASSERT_TRUE(outputJsonMessage.getData().empty());
829  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
830  printSuccess("Test command INDEX_SET_CONFIG_VAR");
831 }
832 //-----------------------------------------------------------------------------
833 //-----------------------------------------------------------------------------
835  const std::string& sectionName, const std::string& parameterName, std::string& parameterValue)
836 {
837  std::string json;
838  IndexGetConfigVar indexGetConfigVar(fObj);
839  indexGetConfigVar.setIndexName(indexName);
840  indexGetConfigVar.setBranchName(branchName);
841  indexGetConfigVar.setSectionName(sectionName);
842  indexGetConfigVar.setParameterName(parameterName);
843  ASSERT_TRUE(indexGetConfigVar.serialize(json));
844  printSuccess("Serialize IndexGetConfigVar");
845 
846  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
847  msgManage->setCommandString("INDEX_GET_CONFIG_VAR");
848  msgManage->setCommandOptionsString(json);
849  ASSERT_TRUE(msgManage->serialize(json));
850  printSuccess("Serialize SphinxInputJsonMessageManage");
851 
852  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
853  handler.setData(json);
854 
855  std::stringstream str;
856  str << handler;
857 
858  std::string ret = fObj.Process(str.str());
859  std::cout << "ret: '" << ret << "'\n";
860 
861  SphinxOutputJsonMessage outputJsonMessage(ret);
862  ASSERT_TRUE(!outputJsonMessage.isError());
863  ASSERT_TRUE(!outputJsonMessage.getData().empty());
864  std::cout << "Parameter value: '" << outputJsonMessage.getData() << "'" << std::endl;
865  parameterValue = outputJsonMessage.getData();
866  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
867  printSuccess("Test command INDEX_GET_CONFIG_VAR");
868 }
869 //-----------------------------------------------------------------------------
870 //-----------------------------------------------------------------------------
872 {
873  std::string json;
874  std::string dataContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:schema>\n<sphinx:field name = \"title\" weight=\"2\"/>\n<sphinx:field name=\"h\" weight=\"5\"/>\n</sphinx:schema>\n</sphinx:docset>";
875 
876  IndexCheckSchema indexCheckSchema(fObj);
877  indexCheckSchema.setIndexName(indexName);
878  indexCheckSchema.setSchemaContent(HCE::encodeBase64(dataContent));
879  ASSERT_TRUE(indexCheckSchema.serialize(json));
880  printSuccess("Serialize IndexCheckSchema");
881 
882  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
883  msgManage->setCommandString("INDEX_CHECK_SCHEMA");
884  msgManage->setCommandOptionsString(json);
885  ASSERT_TRUE(msgManage->serialize(json));
886  printSuccess("Serialize SphinxInputJsonMessageManage");
887 
888  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
889  handler.setData(json);
890 
891  std::stringstream str;
892  str << handler;
893 
894  std::string ret = fObj.Process(str.str());
895  std::cout << "ret: '" << ret << "'\n";
896 // if (!fObj.getErrorMsg().empty())
897 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
898 
899  SphinxOutputJsonMessage outputJsonMessage(ret);
900  ASSERT_TRUE(!outputJsonMessage.isError());
901  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
902  printSuccess("Test command INDEX_CHECK_SCHEMA");
903 }
904 //-----------------------------------------------------------------------------
905 //-----------------------------------------------------------------------------
907 {
908  std::string json;
909  IndexStatusSearchd indexStatusSearchd(fObj);
910  indexStatusSearchd.setIndexName(indexName);
911  ASSERT_TRUE(indexStatusSearchd.serialize(json));
912  printSuccess("Serialize IndexStatusSearchd");
913 
914  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
915  msgManage->setCommandString("INDEX_STATUS_SEARCHD");
916  msgManage->setCommandOptionsString(json);
917  ASSERT_TRUE(msgManage->serialize(json));
918  printSuccess("Serialize SphinxInputJsonMessageManage");
919 
920  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
921  handler.setData(json);
922 
923  std::stringstream str;
924  str << handler;
925 
926  std::string ret = fObj.Process(str.str());
927  std::cout << "ret: '" << ret << "'\n";
928 // if (!fObj.getErrorMsg().empty())
929 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
930 
931  SphinxOutputJsonMessage outputJsonMessage(ret);
932  ASSERT_TRUE(!outputJsonMessage.isError());
933 // std::cout << "Data:\n" << outputJsonMessage.getData() << std::endl;
934  ASSERT_TRUE(!outputJsonMessage.getData().empty());
935  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
936  printSuccess("Test command INDEX_STATUS_SEARCHD");
937 }
938 //-----------------------------------------------------------------------------
939 //-----------------------------------------------------------------------------
941 {
942  std::string json;
943  IndexStatus indexStatus(fObj);
944  indexStatus.setIndexName(indexName);
945  ASSERT_TRUE(indexStatus.serialize(json));
946  printSuccess("Serialize IndexStatus");
947 
948  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
949  msgManage->setCommandString("INDEX_STATUS");
950  msgManage->setCommandOptionsString(json);
951  ASSERT_TRUE(msgManage->serialize(json));
952  printSuccess("Serialize SphinxInputJsonMessageManage");
953 
954  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
955  handler.setData(json);
956 
957  std::stringstream str;
958  str << handler;
959 
960  std::string ret = fObj.Process(str.str());
961  std::cout << "ret: '" << ret << "'\n";
962 // if (!fObj.getErrorMsg().empty())
963 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
964 
965  SphinxOutputJsonMessage outputJsonMessage(ret);
966  ASSERT_TRUE(!outputJsonMessage.isError());
967 // std::cout << "Data:\n" << outputJsonMessage.getData() << std::endl;
968  ASSERT_TRUE(!outputJsonMessage.getData().empty());
969  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
970  printSuccess("Test command INDEX_STATUS");
971 }
972 //-----------------------------------------------------------------------------
973 //-----------------------------------------------------------------------------
975 {
976 // assert(fObj.isLoadedConfig());
977 
978  std::string json;
979  IndexMaxDocId indexMaxDocId(fObj);
980  indexMaxDocId.setIndexName(indexName);
981  assert(indexMaxDocId.serialize(json));
982  printSuccess("Serialize IndexMaxDocId");
983 
984  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
985  msgManage->setCommandString("INDEX_MAX_DOC_ID");
986  msgManage->setCommandOptionsString(json);
987  assert(msgManage->serialize(json));
988  printSuccess("Serialize SphinxInputJsonMessageManage");
989 
990  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
991  handler.setData(json);
992 
993  std::stringstream str;
994  str << handler;
995 
996  std::string ret = fObj.Process(str.str());
997  std::cout << "ret: '" << ret << "'\n";
998 // if (!fObj.getErrorMsg().empty())
999 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1000 
1001  SphinxOutputJsonMessage outputJsonMessage(ret);
1002  assert(!outputJsonMessage.isError());
1003 // std::cout << "MaxDocId = " << outputJsonMessage.getData() << std::endl;
1004  assert(!outputJsonMessage.getData().empty());
1005  assert(outputJsonMessage.getErrorCode()==NO_ERROR);
1006  printSuccess("Test command INDEX_MAX_DOC_ID");
1007  return std::stoull(outputJsonMessage.getData());
1008 }
1009 //-----------------------------------------------------------------------------
1010 //-----------------------------------------------------------------------------
1012 {
1013  std::vector<std::string> branches = {"*"};
1014  SphinxManageTest::testIndexDeleteDataFile(fObj, indexName, branches);
1017 
1018  std::stringstream dataContent;
1019  dataContent << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"123\">\n"
1020  << "<title><![CDATA[[- Information interchange - Representation of dates and times. A discussion of ISO 8601 has been written by Markus Kuhn. ISO 8601 describes a large number of date/time formats. For example it defines Basic Format, without punctuation, and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.]]></title>\n"
1021  << "<h><![CDATA[[time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions. The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the \"T\" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>\n"
1022  << "</sphinx:document>\n</sphinx:docset>";
1023 
1024  SphinxManageTest::testIndexStoreDataFile(fObj, indexName, "b0001", dataContent.str());
1025  SphinxManageTest::testIndexRebuild(fObj, indexName, branches);
1026  unsigned long long firstMaxDocID = SphinxManageTest::testIndexMaxDocId(fObj, indexName);
1027 
1028  dataContent.str("");
1029  dataContent << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"133\">\n"
1030  << "<title><![CDATA[[- Information interchange - ISO 8601 describes a large , and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.]]></title>\n"
1031  << "<h><![CDATA[[time, so this profile defines six levels. omparing two dates with different precisions. The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the \"T\" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>\n"
1032  << "</sphinx:document>\n"
1033  << "\n<sphinx:document id=\"53\">\n"
1034  << "<title><![CDATA[[ There are more differences between 'gcc' and 'g++' than only the standard libraries, so gcc -lstdc++ will still not get you the same behavior as g++. We put all of that language-specific behavior into its own driver .]]></title>\n"
1035  << "<h><![CDATA[[There are more differences between 'gcc' and 'g++' than only the standard libraries, so gcc -lstdc++ will still not get you the same behavior as g++. We put all of that language-specific behavior into its own driver ]]></h>\n"
1036  << "</sphinx:document>\n</sphinx:docset>";
1037 
1038  SphinxManageTest::testIndexStoreDataFile(fObj, indexName, "b0002", dataContent.str());
1039  SphinxManageTest::testIndexRebuild(fObj, indexName, branches);
1040  unsigned long long secondMaxDocID = SphinxManageTest::testIndexMaxDocId(fObj, indexName);
1041 
1042  branches.clear();
1043  branches.push_back("b0002");
1044  SphinxManageTest::testIndexDeleteDataFile(fObj, indexName, branches);
1045  SphinxManageTest::testIndexRebuild(fObj, indexName, branches);
1046  unsigned long long threeMaxDocID = SphinxManageTest::testIndexMaxDocId(fObj, indexName);
1047 
1048  branches.clear();
1049  branches.push_back("*");
1050  SphinxManageTest::testIndexStoreDataFile(fObj, indexName, "b0002", dataContent.str());
1051  SphinxManageTest::testIndexAppendDataFile(fObj, indexName, "b0001");
1052  SphinxManageTest::testIndexRebuild(fObj, indexName, branches);
1053  unsigned long long fourMaxDocID = SphinxManageTest::testIndexMaxDocId(fObj, indexName);
1054 
1055  branches.clear();
1056  branches.push_back("b0001");
1057  SphinxManageTest::testIndexDeleteDataFile(fObj, indexName, branches);
1058  SphinxManageTest::testIndexRebuild(fObj, indexName, branches);
1059  unsigned long long fiveMaxDocID = SphinxManageTest::testIndexMaxDocId(fObj, indexName);
1060 
1061 // std::cout << "1) maxDocID = " << firstMaxDocID << std::endl;
1062 // std::cout << "2) maxDocID = " << secondMaxDocID << std::endl;
1063 // std::cout << "3) maxDocID = " << threeMaxDocID << std::endl;
1064 // std::cout << "4) maxDocID = " << fourMaxDocID << std::endl;
1065 // std::cout << "5) maxDocID = " << fiveMaxDocID << std::endl;
1066 
1067 // std::cout << "(" << firstMaxDocID << " == " << threeMaxDocID << ") -> " << ((firstMaxDocID==threeMaxDocID)?"GOOD":"BAD") << std::endl;
1068 // std::cout << "(" << secondMaxDocID << " == " << fiveMaxDocID << ") -> " << ((secondMaxDocID==fiveMaxDocID)?"GOOD":"BAD") << std::endl;
1069  ASSERT_TRUE(fourMaxDocID);
1070  ASSERT_TRUE(firstMaxDocID==threeMaxDocID);
1071  ASSERT_TRUE(secondMaxDocID==fiveMaxDocID);
1072  printSuccess("Extended test command INDEX_MAX_DOC_ID");
1073 }
1074 //-----------------------------------------------------------------------------
1075 //-----------------------------------------------------------------------------
1077 {
1078  std::string json;
1079  IndexDataList indexDataList(fObj);
1080  indexDataList.setIndexName(indexName);
1081  ASSERT_TRUE(indexDataList.serialize(json));
1082  printSuccess("Serialize IndexDataList");
1083 
1084  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1085  msgManage->setCommandString("INDEX_DATA_LIST");
1086  msgManage->setCommandOptionsString(json);
1087  ASSERT_TRUE(msgManage->serialize(json));
1088  printSuccess("Serialize SphinxInputJsonMessageManage");
1089 
1090  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1091  handler.setData(json);
1092 
1093  std::stringstream str;
1094  str << handler;
1095 
1096  std::string ret = fObj.Process(str.str());
1097  std::cout << "ret: '" << ret << "'\n";
1098 // if (!fObj.getErrorMsg().empty())
1099 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1100 
1101  SphinxOutputJsonMessage outputJsonMessage(ret);
1102  ASSERT_TRUE(!outputJsonMessage.isError());
1103 // std::cout << "Data: " << outputJsonMessage.getData() << std::endl;
1104  ASSERT_TRUE(!outputJsonMessage.getData().empty());
1105  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1106  printSuccess("Test command INDEX_DATA_LIST");
1107 }
1108 //-----------------------------------------------------------------------------
1109 //-----------------------------------------------------------------------------
1111 {
1112  std::string json;
1113  IndexBranchesList indexBranchesList(fObj);
1114  indexBranchesList.setIndexName(indexName);
1115  ASSERT_TRUE(indexBranchesList.serialize(json));
1116  printSuccess("Serialize IndexBranchesList");
1117 
1118  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1119  msgManage->setCommandString("INDEX_BRANCHES_LIST");
1120  msgManage->setCommandOptionsString(json);
1121  ASSERT_TRUE(msgManage->serialize(json));
1122  printSuccess("Serialize SphinxInputJsonMessageManage");
1123 
1124  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1125  handler.setData(json);
1126 
1127  std::stringstream str;
1128  str << handler;
1129 
1130  std::string ret = fObj.Process(str.str());
1131  std::cout << "ret: '" << ret << "'\n";
1132 // if (!fObj.getErrorMsg().empty())
1133 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1134 
1135  SphinxOutputJsonMessage outputJsonMessage(ret);
1136  ASSERT_TRUE(!outputJsonMessage.isError());
1137 // std::cout << "Data: " << outputJsonMessage.getData() << std::endl;
1138  ASSERT_TRUE(!outputJsonMessage.getData().empty());
1139  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1140  printSuccess("Test command INDEX_BRANCHES_LIST");
1141 }
1142 //-----------------------------------------------------------------------------
1143 //-----------------------------------------------------------------------------
1144 void SphinxManageTest::testIndexBranchesInfo(HCE::sphinx::SphinxFunctionalObject& fObj, const std::string& indexName, std::vector<std::string>& branches)
1145 {
1146  std::string json;
1147  IndexBranchesInfo indexBranchesInfo(fObj);
1148  indexBranchesInfo.setIndexName(indexName);
1149  for (size_t i=0;i<branches.size();++i)
1150  indexBranchesInfo.addBranch(branches[i]);
1151  ASSERT_TRUE(indexBranchesInfo.serialize(json));
1152  printSuccess("Serialize IndexBranchesInfo");
1153 
1154  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1155  msgManage->setCommandString("INDEX_BRANCHES_INFO");
1156  msgManage->setCommandOptionsString(json);
1157  ASSERT_TRUE(msgManage->serialize(json));
1158  printSuccess("Serialize SphinxInputJsonMessageManage");
1159 
1160  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1161  handler.setData(json);
1162 
1163  std::stringstream str;
1164  str << handler;
1165 
1166  std::string ret = fObj.Process(str.str());
1167  std::cout << "ret: '" << ret << "'\n";
1168 // if (!fObj.getErrorMsg().empty())
1169 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1170 
1171  SphinxOutputJsonMessage outputJsonMessage(ret);
1172  ASSERT_TRUE(!outputJsonMessage.isError());
1173 // std::cout << "Data: " << outputJsonMessage.getData() << std::endl;
1174  ASSERT_TRUE(!outputJsonMessage.getData().empty());
1175  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1176  printSuccess("Test command INDEX_BRANCHES_INFO");
1177 }
1178 //-----------------------------------------------------------------------------
1179 //-----------------------------------------------------------------------------
1181 {
1182  std::string json;
1183  IndexBranchesStatus indexBranchesStatus(fObj);
1184  indexBranchesStatus.setIndexName(indexName);
1185  for (size_t i=0;i<branches.size();++i)
1186  indexBranchesStatus.addBranch(branches[i]);
1187  ASSERT_TRUE(indexBranchesStatus.serialize(json));
1188  printSuccess("Serialize IndexBranchesStatus");
1189 
1190  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1191  msgManage->setCommandString("INDEX_BRANCHES_STATUS");
1192  msgManage->setCommandOptionsString(json);
1193  ASSERT_TRUE(msgManage->serialize(json));
1194  printSuccess("Serialize SphinxInputJsonMessageManage");
1195 
1196  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1197  handler.setData(json);
1198 
1199  std::stringstream str;
1200  str << handler;
1201 
1202  std::string ret = fObj.Process(str.str());
1203  std::cout << "ret: '" << ret << "'\n";
1204 // if (!fObj.getErrorMsg().empty())
1205 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1206 
1207  SphinxOutputJsonMessage outputJsonMessage(ret);
1208  ASSERT_TRUE(!outputJsonMessage.isError());
1209 // std::cout << "Data: " << outputJsonMessage.getData() << std::endl;
1210  ASSERT_TRUE(!outputJsonMessage.getData().empty());
1211  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1212  printSuccess("Test command INDEX_BRANCHES_STATUS");
1213 }
1214 //-----------------------------------------------------------------------------
1215 //-----------------------------------------------------------------------------
1217 {
1218  const unsigned int SZ = 3;
1219  Poco::SharedPtr<HCE::sphinx::SphinxFunctionalObject> pObj[SZ];
1220  for (unsigned int i=0;i<SZ;++i)
1221  {
1222  pObj[i] = new HCE::sphinx::SphinxFunctionalObject(fObj.getNodeName(), fObj.getHomeDir());
1223 // pObj[i]->setLogStream(std::cout);
1224 
1225  std::string json;
1226  IndexConnect indexConnect(*(pObj[i]));
1227  indexConnect.setIndexName(indexName);
1228  ASSERT_TRUE(indexConnect.serialize(json));
1229  printSuccess("Serialize IndexConnect");
1230 
1231  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1232  msgManage->setCommandString("INDEX_CONNECT");
1233  msgManage->setCommandOptionsString(json);
1234  ASSERT_TRUE(msgManage->serialize(json));
1235  printSuccess("Serialize SphinxInputJsonMessageManage");
1236 
1237  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1238  handler.setData(json);
1239 
1240  std::stringstream str;
1241  str << handler;
1242 
1243  std::string ret = pObj[i]->Process(str.str());
1244  std::cout << "ret: '" << ret << "'" << std::endl;
1245 // if (!pObj[i]->getErrorMsg().empty())
1246 // std::cout << "Error: '" << pObj[i]->getErrorMsg() << "'\n";
1247 
1248  SphinxOutputJsonMessage outputJsonMessage(ret);
1249  ASSERT_TRUE(!outputJsonMessage.isError());
1250  ASSERT_TRUE(outputJsonMessage.getData().empty());
1251  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1252  }
1253  printSuccess("Test command INDEX_CONNECT");
1254 }
1255 //-----------------------------------------------------------------------------
1256 //-----------------------------------------------------------------------------
1258 {
1259  std::string json;
1260  IndexDisconnect indexDisconnect(fObj);
1261  ASSERT_TRUE(indexDisconnect.serialize(json));
1262  printSuccess("Serialize IndexDisconnect");
1263 
1264  Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage = new SphinxInputJsonMessageManage();
1265  msgManage->setCommandString("INDEX_DISCONNECT");
1266  msgManage->setCommandOptionsString(json);
1267  ASSERT_TRUE(msgManage->serialize(json));
1268  printSuccess("Serialize SphinxInputJsonMessageManage");
1269 
1270  SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
1271  handler.setData(json);
1272 
1273  std::stringstream str;
1274  str << handler;
1275 
1276  std::string ret = fObj.Process(str.str());
1277  std::cout << "ret: '" << ret << "'" << std::endl;
1278 // if (!fObj.getErrorMsg().empty())
1279 // std::cout << "Error: '" << fObj.getErrorMsg() << "'\n";
1280 
1281  SphinxOutputJsonMessage outputJsonMessage(ret);
1282  ASSERT_TRUE(!outputJsonMessage.isError());
1283  ASSERT_TRUE(outputJsonMessage.getData().empty());
1284  ASSERT_TRUE(outputJsonMessage.getErrorCode()==NO_ERROR);
1285  printSuccess("Test command INDEX_DISCONNECT");
1286 }
1287 //-----------------------------------------------------------------------------
1288 //-----------------------------------------------------------------------------
1289 } // end namespace tests
1290 } // end namespace sphinx
1291 } // end namespace HCE