本文整理汇总了C++中Attributes::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Attributes::get方法的具体用法?C++ Attributes::get怎么用?C++ Attributes::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attributes
的用法示例。
在下文中一共展示了Attributes::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
// Test that the changes made by the resources decorator hook are correctly
// propagated to the resource offer.
TEST_F(HookTest, VerifySlaveResourcesAndAttributesDecorator)
{
Try<PID<Master>> master = StartMaster(CreateMasterFlags());
ASSERT_SOME(master);
MockExecutor exec(DEFAULT_EXECUTOR_ID);
TestContainerizer containerizer(&exec);
// Start a mock slave since we aren't testing the slave hooks yet.
Try<PID<Slave>> slave = StartSlave(&containerizer);
ASSERT_SOME(slave);
MockScheduler sched;
MesosSchedulerDriver driver(
&sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
EXPECT_CALL(sched, registered(&driver, _, _));
Future<vector<Offer>> offers;
EXPECT_CALL(sched, resourceOffers(&driver, _))
.WillOnce(FutureArg<1>(&offers))
.WillRepeatedly(Return()); // Ignore subsequent offers.
driver.start();
AWAIT_READY(offers);
EXPECT_NE(0u, offers.get().size());
Resources resources = offers.get()[0].resources();
// The test hook sets "cpus" to 4.
EXPECT_EQ(4, resources.cpus().get());
// The test hook adds a resource named "foo" of type set with values "bar"
// and "baz".
EXPECT_EQ(Resources::parse("foo:{bar,baz}").get(), resources.get("foo"));
// The test hook does not modify "mem", the default value must still be
// present.
EXPECT_SOME(resources.mem());
// The test hook adds an attribute named "rack" with value "rack1".
Attributes attributes = offers.get()[0].attributes();
ASSERT_EQ(attributes.get(0).name(), "rack");
ASSERT_EQ(attributes.get(0).text().value(), "rack1");
driver.stop();
driver.join();
Shutdown();
}
示例2:
TEST(AttributesTest, invalid_attrib_is_ignored)
{
string s = "default";
Attributes a;
a.addFromGFF("foo");
EXPECT_FALSE(a.get("foo", s));
EXPECT_EQ("default", s);
}
示例3:
TEST(AttributesTest, Parsing)
{
Attributes a = Attributes::parse("cpus:45.55;"
"ports:[10000-20000, 30000-50000];"
"rack:rack1,rack2");
ASSERT_EQ(Value::SCALAR, a.get(0).type());
ASSERT_EQ("cpus", a.get(0).name());
ASSERT_FLOAT_EQ(45.55, a.get(0).scalar().value());
ASSERT_EQ(Value::RANGES, a.get(1).type());
ASSERT_EQ("ports", a.get(1).name());
ASSERT_EQ(2, a.get(1).ranges().range_size());
ASSERT_EQ(10000u, a.get(1).ranges().range(0).begin());
ASSERT_EQ(20000u, a.get(1).ranges().range(0).end());
ASSERT_EQ(30000u, a.get(1).ranges().range(1).begin());
ASSERT_EQ(50000u, a.get(1).ranges().range(1).end());
ASSERT_EQ(Value::TEXT, a.get(2).type());
ASSERT_EQ("rack", a.get(2).name());
ASSERT_EQ("rack1,rack2", a.get(2).text().value());
Attributes b = Attributes::parse("attr1:foo:bar;attr2:baz:qux:");
ASSERT_EQ(Value::TEXT, b.get(0).type());
ASSERT_EQ("attr1", b.get(0).name());
ASSERT_EQ("foo:bar", b.get(0).text().value());
ASSERT_EQ(Value::TEXT, b.get(1).type());
ASSERT_EQ("attr2", b.get(1).name());
ASSERT_EQ("baz:qux:", b.get(1).text().value());
}