MCPcopy Create free account
hub / github.com/apache/mesos / TEST_F

Function TEST_F

src/tests/reservation_tests.cpp:139–231  ·  view source on GitHub ↗

This tests that a framework can send back a Reserve operation as a response to an offer, which updates the resources in the allocator and results in the reserved resources being reoffered to the framework. The framework then sends back an Unreserved offer operation to unreserve the reserved resources. Finally, We test that the framework receives the unreserved resources.

Source from the content-addressed store, hash-verified

137// operation to unreserve the reserved resources. Finally, We test
138// that the framework receives the unreserved resources.
139TEST_F(ReservationTest, ReserveThenUnreserve)
140{
141 FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
142 frameworkInfo.set_roles(0, "role");
143
144 master::Flags masterFlags = CreateMasterFlags();
145 masterFlags.allocation_interval = Milliseconds(5);
146 masterFlags.roles = frameworkInfo.roles(0);
147
148 Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
149 ASSERT_SOME(master);
150
151 slave::Flags slaveFlags = CreateSlaveFlags();
152 slaveFlags.resources = "cpus:1;mem:512";
153
154 Future<UpdateSlaveMessage> updateSlaveMessage =
155 FUTURE_PROTOBUF(UpdateSlaveMessage(), _, _);
156
157 Owned<MasterDetector> detector = master.get()->createDetector();
158 Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
159 ASSERT_SOME(slave);
160
161 AWAIT_READY(updateSlaveMessage);
162
163 MockScheduler sched;
164 MesosSchedulerDriver driver(
165 &sched, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL);
166
167 // We use the filter explicitly here so that the resources will not
168 // be filtered for 5 seconds (the default).
169 Filters filters;
170 filters.set_refuse_seconds(0);
171
172 Resources unreserved = Resources::parse("cpus:1;mem:512").get();
173 Resources dynamicallyReserved =
174 unreserved.pushReservation(createDynamicReservationInfo(
175 frameworkInfo.roles(0), frameworkInfo.principal()));
176
177 // We use this to capture offers from 'resourceOffers'.
178 Future<vector<Offer>> offers;
179
180 EXPECT_CALL(sched, registered(&driver, _, _));
181
182 // The expectation for the first offer.
183 EXPECT_CALL(sched, resourceOffers(&driver, _))
184 .WillOnce(FutureArg<1>(&offers));
185
186 driver.start();
187
188 // In the first offer, expect an offer with unreserved resources.
189 AWAIT_READY(offers);
190
191 ASSERT_EQ(1u, offers->size());
192 Offer offer = offers.get()[0];
193
194 EXPECT_TRUE(Resources(offer.resources()).contains(
195 allocatedResources(unreserved, frameworkInfo.roles(0))));
196

Callers

nothing calls this directly

Calls 15

MillisecondsClass · 0.85
allocatedResourcesFunction · 0.85
RESERVEFunction · 0.85
UNRESERVEFunction · 0.85
shutdownFunction · 0.85
maxFunction · 0.85
upgradeResourcesFunction · 0.85
getBootIdPathFunction · 0.85
getMetaRootDirFunction · 0.85
createDiskInfoFunction · 0.85
NoneClass · 0.85

Tested by

no test coverage detected