hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxReducerIntergationTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxReducerTest.cpp
3  *
4  * Created on: May 3, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
9 #include "SphinxTaskReducer.hpp"
10 #include "SphinxResultBuilder.hpp"
13 
14 using namespace HCE::sphinx;
15 using namespace HCE::sphinx::reduce_task;
16 using namespace HCE::reduce::core;
17 using namespace Poco;
18 using namespace std;
19 
20 class SphinxReducerIntergationTest: public ::testing::Test{
21  protected:
22  virtual void SetUp(){
23  sphinxResultBuilder.assign(new SphinxResultBuilder());
24  reduceJobBuilder.assign(new SphinxReduceJobBuilder());
25  sphinxResultDataAccumulatorFactory.assign(new
27 
28  sphinxReducer.assign(new SphinxTaskReducer(*sphinxResultBuilder.get(),
29  *reduceJobBuilder.get(),
30  *sphinxResultDataAccumulatorFactory.get()));
31 
32  WordInfo word1 = WordInfo("word1", 10, 3);
33  WordInfo word2 = WordInfo("word2", 1, 1);
34 
35  matchInfo1 = buildSimpleMatchInfo(7LLU, 111LLU);
36  matchInfo2 = buildSimpleMatchInfo(9LLU, 222LLU);
37  matchInfo3 = buildSimpleMatchInfo(15LLU, 674387LLU);
38  matchInfo4 = buildSimpleMatchInfo(9LLU, 674387LLU);
39 
40  AttrInfo attrInfo1 = AttrInfo("first", "value");
41 
42  matchInfo1.addAttrInfo(attrInfo1);
43  matchInfo2.addAttrInfo(attrInfo1);
44  matchInfo3.addAttrInfo(attrInfo1);
45  matchInfo4.addAttrInfo(attrInfo1);
46 
47  sphinxRequestInfo1.setNodeName("nodeName1");
48  sphinxRequestInfo1.setQuery(query1);
49  sphinxRequestInfo1.setTotal(totalRes1);
50  sphinxRequestInfo1.setTotalFound(totalFound1);
51  sphinxRequestInfo1.setTimeMsec(time1);
52  sphinxRequestInfo1.addWordInfo(word1);
53  sphinxRequestInfo1.addWordInfo(word2);
54 
55  sphinxRequestInfo2.setNodeName("nodeName2");
56  sphinxRequestInfo2.addWordInfo(word1);
57  sphinxRequestInfo2.addWordInfo(word2);
58 
59  sphinxResultData1.addMatchInfo(matchInfo1);
60  sphinxResultData1.addMatchInfo(matchInfo2);
61  sphinxResultData1.addRequestInfo(sphinxRequestInfo1);
62 
63  sphinxResultData2.addMatchInfo(matchInfo3);
64  sphinxResultData2.addMatchInfo(matchInfo4);
65  sphinxResultData2.addRequestInfo(sphinxRequestInfo2);
66  }
67 
69  expected.clear();
70  expected.addMatchInfo(matchInfo1);
71  expected.addMatchInfo(matchInfo4);
72  expected.addMatchInfo(matchInfo3);
73  expected.addRequestInfo(sphinxRequestInfo1);
74  expected.addRequestInfo(sphinxRequestInfo2);
75  }
76 
77  SharedPtr<SphinxResultBuilder> sphinxResultBuilder;
78  SharedPtr<SphinxReduceJobBuilder>reduceJobBuilder;
79  SharedPtr<SphinxResultDataAccumulatorFactory>sphinxResultDataAccumulatorFactory;
80  SharedPtr<SphinxTaskReducer>sphinxReducer;
82 
83  string query1;
84  int totalRes1;
86  int time1;
87 
96 };
97 
99 {
100  SharedPtr<SphinxResultData> reducedSphinxResult = sphinxReducer->getResult();
101  SphinxResultData emptySphinxResult;
102 
103  ASSERT_TRUE(isEqualSphinxResultData(*reducedSphinxResult.get(), emptySphinxResult));
104 }
105 
106 
108 {
109  SphinxResultData emptyInputSphinxResult;
110  SphinxResultData emptySphinxResult;
111 
112  sphinxReducer->addData(emptyInputSphinxResult);
113  sphinxReducer->reduce(scheduleStrategy);
114  SharedPtr<SphinxResultData> reducedSphinxResult = sphinxReducer->getResult();
115 
116  ASSERT_TRUE(isEqualSphinxResultData(*reducedSphinxResult.get(), emptySphinxResult));
117 }
118 
119 
121 {
122  sphinxReducer->addData(sphinxResultData1);
123  sphinxReducer->reduce(scheduleStrategy);
124  SharedPtr<SphinxResultData> reducedSphinxResult = sphinxReducer->getResult();
125 
126  ASSERT_TRUE(isEqualSphinxResultData(*reducedSphinxResult.get(), sphinxResultData1));
127 }
128 
129 
131 {
132  ScheduleStrategySingle scheduleStrategy;
133  SphinxResultData expectedSphinxResult;
134  buildExpectedSphinxResultData(expectedSphinxResult);
135 
136  sphinxReducer->addData(sphinxResultData1);
137  sphinxReducer->addData(sphinxResultData2);
138  sphinxReducer->reduce(scheduleStrategy);
139  SharedPtr<SphinxResultData> reducedSphinxResult = sphinxReducer->getResult();
140 
141  ASSERT_TRUE(isEqualRequestInfo(*reducedSphinxResult.get(), expectedSphinxResult));
142  ASSERT_TRUE(isEqualUnSortMatchInfo(*reducedSphinxResult.get(), expectedSphinxResult));
143 }
144