7 #include <gmock/gmock.h>
16 using namespace HCE::sphinx::reduce_task;
17 using namespace HCE::reduce::core;
18 using namespace HCE::reduce;
21 using ::testing::Return;
22 using ::testing::ReturnRef;
23 using ::testing::ReturnPointee;
24 using ::testing::Throw;
38 sphinxTaskReducersStorage.assign(NULL);
39 sphinxTaskReducerFactory.assign(NULL);
40 sphinxResultJSONConvertor.assign(NULL);
41 sphinxTaskReducer.assign(NULL);
53 unsigned long long existTaskId = 2;
56 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
58 EXPECT_CALL(*sphinxTaskReducersStorage.get(), findByKey(_))
59 .WillOnce(ReturnPointee(&sphinxTaskReducer));
60 ASSERT_THAT(sphinxTaskReducersManager.
isReducerExist(existTaskId),
true);
67 unsigned long long noExistTaskId = 7;
71 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
73 EXPECT_CALL(*sphinxTaskReducersStorage.get(), findByKey(_))
74 .WillOnce(Throw(notFoundSphinxTaskReducerException));
75 ASSERT_THAT(sphinxTaskReducersManager.
isReducerExist(noExistTaskId),
false);
81 unsigned long long newTaskId = 3;
84 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
86 EXPECT_CALL(*sphinxTaskReducerFactory.get(), create())
87 .WillOnce(ReturnPointee(&sphinxTaskReducer));
88 EXPECT_CALL(*sphinxTaskReducersStorage.get(), addWithKey(Eq(newTaskId), _))
97 unsigned long long existTaskId = 7;
98 string json =
"fake JSON";
99 SharedPtr<SphinxResultData> buildFromJSONSphinxResult;
102 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
104 EXPECT_CALL(*sphinxResultJSONConvertor.get(), convertToSphinxResultDataFrom(Eq(json)))
105 .WillOnce(ReturnPointee(&buildFromJSONSphinxResult));
106 EXPECT_CALL(*sphinxTaskReducersStorage.get(), findByKey(Eq(existTaskId)))
107 .WillOnce(ReturnPointee(&sphinxTaskReducer));
108 EXPECT_CALL(*sphinxTaskReducer.get(), addData(_))
117 unsigned long long existTaskId = 7;
118 string badStructuredJSON =
"bad structure";
122 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
124 EXPECT_CALL(*sphinxResultJSONConvertor.get(), convertToSphinxResultDataFrom(_))
125 .WillOnce(Throw(wrongJSONStructureException));
134 unsigned long long reducedTaskId = 4;
136 SharedPtr<SphinxResultData> reducedSphinxResult;
140 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
142 EXPECT_CALL(*sphinxTaskReducersStorage.get(), findByKey(Eq(reducedTaskId)))
143 .WillOnce(ReturnPointee(&sphinxTaskReducer));
144 EXPECT_CALL(*sphinxTaskReducerFactory.get(), getScheduleStrategy())
145 .WillOnce(ReturnRef(scheduleStrategy));
146 EXPECT_CALL(*sphinxTaskReducer.get(), reduce(_))
148 EXPECT_CALL(*sphinxTaskReducer.get(), getResult())
149 .WillOnce(ReturnPointee(&reducedSphinxResult));
150 EXPECT_CALL(*sphinxTaskReducerFactory.get(), getSphinxResultTrancater())
151 .WillOnce(ReturnRef(SphinxResultTrancater));
152 EXPECT_CALL(SphinxResultTrancater, trancate(Eq(reducedSphinxResult)))
153 .WillOnce(ReturnPointee(&reducedSphinxResult));
154 EXPECT_CALL(*sphinxResultJSONConvertor.get(), convertToJSONFrom(Eq(reducedSphinxResult)))
163 unsigned long long taskId = 3;
166 sphinxTaskReducerFactory, sphinxResultJSONConvertor);
168 EXPECT_CALL(*sphinxTaskReducersStorage.get(), deleteByKey(Eq(taskId)))