hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxResultDataAccumulatorTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxResultAccumulatorTest.cpp
3  *
4  * Created on: May 15, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
12 
13 using namespace HCE::sphinx;
14 using namespace HCE::sphinx::reduce_task;
15 using namespace Poco;
16 
17 TEST(SphinxResultDataAccumulator, accumulateEmptyResult)
18 {
19  SphinxResultData emptySphinxResultData;
20  SharedPtr<SphinxReduceDataStorage>sphinxDataStorage(new SphinxReduceDataStorage());
21 
22  SphinxResultDataAccumulator sphinxResultDataAccumulator(sphinxDataStorage);
23 
24  sphinxResultDataAccumulator.accumulate(emptySphinxResultData);
25 
26  ASSERT_EQ(sphinxResultDataAccumulator.getAllSphinxRequestInfo().size(), 0U);
27  sphinxResultDataAccumulator.getSphinxDataStorage()->reset();
28  ASSERT_TRUE(sphinxResultDataAccumulator.getSphinxDataStorage()->hasNext() == false);
29 }
30 
31 
32 class SphinxResultDataAccumulatorTest: public ::testing::Test{
33  protected:
34  virtual void SetUp(){
35  query1 = "query";
36  totalRes1 = 2;
37  totalFound1 = 13;
38  time1 = 55;
39 
40  WordInfo word1 = WordInfo("word1", 10, 3);
41  WordInfo word2 = WordInfo("word2", 1, 1);
42 
43  matchInfo1 = buildSimpleMatchInfo(7LLU, 11LLU);
44  matchInfo2 = buildSimpleMatchInfo(9LLU, 22LLU);
45  matchInfo3 = buildSimpleMatchInfo(15LLU, 674387LLU);
46 
47  AttrInfo attrInfo1("first", "value");
48 
49  matchInfo1.addAttrInfo(attrInfo1);
50  matchInfo2.addAttrInfo(attrInfo1);
51  matchInfo3.addAttrInfo(attrInfo1);
52 
53  sphinxRequestInfo.setQuery(query1);
54  sphinxRequestInfo.setTotal(totalRes1);
55  sphinxRequestInfo.setTotalFound(totalFound1);
56  sphinxRequestInfo.setTimeMsec(time1);
57  sphinxRequestInfo.addWordInfo(word1);
58  sphinxRequestInfo.addWordInfo(word2);
59 
60  sphinxResultData1.addMatchInfo(matchInfo1);
61  sphinxResultData1.addMatchInfo(matchInfo2);
62  sphinxResultData1.addRequestInfo(sphinxRequestInfo);
63 
64  sphinxResultData2.addMatchInfo(matchInfo3);
65  }
66 
67  string query1;
68  string key;
69  string weight;
70  int totalRes1;
72  int time1;
73 
80 };
81 
82 
83 TEST_F(SphinxResultDataAccumulatorTest, accumulateSeveralResources)
84 {
85  map<string, bool> expectStorage;
86  expectStorage.insert(make_pair(to_string(matchInfo1.getDocId()) + matchInfo1.getWeight(),
87  true));
88  expectStorage.insert(make_pair(to_string(matchInfo2.getDocId()) + matchInfo2.getWeight(),
89  true));
90  expectStorage.insert(make_pair(to_string(matchInfo3.getDocId()) + matchInfo3.getWeight(),
91  true));
92 
93  int storageElemNumber = 0;
94  SharedPtr<SphinxReduceDataStorage>sphinxDataStorage(new SphinxReduceDataStorage());
95  SphinxResultDataAccumulator sphinxResultDataAccumulator(sphinxDataStorage);
96 
97  sphinxResultDataAccumulator.accumulate(sphinxResultData1);
98  sphinxResultDataAccumulator.accumulate(sphinxResultData2);
99 
100  //check info
101  ASSERT_EQ(sphinxResultDataAccumulator.getAllSphinxRequestInfo().size(), 1U);
102 
103  EXPECT_TRUE(isEqualRequestInfoStatParams(sphinxResultDataAccumulator.getAllSphinxRequestInfo()[0],
104  sphinxRequestInfo));
105 
106  sphinxResultDataAccumulator.getSphinxDataStorage()->reset();
107  while(sphinxResultDataAccumulator.getSphinxDataStorage()->hasNext()){
108  sphinxResultDataAccumulator.getSphinxDataStorage()->getNext(key, weight);
109  ASSERT_TRUE(expectStorage.find(key + weight) != expectStorage.end());
110  storageElemNumber++;
111  }
112  ASSERT_EQ(storageElemNumber, 3);
113 }
114 
115