// Helpers for creating offer operations. inline Offer::Operation CREATE(const Resources& volumes) { Offer::Operation operation; operation.set_type(Offer::Operation::CREATE); operation.mutable_create()->mutable_volumes()->CopyFrom(volumes); return operation; }
TEST(SorterTest, Update) { DRFSorter sorter; sorter.add("a"); sorter.add("b"); sorter.add(Resources::parse("cpus:10;mem:10;disk:10").get()); sorter.allocated("a", Resources::parse("cpus:10;mem:10;disk:10").get()); // Construct an offer operation. Resource volume = Resources::parse("disk", "5", "*").get(); volume.mutable_disk()->mutable_persistence()->set_id("ID"); volume.mutable_disk()->mutable_volume()->set_container_path("data"); Offer::Operation create; create.set_type(Offer::Operation::CREATE); create.mutable_create()->add_volumes()->CopyFrom(volume); // Compute the updated allocation. Resources allocation = sorter.allocation("a"); Try<Resources> newAllocation = allocation.apply(create); ASSERT_SOME(newAllocation); // Update the resources for the client. sorter.update("a", allocation, newAllocation.get()); EXPECT_EQ(newAllocation.get(), sorter.allocation("a")); }