コード例 #1
0
ファイル: resources_tests.cpp プロジェクト: adegtiar/mesos
TEST(ResourcesTest, ScalarSubtraction)
{
  Resource cpus1 = Resources::parse("cpus", "50");
  Resource mem1 = Resources::parse("mem", "4096");

  Resource cpus2 = Resources::parse("cpus", "0.5");
  Resource mem2 = Resources::parse("mem", "1024");

  Resources r1;
  r1 += cpus1;
  r1 += mem1;

  Resources r2;
  r2 += cpus2;
  r2 += mem2;

  Resources diff = r1 - r2;
  EXPECT_EQ(2, diff.size());
  EXPECT_EQ(49.5, diff.get("cpus", Resource::Scalar()).value());
  EXPECT_EQ(3072, diff.get("mem", Resource::Scalar()).value());

  Resources r = r1;
  r -= r2;
  EXPECT_EQ(49.5, diff.get("cpus", Resource::Scalar()).value());
  EXPECT_EQ(3072, diff.get("mem", Resource::Scalar()).value());

  r = r1;
  r -= r1;
  EXPECT_EQ(0, r.allocatable().size());
}
コード例 #2
0
ファイル: resources_tests.cpp プロジェクト: adegtiar/mesos
TEST(ResourcesTest, ScalarAddition)
{
  Resource cpus1 = Resources::parse("cpus", "1");
  Resource mem1 = Resources::parse("mem", "5");

  Resource cpus2 = Resources::parse("cpus", "2");
  Resource mem2 = Resources::parse("mem", "10");

  Resources r1;
  r1 += cpus1;
  r1 += mem1;

  Resources r2;
  r2 += cpus2;
  r2 += mem2;

  Resources sum = r1 + r2;
  EXPECT_EQ(2, sum.size());
  EXPECT_EQ(3, sum.get("cpus", Resource::Scalar()).value());
  EXPECT_EQ(15, sum.get("mem", Resource::Scalar()).value());

  Resources r = r1;
  r += r2;
  EXPECT_EQ(2, r.size());
  EXPECT_EQ(3, r.get("cpus", Resource::Scalar()).value());
  EXPECT_EQ(15, r.get("mem", Resource::Scalar()).value());
}
コード例 #3
0
ファイル: Resources.cpp プロジェクト: amecky/space
	// ------------------------------------------------------
	// show resources
	// ------------------------------------------------------
	void show_resources(const ResourceRegistry& reg,const Resources& res,bool complete) {
		//printf("Resources:\n");
		for ( int i = 0; i <reg.size(); ++i ) {
			if ( complete) {
				printf("%10s : %d\n",reg.getName(i),res.get(i));
			}
			else {
				if ( res.get(i) > 0 ) {
					printf("%10s : %d\n",reg.getName(i),res.get(i));
				}
			}
		}	
	}
コード例 #4
0
ファイル: TmxMap.cpp プロジェクト: mahnovsky/tbs_client
spTmxMap TmxMap::loadMap(const char* name, Resources& resStore, const PropCallback& pc)
{
    Resource* res = resStore.get(name);
    
    if(res == nullptr)
    {
        log::error("resource %s not found", name);
        return nullptr;
    }
    
    ResBuffer* rb = dynamic_cast<ResBuffer*>(res);
    
    if(rb == nullptr)
    {
        log::error("resource %s not buffer", name);
        return nullptr;
    }
    
    const file::buffer& buf = rb->getBuffer();
    
    pugi::xml_document doc;
    pugi::xml_parse_result pr = doc.load_buffer(buf.getData(), buf.getSize());
    
    if(pr.status != pugi::status_ok)
    {
        log::error("resource %s not xml", name);
        return nullptr;
    }
    
    pugi::xml_node xm = doc.child("map");
    
    spTmxMap map = new TmxMap;
    
    map->_width = xm.attribute("width").as_int();
    map->_height = xm.attribute("height").as_int();
    map->_tileWidth = xm.attribute("tile_width").as_int();
    map->_tileHeight = xm.attribute("tile_height").as_int();

	pugi::xml_node ts = xm.child("tileset");
	map->_tileset.init(ts, resStore);
    
    int order = 0;
    for (auto item = xm.first_child(); item; item = item.next_sibling())
    {
        if(strcmp(item.name(), "layer") == 0)
        {
            spTmxLayer layer = TmxLayer::loadLayer(item, resStore, &map->_tileset, pc);
            
            if(layer.get() != nullptr)
            {
                layer->setPriority(order);
                layer->attachTo(map);
                
                ++order;
            }
        }
    }
    
    return map;
}
コード例 #5
0
ファイル: Resources.cpp プロジェクト: amecky/space
	// ------------------------------------------------------
	// show resources
	// ------------------------------------------------------
	void log_resources(const ResourceRegistry& reg,const Resources& res,bool complete) {
		LOG << "Resources:";
		char buffer[128];
		for ( int i = 0; i <reg.size(); ++i ) {
			if ( complete) {
				sprintf(buffer,"%10s : %d",reg.getName(i),res.get(i));
				LOG << buffer;
			}
			else {
				if ( res.get(i) > 0 ) {
					sprintf(buffer,"%10s : %d",reg.getName(i),res.get(i));
					LOG << buffer;
				}
			}
		}	
	}
コード例 #6
0
ファイル: hook_tests.cpp プロジェクト: lodejard/mesoswin
// 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();
}
コード例 #7
0
ファイル: resources_tests.cpp プロジェクト: adegtiar/mesos
TEST(ResourcesTest, SetAddition)
{
  Resource disks1 = Resources::parse("disks", "{sda1,sda2,sda3}");
  Resource disks2 = Resources::parse("disks", "{sda1,sda2,sda3,sda4}");

  Resources r;
  r += disks1;
  r += disks2;

  EXPECT_EQ(1, r.size());

  const Resource::Set& set = r.get("disks", Resource::Set());

  EXPECT_EQ(4, set.item_size());
}
コード例 #8
0
ファイル: resources_tests.cpp プロジェクト: adegtiar/mesos
TEST(ResourcesTest, RangesSubtraction)
{
  Resource ports1 = Resources::parse("ports", "[20000-40000]");
  Resource ports2 = Resources::parse("ports", "[10000-20000, 30000-50000]");

  Resources r;
  r += ports1;
  r -= ports2;

  EXPECT_EQ(1, r.size());

  const Resource::Ranges& ranges = r.get("ports", Resource::Ranges());

  EXPECT_EQ(1, ranges.range_size());
  EXPECT_EQ(20001, ranges.range(0).begin());
  EXPECT_EQ(29999, ranges.range(0).end());
}
コード例 #9
0
ファイル: resources_tests.cpp プロジェクト: adegtiar/mesos
TEST(ResourcesTest, RangesAddition)
{
  Resource ports1 = Resources::parse("ports", "[20000-40000, 21000-38000]");
  Resource ports2 = Resources::parse("ports", "[30000-50000, 10000-20000]");

  Resources r;
  r += ports1;
  r += ports2;

  EXPECT_EQ(1, r.size());

  const Resource::Ranges& ranges = r.get("ports", Resource::Ranges());

  EXPECT_EQ(1, ranges.range_size());
  EXPECT_EQ(10000, ranges.range(0).begin());
  EXPECT_EQ(50000, ranges.range(0).end());
}
コード例 #10
0
void example_init()
{
	//load xml file with resources definition
	gameResources.loadXML("res.xml");

	Resources::registerResourceType(ResKeyframeAnimation::create, "keyframe_anim");
	animResources.loadXML("godscores_res.xml");

	// temporary solution
	// here we are connecting string resources names to real ResAnims
	int res_count = animResources.getCount();
	for (int ind = 0; ind < res_count; ++ind)
	{
		Resource * res = animResources.get(ind);
		ResKeyframeAnimation * res_ka = dynamic_cast<ResKeyframeAnimation *>(res);

		if (res_ka)
			res_ka->linkWithResAnims(&animResources);
	}

	spAnimatedActor anim = new AnimatedActor();
	anim->setName("anim");
	anim->setPosition(250, 80);
	anim->setResAnim(animResources.getT<ResKeyframeAnimation>("godscores"));
	anim->play();

	RootActor::instance->addChild(anim);

	//create Play/Stop button
	spButton button = new Button();
	button->setName("btn");
	button->setResAnim(gameResources.getResAnim("button"));
	button->setPosition(50, VirtualHeight - 10);		
	button->setAnchor(Vector2(0.0, 1.0));
	button->setInputChildrenEnabled(false);
	EventCallback cb = CLOSURE(&a, &ab::clicked);
	button->addEventListener(TouchEvent::CLICK, cb);
	RootActor::instance->addChild(button);

	//create Actor with Text and it to button as child
	spTextActor caption = new TextActor();
	caption->setName("caption");
	TextStyle style;
	style.font = gameResources.getResFont("main")->getFont();
	style.color = Color(255, 255, 139, 255);
	style.vAlign = TextStyle::VALIGN_MIDDLE;
	style.hAlign = TextStyle::HALIGN_CENTER;
	caption->setStyle(style);
	caption->setSize(button->getSize());
	caption->setText(L"Pause");
	button->setScale(0.8f);
	button->addChild(caption);

	// create frame counter
	spTextActor frame_text = new TextActor();
	frame_text->setName("frame");
	TextStyle style2;
	style2.font = gameResources.getResFont("main")->getFont();
	style2.color = Color(255, 255, 139, 255);
	style2.vAlign = TextStyle::VALIGN_TOP;
	frame_text->setStyle(style2);
	frame_text->setPosition(10, 10);
	frame_text->setScale(0.6f);
	frame_text->setSize(200, 30);
	RootActor::instance->addChild(frame_text);
}