1 #include <gtest/gtest.h>
9 using namespace HCE::reduce_types;
10 using namespace HCE::sphinx::reduce_task;
14 using ::testing::Return;
15 using ::testing::NiceMock;
16 using ::testing::Throw;
17 using ::testing::ReturnPointee;
18 using ::testing::Matcher;
19 using ::testing::InSequence;
31 reducingPartsCountersStorageNice.assign(
new NiceMock<ReducingPartsCountersStorageMock>());
33 reducingHandler.assign(
new ReducingHandler(reducingPartsCountersStorage,
34 reduceAdditionsStorage,
35 taskReducersManagerFactory,
36 reducingOutputMessageBuilder,
41 string body =
"some body";
63 SharedPtr<TaskReducersManagerMock>taskReducersManagerN(
new NiceMock<TaskReducersManagerMock>());
67 EXPECT_CALL(*reducingPartsCountersStorage.get(), findBy(Eq(itemId)))
68 .WillRepeatedly(Return(
false));
70 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<HCE::types::MessageType>(_)))
71 .WillRepeatedly(Throw(notFoundByKeyException));
72 EXPECT_CALL(*taskReducersManagerFactory.get(), build(_))
73 .WillOnce(ReturnPointee(&taskReducersManagerN));
74 EXPECT_CALL(*reduceAdditionsStorage.get(), addWith(Matcher<HCE::types::MessageType>(_), _))
76 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<HCE::types::MessageType>(_)))
77 .WillRepeatedly(ReturnPointee(&taskReducersManagerN));
78 EXPECT_CALL(*reduceAdditionsStorage.get(), addWith(Matcher<unsigned long long>(_), _))
80 EXPECT_CALL(*reducingPartsCountersStorage.get(), addReducingPartsCounterWithKey(Eq(itemId)))
82 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<HCE::types::MessageType>(_)))
83 .WillRepeatedly(ReturnPointee(&taskReducersManagerN));
85 EXPECT_CALL(*reducingPartsCountersStorage.get(), incrementBy(Eq(itemId)))
87 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
88 .WillRepeatedly(ReturnPointee(&taskReducersManagerN));
90 reducingHandler->accumulateReducingData(itemId, reducingInputMessage);
98 EXPECT_CALL(*reducingPartsCountersStorage.get(), findBy(_))
99 .WillOnce(Return(
true));
101 EXPECT_CALL(*reducingPartsCountersStorage.get(), incrementBy(_))
104 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
105 .WillRepeatedly(ReturnPointee(&taskReducersManager));
107 EXPECT_CALL(*taskReducersManager.get(), addDataInReducer(_, _))
108 .WillOnce(Throw(wrongJSONStructureException));
110 EXPECT_CALL(*supportNotifier.get(), notifyWrongJSONStructure(_, _))
113 reducingHandler->accumulateReducingData(itemId, reducingInputMessage);
121 EXPECT_CALL(*reducingPartsCountersStorage.get(), findBy(_))
122 .WillOnce(Return(
false));
124 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<HCE::types::MessageType>(_)))
125 .WillOnce(Throw(notFoundByKeyException));
127 EXPECT_CALL(*taskReducersManagerFactory.get(), build(_))
128 .WillOnce(Throw(notFoundByKeyException));
130 EXPECT_CALL(*supportNotifier.get(), notifyNotFoundItemException(_))
133 reducingHandler->accumulateReducingData(itemId, reducingInputMessage);
142 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
143 .WillRepeatedly(ReturnPointee(&taskReducersManager));
144 EXPECT_CALL(*taskReducersManager.get(), getType())
145 .WillOnce(Return(msgType));
147 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
148 .WillRepeatedly(ReturnPointee(&taskReducersManager));
150 EXPECT_CALL(*taskReducersManager.get(), runReduceTaskForTaskId(Eq(itemId)))
151 .WillOnce(Return(reducingJSON));
152 EXPECT_CALL(*reducingOutputMessageBuilder.get(), build(_, _, Matcher<const string&>(Eq(reducingJSON))))
153 .WillOnce(ReturnPointee(&reducingOutputMessage));
155 reducingHandler->makeReducing(itemId);
164 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
165 .WillRepeatedly(ReturnPointee(&taskReducersManager));
167 EXPECT_CALL(*taskReducersManager.get(), getType())
168 .WillOnce(Return(msgType));
170 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
171 .WillRepeatedly(ReturnPointee(&taskReducersManager));
173 EXPECT_CALL(*taskReducersManager.get(), runReduceTaskForTaskId(Eq(itemId)))
174 .WillOnce(Throw(notFoundSphinxTaskReducerException));
175 EXPECT_CALL(*supportNotifier.get(), notifyNotFoundItemException(_))
177 EXPECT_CALL(*reducingOutputMessageBuilder.get(),
178 build(Matcher<const NotFoundByKeyException&>(_)))
179 .WillOnce(ReturnPointee(&reducingOutputMessage));
181 reducingHandler->makeReducing(itemId);
187 EXPECT_CALL(*reducingPartsCountersStorage.get(), deleteBy(Eq(itemId)))
189 EXPECT_CALL(*reduceAdditionsStorage.get(), findBy(Matcher<unsigned long long>(Eq(itemId))))
190 .WillRepeatedly(ReturnPointee(&taskReducersManager));
191 EXPECT_CALL(*taskReducersManager.get(), deleteReducerBy(Eq(itemId)))
193 EXPECT_CALL(*reduceAdditionsStorage.get(), deleteBy(Matcher<unsigned long long>(Eq(itemId))))
196 reducingHandler->deleteReducingTaskBy(itemId);
204 EXPECT_CALL(*reducingPartsCountersStorage.get(), deleteBy(Eq(itemId)))
205 .WillOnce(Throw(notFoundSphinxTaskReducerException));
206 EXPECT_CALL(*supportNotifier.get(), notifyNotFoundItemException(_))
209 reducingHandler->deleteReducingTaskBy(itemId);
215 EXPECT_CALL(*reducingPartsCountersStorage.get(), getAccumulateReducingParts(Eq(itemId)))
216 .WillOnce(Return(1));
218 reducingHandler->getAccumulateReducingPartsNumberBy(itemId);
226 EXPECT_CALL(*reducingPartsCountersStorage.get(), getAccumulateReducingParts(Eq(itemId)))
227 .WillOnce(Throw(notFoundSphinxTaskReducerException));
229 ASSERT_THROW(reducingHandler->getAccumulateReducingPartsNumberBy(itemId),