hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxReducerTestMock.cpp
Go to the documentation of this file.
1 /*
2  * SphinxReducerTestMock.cpp
3  *
4  * Created on: May 7, 2013
5  * Author: igor
6  */
7 #include <gtest/gtest.h>
8 #include <string>
9 #include "SphinxTaskReducer.hpp"
10 #include <SphinxResultData.hpp>
12 #include <Poco/SharedPtr.h>
14 #include "SphinxResultBuilder.hpp"
17 #include "Mocks.hpp"
18 #include "CoreMocks.hpp"
19 
20 using namespace HCE::sphinx;
21 using namespace HCE::sphinx::reduce_task;
22 using namespace HCE::reduce::core;
23 using namespace Poco;
24 using namespace std;
25 
26 using ::testing::_;
27 using ::testing::InSequence;
28 using ::testing::SetArgReferee;
29 using ::testing::Return;
30 using ::testing::ReturnPointee;
31 using ::testing::ReturnRef;
32 using ::testing::Eq;
33 
34 
35 TEST(SphinxReducerTestMock, fillDataStorage)
36 {
37  SphinxResultBuilderMock sphinxResultBuilder;
38  SphinxResultDataAccumulatorFactoryMock sphinxResultDataAccumulatorFactory;
39  SharedPtr<SphinxResultDataAccumulatorMock>sphinxResultDataAccumulator(
41  SphinxReduceJobBuilderMock sphinxReduceJobBuilder;
42  ScheduleStrategyMock scheduleStrategy;
43 
44  SharedPtr<SphinxReduceDataStorage>sphinxReduceDataStorage(new SphinxReduceDataStorage());
45  SharedPtr<SphinxReduceResult>sphinxReduceResult(new SphinxReduceResult());
46  SharedPtr<ReduceJobMock> sphinxReduceJobMock(new ReduceJobMock());
47 
48  SharedPtr<SphinxResultData> sphinxResultAfterReducing;
49  vector<SphinxRequestInfo> requestInfo;
50 
51  InSequence s;
52  EXPECT_CALL(sphinxReduceJobBuilder, build())
53  .WillOnce(ReturnPointee(&sphinxReduceJobMock));
54 
55  EXPECT_CALL(*sphinxReduceJobMock.get(), getDataStorage())
56  .WillOnce(ReturnPointee(&sphinxReduceDataStorage));
57 
58  EXPECT_CALL(sphinxResultDataAccumulatorFactory, build(_))
59  .WillOnce(ReturnPointee(&sphinxResultDataAccumulator));
60 
61  EXPECT_CALL(*sphinxResultDataAccumulator.get(), accumulate(_))
62  .Times(2);
63  EXPECT_CALL(scheduleStrategy, executeJob(_))
64  .Times(1);
65  //getResult
66  EXPECT_CALL(*sphinxReduceJobMock.get(), getReduceResult())
67  .WillOnce(ReturnPointee(&sphinxReduceResult));
68  EXPECT_CALL(*sphinxResultDataAccumulator.get(), getSphinxDataStorage())
69  .WillOnce(ReturnPointee(&sphinxReduceDataStorage));
70  EXPECT_CALL(*sphinxResultDataAccumulator.get(), getAllSphinxRequestInfo())
71  .WillOnce(ReturnRef(requestInfo));
72  EXPECT_CALL(sphinxResultBuilder, build(_, _,_))
73  .WillOnce(ReturnPointee(&sphinxResultAfterReducing));
74 
75  SphinxTaskReducer sphinxReducer(sphinxResultBuilder, sphinxReduceJobBuilder,
76  sphinxResultDataAccumulatorFactory);
77 
78  SphinxResultData sphinxResultData1;
79  SphinxResultData sphinxResultData2;
80 
81  sphinxReducer.addData(sphinxResultData1);
82  sphinxReducer.addData(sphinxResultData2);
83  sphinxReducer.reduce(scheduleStrategy);
84  sphinxResultAfterReducing = sphinxReducer.getResult();
85 }