hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxTaskReducersManagerIntegrationTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxTaskReducersManagerIntegrationTest.cpp
3  *
4  * Created on: May 21, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
14 
15 using namespace HCE::sphinx::reduce_task;
16 using namespace HCE::sphinx;
17 using namespace HCE::reduce;
18 using namespace Poco;
19 
20 
21 class SphinxTaskReducersManagerIntegrationTest: public ::testing::Test{
22  protected:
23  virtual void SetUp(){
24  sphinxTaskReducersStorage.assign(new SphinxTaskReducersStorage());
25  sphinxTaskReducerFactory.assign(new SphinxTaskReducerFactory());
26  sphinxResultJSONConvertor.assign(new SphinxResultJSONConvertor());
27 
28  WordInfo word1 = WordInfo("word1", 10, 3);
29  WordInfo word2 = WordInfo("word2", 1, 1);
30 
31  matchInfo1 = buildSimpleMatchInfo(7LLU, 111LLU);
32  matchInfo2 = buildSimpleMatchInfo(9LLU, 222LLU);
33  matchInfo3 = buildSimpleMatchInfo(15LLU, 674387LLU);
34  matchInfo4 = buildSimpleMatchInfo(9LLU, 674387LLU);
35 
36  AttrInfo attrInfo1 = AttrInfo("first", "value");
37 
38  matchInfo1.addAttrInfo(attrInfo1);
39  matchInfo2.addAttrInfo(attrInfo1);
40  matchInfo3.addAttrInfo(attrInfo1);
41  matchInfo4.addAttrInfo(attrInfo1);
42 
43  sphinxRequestInfo1.setNodeName("nodeName1");
44  sphinxRequestInfo1.setMaxResultsNumber(5);
45  sphinxRequestInfo1.setQuery(query1);
46  sphinxRequestInfo1.setTotal(totalRes1);
47  sphinxRequestInfo1.setTotalFound(totalFound1);
48  sphinxRequestInfo1.setTimeMsec(time1);
49  sphinxRequestInfo1.addWordInfo(word1);
50  sphinxRequestInfo1.addWordInfo(word2);
51 
52  sphinxRequestInfo2.setNodeName("nodeName2");
53  sphinxRequestInfo2.setMaxResultsNumber(5);
54  sphinxRequestInfo2.addWordInfo(word1);
55  sphinxRequestInfo2.addWordInfo(word2);
56 
57  sphinxResultData1.addMatchInfo(matchInfo1);
58  sphinxResultData1.addMatchInfo(matchInfo2);
59  sphinxResultData1.addRequestInfo(sphinxRequestInfo1);
60 
61  sphinxResultData2.addMatchInfo(matchInfo3);
62  sphinxResultData2.addMatchInfo(matchInfo4);
63  sphinxResultData2.addRequestInfo(sphinxRequestInfo2);
64  }
65 
66  virtual void TearDown(){
67  sphinxTaskReducersStorage.assign(new SphinxTaskReducersStorage());
68  sphinxTaskReducerFactory.assign(new SphinxTaskReducerFactory());
69  sphinxResultJSONConvertor.assign(new SphinxResultJSONConvertor());
70  }
71 
73  expected.clear();
74  expected.addMatchInfo(matchInfo3);
75  expected.addMatchInfo(matchInfo1);
76  expected.addMatchInfo(matchInfo4);
77  //expected.addMatchInfo(matchInfo3);
78  expected.addRequestInfo(sphinxRequestInfo1);
79  expected.addRequestInfo(sphinxRequestInfo2);
80  }
81 
82  SharedPtr<SphinxTaskReducersStorage>sphinxTaskReducersStorage;
83  SharedPtr<SphinxTaskReducerFactory>sphinxTaskReducerFactory;
84  SharedPtr<SphinxResultJSONConvertor>sphinxResultJSONConvertor;
85 
86  static string query1;
87  static int totalRes1;
88  static int totalFound1;
89  static int time1;
90 
99 };
104 
105 
106 TEST_F(SphinxTaskReducersManagerIntegrationTest, checkExistenceASphinxReducer)
107 {
108  unsigned long long taskId = 2442352714LLU;
109  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
110  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
111 
112  sphinxTaskReducersManager.createReducer(taskId);
113 
114  ASSERT_TRUE(sphinxTaskReducersManager.isReducerExist(taskId) == true);
115 }
116 
117 
118 TEST_F(SphinxTaskReducersManagerIntegrationTest, reduceEmptySphinxResultResponses)
119 {
120  SphinxResultData emptySphinxResult;
121  string json = buildOutputJSONFromSphinxResultData(emptySphinxResult);
122  string json_input = buildInputJSONFromSphinxResultData(emptySphinxResult);
123  int taskId = 2442352714LLU;
124 
125  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
126  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
127 
128  sphinxTaskReducersManager.createReducer(taskId);
129  sphinxTaskReducersManager.addDataInReducer(taskId, json_input);
130  string reducedJSON = sphinxTaskReducersManager.runReduceTaskForTaskId(taskId);
131 
132  ASSERT_EQ(json, reducedJSON);
133 }
134 
135 
136 TEST_F(SphinxTaskReducersManagerIntegrationTest, throwExceptionWhileAddDataWithInvalidTaskId)
137 {
138  SphinxResultData emptySphinxResult;
139  string validJSON = buildInputJSONFromSphinxResultData(emptySphinxResult);
140  int invalidTaskId = 1;
141 
142  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
143  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
144 
145  ASSERT_THROW(sphinxTaskReducersManager.addDataInReducer(invalidTaskId, validJSON),
147 }
148 
149 
150 TEST_F(SphinxTaskReducersManagerIntegrationTest, throwExceptionWhileParseWrongJSONFormatString)
151 {
152  string invalidJSON = "data";
153  int taskId = 1;
154 
155  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
156  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
157 
158  sphinxTaskReducersManager.createReducer(taskId);
159 
160  ASSERT_THROW(sphinxTaskReducersManager.addDataInReducer(taskId, invalidJSON),
162 }
163 
164 
166 {
167  string json = buildOutputJSONFromSphinxResultData(sphinxResultData1);
168  string json_input = buildInputJSONFromSphinxResultData(sphinxResultData1);
169  int taskId = 7;
170 
171  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
172  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
173 
174  sphinxTaskReducersManager.createReducer(taskId);
175  sphinxTaskReducersManager.addDataInReducer(taskId, json_input);
176  string reducedJSON = sphinxTaskReducersManager.runReduceTaskForTaskId(taskId);
177 
178  ASSERT_EQ(json, reducedJSON);
179 }
180 
181 
183 {
184  SphinxResultData reducedSphinxResult;
185  buildExpectedSphinxResult(reducedSphinxResult);
186 
187  string expectedJSON = buildOutputJSONFromSphinxResultData(reducedSphinxResult);
188  string json1 = buildInputJSONFromSphinxResultData(sphinxResultData1);
189  string json2 = buildInputJSONFromSphinxResultData(sphinxResultData2);
190  int taskId = 7;
191 
192  SphinxTaskReducersManager sphinxTaskReducersManager(sphinxTaskReducersStorage,
193  sphinxTaskReducerFactory, sphinxResultJSONConvertor);
194 
195  sphinxTaskReducersManager.createReducer(taskId);
196  sphinxTaskReducersManager.addDataInReducer(taskId, json1);
197  sphinxTaskReducersManager.addDataInReducer(taskId, json2);
198 
199  string reducedJSON = sphinxTaskReducersManager.runReduceTaskForTaskId(taskId);
200 
201  ASSERT_EQ(expectedJSON, reducedJSON);
202 }
203