hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxReduceDataStorageTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxDataStorageIteratorTest.cpp
3  *
4  * Created on: May 1, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
10 #include "SphinxResultData.hpp"
11 #include <vector>
12 
13 using namespace HCE::sphinx;
14 using namespace HCE::sphinx::reduce_task;
15 using namespace std;
16 
17 TEST(SphinxReduceDataStorage, IterableIfMustBeEmptyAfterInit)
18 {
19  SphinxReduceDataStorage sphinxReduceDataStorage;
20 
21  sphinxReduceDataStorage.reset();
22  ASSERT_TRUE(sphinxReduceDataStorage.hasNext() == false);
23 }
24 
25 
26 
27 class SphinxReduceDataStorageTest: public ::testing::Test{
28  protected:
29  virtual void SetUp(){
30  SphinxMatchInfo sphinxMatchInfo1;
31  sphinxMatchInfo1.setDocId(14);
32  sphinxMatchInfo1.setWeightFromDecString("12345");
33 
34  SphinxMatchInfo sphinxMatchInfo2;
35  sphinxMatchInfo2.setDocId(7);
36  sphinxMatchInfo2.setWeightFromDecString("256789");
37 
38  SphinxMatchInfo sphinxMatchInfo3;
39  sphinxMatchInfo3.setDocId(21);
40  sphinxMatchInfo3.setWeightFromDecString("1122334");
41 
42  resources.push_back(sphinxMatchInfo1);
43  resources.push_back(sphinxMatchInfo2);
44  resources.push_back(sphinxMatchInfo3);
45 
46  expectIdsWeights.push_back(make_pair(to_string(14LLU), toHexString(12345LLU)));
47  expectIdsWeights.push_back(make_pair(to_string(7LLU), toHexString(256789LLU)));
48  expectIdsWeights.push_back(make_pair(to_string(21LLU), toHexString(1122334LLU)));
49  }
50 
51  bool isFindExpectData(string &expectDocId, string &expectWeight){
52  for(size_t index = 0; index < expectIdsWeights.size(); ++index){
53  if (expectDocId == expectIdsWeights[index].first &&
54  expectWeight == expectIdsWeights[index].second){
55  return true;
56  }
57  }
58  return false;
59  }
60 
61  vector<pair<string, string> > expectIdsWeights;
62  vector<SphinxMatchInfo> resources;
63  string expectDocId;
64  string expectWeight;
65 };
66 
67 
69 {
70  SphinxReduceDataStorage sphinxReduceDataStorage;
71  int index = 0;
72 
73  sphinxReduceDataStorage.addData(resources[index]);
74 
75  sphinxReduceDataStorage.reset();
76  ASSERT_TRUE(sphinxReduceDataStorage.hasNext());
77  sphinxReduceDataStorage.getNext(expectDocId, expectWeight);
78  EXPECT_EQ(expectDocId, expectIdsWeights[index].first);
79  EXPECT_EQ(expectWeight, expectIdsWeights[index].second);
80 }
81 
82 
83 TEST_F(SphinxReduceDataStorageTest, creationComplexKeyForInputData)
84 {
85  SphinxReduceDataStorage sphinxReduceDataStorage;
86  int index = 0;
88 
89  sphinxReduceDataStorage.addData(resources[index]);
90 
91  string expectComplexKey = expectIdsWeights[index].first + expectIdsWeights[index].second;
92 
93  storageDataIter = sphinxReduceDataStorage.getData(expectComplexKey);
94 
95  ASSERT_TRUE(storageDataIter.first != storageDataIter.second);
96  EXPECT_EQ(storageDataIter.first->second.getDocId(), resources[index].getDocId());
97  EXPECT_EQ(storageDataIter.first->second.getWeight(), resources[index].getWeight());
98 }
99 
100 
102 {
103  SphinxReduceDataStorage sphinxReduceDataStorage;
104 
105  for (size_t index = 0; index < resources.size(); ++index){
106  sphinxReduceDataStorage.addData(resources[index]);
107  }
108 
109  unsigned int docsNumber = 0;
110  sphinxReduceDataStorage.reset();
111  while(sphinxReduceDataStorage.hasNext()){
112  sphinxReduceDataStorage.getNext(expectDocId, expectWeight);
113  EXPECT_TRUE(isFindExpectData(expectDocId, expectWeight));
114  ++docsNumber;
115  }
116  ASSERT_EQ(docsNumber, expectIdsWeights.size());
117 }
118 
119 
120 TEST_F(SphinxReduceDataStorageTest, orderDataWithEqualComplexKey)
121 {
122  SphinxReduceDataStorage sphinxReduceDataStorage;
124 
125  int doubleIndex = 1;
126  SphinxMatchInfo sphinxMatchInfo4;
127  sphinxMatchInfo4.setDocId(7);
128  sphinxMatchInfo4.setWeightFromDecString("256789");
129  AttrInfo attrInfo1 = AttrInfo("first", "value");
130  sphinxMatchInfo4.addAttrInfo(attrInfo1);
131 
132  resources.push_back(sphinxMatchInfo4);
133 
134  for (size_t index = 0; index < resources.size(); ++index){
135  sphinxReduceDataStorage.addData(resources[index]);
136  }
137 
138  string expectComplexKey = expectIdsWeights[doubleIndex].first + expectIdsWeights[doubleIndex].second;
139  storageDataIter = sphinxReduceDataStorage.getData(expectComplexKey);
140 
141  ASSERT_EQ(storageDataIter.first->second.getAttributes().size(), 0U);
142  storageDataIter.first++;
143  ASSERT_EQ(storageDataIter.first->second.getAttributes().size(), 1U);
144  storageDataIter.first++;
145  ASSERT_TRUE(storageDataIter.first == storageDataIter.second);
146 }