17 #ifndef __TESTS_ALLOCATOR_HPP__ 18 #define __TESTS_ALLOCATOR_HPP__ 20 #include <gmock/gmock.h> 32 using ::testing::DoDefault;
33 using ::testing::Invoke;
34 using ::testing::Return;
44 Quota
createQuota(
const std::string& guarantees,
const std::string& limits);
63 allocator->real->initialize(
arg0,
arg1, arg2);
69 allocator->real->recover(
arg0,
arg1);
75 allocator->real->addFramework(
arg0,
arg1, arg2, arg3, std::move(arg4));
81 allocator->real->removeFramework(
arg0);
87 allocator->real->activateFramework(
arg0);
93 allocator->real->deactivateFramework(
arg0);
99 allocator->real->updateFramework(
arg0,
arg1, std::move(arg2));
105 allocator->real->addSlave(
arg0,
arg1, arg2, arg3, arg4, arg5);
111 allocator->real->removeSlave(
arg0);
117 allocator->real->updateSlave(
arg0,
arg1, arg2, arg3);
123 allocator->real->addResourceProvider(
arg0,
arg1, arg2);
129 allocator->real->activateSlave(
arg0);
135 allocator->real->deactivateSlave(
arg0);
141 allocator->real->updateWhitelist(
arg0);
147 allocator->real->requestResources(
arg0,
arg1);
153 allocator->real->updateAllocation(
arg0,
arg1, arg2, arg3);
159 return allocator->real->updateAvailable(
arg0,
arg1);
165 return allocator->real->updateUnavailability(
arg0,
arg1);
171 return allocator->real->updateInverseOffer(
arg0,
arg1, arg2, arg3, arg4);
177 return allocator->real->getInverseOfferStatuses();
181 ACTION_P(InvokeTransitionOfferedToAllocated, allocator)
183 allocator->real->transitionOfferedToAllocated(
arg0,
arg1);
189 allocator->real->recoverResources(
arg0,
arg1, arg2, arg3, arg4);
193 ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, timeout)
196 filters.set_refuse_seconds(timeout);
198 allocator->real->recoverResources(
arg0,
arg1, arg2, filters,
false);
204 allocator->real->suppressOffers(
arg0,
arg1);
210 allocator->real->reviveOffers(
arg0,
arg1);
216 allocator->real->updateQuota(
arg0,
arg1);
222 allocator->real->updateWeights(
arg0);
228 allocator->real->pause();
234 allocator->real->resume();
238 template <
typename T = master::allocator::HierarchicalDRFAllocator>
245 return CHECK_NOTNULL(instance.
get());
248 template <
typename T = master::allocator::HierarchicalDRFAllocator>
266 .WillByDefault(InvokeInitialize(
this));
268 .WillRepeatedly(DoDefault());
271 .WillByDefault(InvokeRecover(
this));
272 EXPECT_CALL(*
this,
recover(_, _))
273 .WillRepeatedly(DoDefault());
275 ON_CALL(*
this, addFramework_(_, _, _, _, _))
276 .WillByDefault(InvokeAddFramework(
this));
277 EXPECT_CALL(*
this, addFramework_(_, _, _, _, _))
278 .WillRepeatedly(DoDefault());
281 .WillByDefault(InvokeRemoveFramework(
this));
283 .WillRepeatedly(DoDefault());
286 .WillByDefault(InvokeActivateFramework(
this));
288 .WillRepeatedly(DoDefault());
291 .WillByDefault(InvokeDeactivateFramework(
this));
293 .WillRepeatedly(DoDefault());
295 ON_CALL(*
this, updateFramework_(_, _, _))
296 .WillByDefault(InvokeUpdateFramework(
this));
297 EXPECT_CALL(*
this, updateFramework_( _, _, _))
298 .WillRepeatedly(DoDefault());
300 ON_CALL(*
this,
addSlave(_, _, _, _, _, _))
301 .WillByDefault(InvokeAddSlave(
this));
302 EXPECT_CALL(*
this,
addSlave(_, _, _, _, _, _))
303 .WillRepeatedly(DoDefault());
306 .WillByDefault(InvokeRemoveSlave(
this));
308 .WillRepeatedly(DoDefault());
311 .WillByDefault(InvokeUpdateSlave(
this));
313 .WillRepeatedly(DoDefault());
316 .WillByDefault(InvokeAddResourceProvider(
this));
318 .WillRepeatedly(DoDefault());
321 .WillByDefault(InvokeActivateSlave(
this));
323 .WillRepeatedly(DoDefault());
326 .WillByDefault(InvokeDeactivateSlave(
this));
328 .WillRepeatedly(DoDefault());
331 .WillByDefault(InvokeUpdateWhitelist(
this));
333 .WillRepeatedly(DoDefault());
336 .WillByDefault(InvokeRequestResources(
this));
338 .WillRepeatedly(DoDefault());
341 .WillByDefault(InvokeUpdateAllocation(
this));
343 .WillRepeatedly(DoDefault());
346 .WillByDefault(InvokeUpdateAvailable(
this));
348 .WillRepeatedly(DoDefault());
351 .WillByDefault(InvokeUpdateUnavailability(
this));
353 .WillRepeatedly(DoDefault());
356 .WillByDefault(InvokeUpdateInverseOffer(
this));
358 .WillRepeatedly(DoDefault());
361 .WillByDefault(InvokeGetInverseOfferStatuses(
this));
363 .WillRepeatedly(DoDefault());
366 .WillByDefault(InvokeTransitionOfferedToAllocated(
this));
368 .WillRepeatedly(DoDefault());
371 .WillByDefault(InvokeRecoverResources(
this));
373 .WillRepeatedly(DoDefault());
376 .WillByDefault(InvokeSuppressOffers(
this));
378 .WillRepeatedly(DoDefault());
381 .WillByDefault(InvokeReviveOffers(
this));
383 .WillRepeatedly(DoDefault());
386 .WillByDefault(InvokeUpdateQuota(
this));
388 .WillRepeatedly(DoDefault());
391 .WillByDefault(InvokeUpdateWeights(
this));
393 .WillRepeatedly(DoDefault());
395 ON_CALL(*
this,
pause())
396 .WillByDefault(InvokePause(
this));
397 EXPECT_CALL(*
this,
pause())
398 .WillRepeatedly(DoDefault());
401 .WillByDefault(InvokeResume(
this));
402 EXPECT_CALL(*
this,
resume())
403 .WillRepeatedly(DoDefault());
410 const lambda::function<
411 void(
const FrameworkID&,
413 const lambda::function<
414 void(
const FrameworkID&,
418 const int expectedAgentCount,
426 const FrameworkInfo&,
432 const FrameworkID& frameworkId,
433 const FrameworkInfo& frameworkInfo,
438 addFramework_(frameworkId, frameworkInfo, used, active, options);
442 const FrameworkID&));
445 const FrameworkID&));
448 const FrameworkID&));
455 const FrameworkInfo&,
459 const FrameworkID& frameworkId,
460 const FrameworkInfo& frameworkInfo,
463 updateFramework_(frameworkId, frameworkInfo, options);
469 const std::vector<SlaveInfo::Capability>&,
481 const Option<std::vector<SlaveInfo::Capability>>&));
499 const std::vector<Request>&));
505 const std::vector<ResourceConversion>&));
509 const std::vector<Offer::Operation>&));
525 mesos::allocator::InverseOfferStatus>>>());
540 const std::set<std::string>&));
544 const std::set<std::string>&));
551 const std::vector<WeightInfo>&));
564 #endif // __TESTS_ALLOCATOR_HPP__ MOCK_METHOD6(addSlave, void(const SlaveID &, const SlaveInfo &, const std::vector< SlaveInfo::Capability > &, const Option< Unavailability > &, const Resources &, const hashmap< FrameworkID, Resources > &))
virtual void addResourceProvider(const SlaveID &slave, const Resources &total, const hashmap< FrameworkID, Resources > &used)=0
Add resources from a local resource provider to an agent.
Per-framework allocator-specific options that are not part of FrameworkInfo.
Definition: allocator.hpp:147
constexpr const char * arg1
Definition: shell.hpp:43
Definition: option.hpp:29
T & get()&
Definition: try.hpp:80
virtual void pause()=0
Idempotent helper to pause allocations.
virtual void activateSlave(const SlaveID &slaveId)=0
Activates an agent.
virtual void updateAllocation(const FrameworkID &frameworkId, const SlaveID &slaveId, const Resources &offeredResources, const std::vector< ResourceConversion > &conversions)=0
Updates allocation by applying offer operations.
TestAllocator()
Definition: allocator.hpp:254
Definition: resources.hpp:83
virtual void reviveOffers(const FrameworkID &frameworkId, const std::set< std::string > &roles)=0
Revives offers to this framework for the specified roles.
Pass in configuration to the allocator.
Definition: allocator.hpp:53
mesos::allocator::Allocator * createAllocator()
Definition: allocator.hpp:239
virtual process::Future< hashmap< SlaveID, hashmap< FrameworkID, mesos::allocator::InverseOfferStatus > > > getInverseOfferStatuses()=0
Retrieves the status of all inverse offers maintained by the allocator.
virtual void deactivateFramework(const FrameworkID &frameworkId)=0
Deactivates a framework in the Mesos cluster.
WeightInfo createWeightInfo(const std::string &role, double weight)
constexpr const char * arg0
Definition: shell.hpp:42
Definition: hashmap.hpp:38
virtual void initialize(const Options &options, const lambda::function< void(const FrameworkID &, const hashmap< std::string, hashmap< SlaveID, Resources >> &)> &offerCallback, const lambda::function< void(const FrameworkID &, const hashmap< SlaveID, UnavailableResources > &)> &inverseOfferCallback)=0
Initializes the allocator when the master starts up.
virtual void updateWeights(const std::vector< WeightInfo > &weightInfos)=0
Updates the weight associated with one or more roles.
virtual void updateQuota(const std::string &role, const Quota "a)=0
Informs the allocator to update quota for the given role.
#define CHECK_SOME(expression)
Definition: check.hpp:50
virtual void removeSlave(const SlaveID &slaveId)=0
Removes an agent from the Mesos cluster.
Try< Bytes > used(const std::string &path="/")
Definition: fs.hpp:43
virtual void activateFramework(const FrameworkID &frameworkId)=0
Activates a framework in the Mesos cluster.
Result< std::vector< Filter< Classifier > > > filters(const std::string &_link, const Handle &parent)
Definition: internal.hpp:769
Definition: allocator.hpp:249
virtual void resume()=0
Idempotent helper to resume allocations.
MOCK_METHOD4(updateSlave, void(const SlaveID &, const SlaveInfo &, const Option< Resources > &, const Option< std::vector< SlaveInfo::Capability >> &))
virtual void recoverResources(const FrameworkID &frameworkId, const SlaveID &slaveId, const Resources &resources, const Option< Filters > &filters, bool isAllocated)=0
Recovers resources.
virtual void removeFramework(const FrameworkID &frameworkId)=0
Removes a framework from the Mesos cluster.
virtual void updateUnavailability(const SlaveID &slaveId, const Option< Unavailability > &unavailability)=0
Updates unavailability for an agent.
virtual void addSlave(const SlaveID &slaveId, const SlaveInfo &slaveInfo, const std::vector< SlaveInfo::Capability > &capabilities, const Option< Unavailability > &unavailability, const Resources &total, const hashmap< FrameworkID, Resources > &used)=0
Adds or re-adds an agent to the Mesos cluster.
Basic model of an allocator: resources are allocated to a framework in the form of offers...
Definition: allocator.hpp:172
MOCK_METHOD5(addFramework_, void(const FrameworkID &, const FrameworkInfo &, const hashmap< SlaveID, Resources > &, bool active,::mesos::allocator::FrameworkOptions &))
virtual void deactivateSlave(const SlaveID &slaveId)=0
Deactivates an agent.
void updateFramework(const FrameworkID &frameworkId, const FrameworkInfo &frameworkInfo,::mesos::allocator::FrameworkOptions &&options) override
Definition: allocator.hpp:458
void addFramework(const FrameworkID &frameworkId, const FrameworkInfo &frameworkInfo, const hashmap< SlaveID, Resources > &used, bool active,::mesos::allocator::FrameworkOptions &&options) override
Definition: allocator.hpp:431
Definition: attributes.hpp:24
virtual void transitionOfferedToAllocated(const SlaveID &slaveId, const Resources &resources)=0
This method should be invoked when the offered resources has become actually allocated.
~TestAllocator() override
Definition: allocator.hpp:406
virtual void updateWhitelist(const Option< hashset< std::string >> &whitelist)=0
Updates the list of trusted agents.
process::Owned< mesos::allocator::Allocator > real
Definition: allocator.hpp:557
virtual void requestResources(const FrameworkID &frameworkId, const std::vector< Request > &requests)=0
Requests resources for a framework.
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, timeout)
Definition: allocator.hpp:193
virtual void recover(const int expectedAgentCount, const hashmap< std::string, Quota > "as)=0
Informs the allocator of the recovered state from the master.
ACTION_P(InvokeInitialize, allocator)
Definition: allocator.hpp:61
MOCK_METHOD2(recover, void(const int expectedAgentCount, const hashmap< std::string, Quota > &))
virtual void suppressOffers(const FrameworkID &frameworkId, const std::set< std::string > &roles)=0
Suppresses offers.
MOCK_METHOD0(getInverseOfferStatuses, process::Future< hashmap< SlaveID, hashmap< FrameworkID, mesos::allocator::InverseOfferStatus >>>())
virtual process::Future< Nothing > updateAvailable(const SlaveID &slaveId, const std::vector< Offer::Operation > &operations)=0
Updates available resources on an agent based on a sequence of offer operations.
Quota createQuota(const std::string &guarantees, const std::string &limits)
MOCK_METHOD1(removeFramework, void(const FrameworkID &))
virtual void updateInverseOffer(const SlaveID &slaveId, const FrameworkID &frameworkId, const Option< UnavailableResources > &unavailableResources, const Option< InverseOfferStatus > &status, const Option< Filters > &filters=None())=0
Updates inverse offer.
virtual void updateSlave(const SlaveID &slave, const SlaveInfo &slaveInfo, const Option< Resources > &total=None(), const Option< std::vector< SlaveInfo::Capability >> &capabilities=None())=0
Updates an agent.
MOCK_METHOD3(initialize, void(const Options &options, const lambda::function< void(const FrameworkID &, const hashmap< std::string, hashmap< SlaveID, Resources >> &)> &, const lambda::function< void(const FrameworkID &, const hashmap< SlaveID, UnavailableResources > &)> &))