Checks that the DRF allocator implements the DRF algorithm correctly. The test accomplishes this by adding frameworks and slaves one at a time to the allocator, making sure that each time a new slave is added all of its resources are offered to whichever framework currently has the smallest share. Checking for proper DRF logic when resources are returned, frameworks exit, etc. is handled by Sorter
| 291 | // logic when resources are returned, frameworks exit, etc. is handled |
| 292 | // by SorterTest.DRFSorter. |
| 293 | TEST_F(HierarchicalAllocatorTest, UnreservedDRF) |
| 294 | { |
| 295 | // Pausing the clock is not necessary, but ensures that the test |
| 296 | // doesn't rely on the batch allocation in the allocator, which |
| 297 | // would slow down the test. |
| 298 | Clock::pause(); |
| 299 | |
| 300 | initialize(); |
| 301 | |
| 302 | // Total cluster resources will become cpus=2, mem=1024. |
| 303 | SlaveInfo slave1 = createSlaveInfo("cpus:2;mem:1024;disk:0"); |
| 304 | allocator->addSlave( |
| 305 | slave1.id(), |
| 306 | slave1, |
| 307 | AGENT_CAPABILITIES(), |
| 308 | None(), |
| 309 | slave1.resources(), |
| 310 | {}); |
| 311 | |
| 312 | // framework1 will be offered all of slave1's resources since it is |
| 313 | // the only framework running so far. |
| 314 | FrameworkInfo framework1 = createFrameworkInfo({"role1"}); |
| 315 | allocator->addFramework(framework1.id(), framework1, {}, true, {}); |
| 316 | |
| 317 | Allocation expected = Allocation( |
| 318 | framework1.id(), |
| 319 | {{"role1", {{slave1.id(), slave1.resources()}}}}); |
| 320 | |
| 321 | AWAIT_EXPECT_EQ(expected, allocations.get()); |
| 322 | |
| 323 | // role1 share = 1 (cpus=2, mem=1024) |
| 324 | // framework1 share = 1 |
| 325 | |
| 326 | FrameworkInfo framework2 = createFrameworkInfo({"role2"}); |
| 327 | allocator->addFramework(framework2.id(), framework2, {}, true, {}); |
| 328 | |
| 329 | // Total cluster resources will become cpus=3, mem=1536: |
| 330 | // role1 share = 0.66 (cpus=2, mem=1024) |
| 331 | // framework1 share = 1 |
| 332 | // role2 share = 0 |
| 333 | // framework2 share = 0 |
| 334 | SlaveInfo slave2 = createSlaveInfo("cpus:1;mem:512;disk:0"); |
| 335 | allocator->addSlave( |
| 336 | slave2.id(), |
| 337 | slave2, |
| 338 | AGENT_CAPABILITIES(), |
| 339 | None(), |
| 340 | slave2.resources(), |
| 341 | {}); |
| 342 | |
| 343 | // framework2 will be offered all of slave2's resources since role2 |
| 344 | // has the lowest user share, and framework2 is its only framework. |
| 345 | expected = Allocation( |
| 346 | framework2.id(), |
| 347 | {{"role2", {{slave2.id(), slave2.resources()}}}}); |
| 348 | |
| 349 | AWAIT_EXPECT_EQ(expected, allocations.get()); |
| 350 |
nothing calls this directly
no test coverage detected