Beispiel #1
0
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"));
}
Beispiel #2
0
LookAndFeel LookAndFeel::create(const std::string& fileName){
    auto root(createRoot<LafParserRoot>(fileName));

    Resources* r = Game::getResources();
    r->load(root.lookAndFeel->resources, fileName, true);
    return LookAndFeel(root.lookAndFeel,r);
}
Beispiel #3
0
void example_destroy()
{
	_tests->detach();
	_tests = 0;
	resources.free();
	resourcesUI.free();
}
Beispiel #4
0
void STLRepository::create( const Resources values, const shared_ptr< Query > query, const function< void ( const shared_ptr< Query > ) >& callback )
{
    unique_lock< mutex> lock( m_resources_lock );
    
    for ( const auto value : values )
    {
        bool conflict = any_of( m_resources.begin( ), m_resources.end( ), [ &value ]( const Resource & resource )
        {
            const auto lhs = String::to_string( value.lower_bound( "key" )->second );
            const auto rhs = String::to_string( resource.lower_bound( "key" )->second );
            
            return String::lowercase( lhs ) == String::lowercase( rhs );
        } );
        
        if ( conflict )
        {
            query->set_error_code( 40009 );
            return callback( query );
        }
    }
    
    m_resources.insert( m_resources.end( ), values.begin( ), values.end( ) );
    
    lock.unlock( );
    
    auto results = fields( values, query );
    
    query->set_resultset( results );
    callback( query );
}
Beispiel #5
0
	void MaterialAsset::__loadTextureToGFXCard( void )
	{
		if ( !__isTextureLoaded )
		{
			Resources* r = DWIngine::singleton()->resources();

			TextureAsset* tex = r->getTexture( __textureUniqueName );

			

			GLuint textureID;
			glGenTextures( 1, &textureID );

			glBindTexture( GL_TEXTURE_2D, textureID );

			unsigned char * data = new unsigned char [tex->width() * tex->height() * 3];

			data = &tex->imageData()[ 68 ];

			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex->width(), tex->height(), 0, GL_BGR, GL_UNSIGNED_BYTE, data );
			//glTexImage2D( GL_TEXTURE_2D, 0, GL_BGR, tex->width(), tex->height(), 0, GL_RGB, GL_UNSIGNED_BYTE, data );

			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
			glGenerateMipmap( GL_TEXTURE_2D );

			__texture = textureID;

			__isTextureLoaded = !__isTextureLoaded;
		}
	}
Beispiel #6
0
TEST(SorterTest, UpdateAllocation)
{
  DRFSorter sorter;

  SlaveID slaveId;
  slaveId.set_value("agentId");

  sorter.add("a");
  sorter.add("b");

  sorter.add(slaveId, Resources::parse("cpus:10;mem:10;disk:10").get());

  sorter.allocated(
      "a", slaveId, 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");

  // Compute the updated allocation.
  Resources oldAllocation = sorter.allocation("a", slaveId);
  Try<Resources> newAllocation = oldAllocation.apply(CREATE(volume));
  ASSERT_SOME(newAllocation);

  // Update the resources for the client.
  sorter.update("a", slaveId, oldAllocation, newAllocation.get());

  hashmap<SlaveID, Resources> allocation = sorter.allocation("a");
  EXPECT_EQ(1u, allocation.size());
  EXPECT_EQ(newAllocation.get(), allocation[slaveId]);
  EXPECT_EQ(newAllocation.get(), sorter.allocation("a", slaveId));
}
Beispiel #7
0
void RandomSorter::remove(const SlaveID& slaveId, const Resources& resources)
{
  if (!resources.empty()) {
    CHECK(total_.resources.contains(slaveId));
    CHECK(total_.resources[slaveId].contains(resources))
      << total_.resources[slaveId] << " does not contain " << resources;

    total_.resources[slaveId] -= resources;

    // Remove shared resources from the total quantities when there
    // are no instances of same resources left in the total.
    const Resources absentShared = resources.shared()
      .filter([this, slaveId](const Resource& resource) {
        return !total_.resources[slaveId].contains(resource);
      });

    const ResourceQuantities scalarQuantities =
      ResourceQuantities::fromScalarResources(
          (resources.nonShared() + absentShared).scalars());

    CHECK(total_.totals.contains(scalarQuantities));
    total_.totals -= scalarQuantities;

    if (total_.resources[slaveId].empty()) {
      total_.resources.erase(slaveId);
    }
  }
}
Beispiel #8
0
int Environment::loadSkin(char *fSkinDirectory)
{

  Elements *fOldElements = mElements;
  Resources *fOldResources = mResources;

  struct stat sbuf;

  char buf[255];
  sprintf(buf, "%sskin.xml", fSkinDirectory);

  printf("Loading %s\n", buf);
  if (stat(buf, &sbuf)) {
    return 0;
  }

  xmlDoc *theDoc = 0;
  xmlNode *theRoot = 0;

  theDoc = xmlReadFile(buf, NULL, 0);
  if (theDoc == NULL) {
    return 0;
  }

  theRoot = xmlDocGetRootElement(theDoc);

  xmlNode *fNode = theRoot->children;

  while (fNode) {
    if (!strcmp((char *) fNode->name, "Resources") && fNode->children) {
      Resources *t = new Resources();
      t->xmlConfigure(fNode->children);
      setResources(t);
    } else if (!strcmp((char *) fNode->name, "Elements") && fNode->children) {
      Elements *t = new Elements();
      t->xmlConfigure(fNode->children);
      setElements(t);
    }
    fNode = fNode->next;
  }

  if (fOldElements != mElements && fOldElements) {
    delete fOldElements;
  }
  if (fOldResources != mResources && fOldResources) {
    delete fOldResources;
  }

  setSkinPath(fSkinDirectory);

  debugPrint("     Loading resources\n");

  mResources->loadResources();
  debugPrint("     Associating resources & elements\n");

  mElements->associateResources(mResources);

  xmlFreeDoc(theDoc);
  return 1;
}
Beispiel #9
0
void Environment::xmlConfigure(xmlNode *fNode)
{
  int fEmbeddedSkin = 0;
  while (fNode) {
    if (!strcmp((char *) fNode->name, "Menu")) {
      SubMenuNode *t = new SubMenuNode();
      t->xmlConfigure(fNode->children);
      setTopMenu(t);
      setCurrentMenu(t);
    } else if (!strcmp((char *) fNode->name, "Resources")) {
      Resources *t = new Resources();
      t->xmlConfigure(fNode->children);
      setResources(t);
      fEmbeddedSkin = 1;
    } else if (!strcmp((char *) fNode->name, "Elements")) {
      Elements *t = new Elements();
      t->xmlConfigure(fNode->children);
      setElements(t);
      fEmbeddedSkin = 1;
    } else if (!strcmp((char *) fNode->name, "Dialog")) {
      Generic *t = new Generic();
      t->xmlConfigure(fNode->children);
      setDialog(t);
    } else if (!strcmp((char *) fNode->name, "LogFile")) {
      setLogFileName((char *) fNode->children->content);
    }
    fNode = fNode->next;
  }
  if (fEmbeddedSkin) {
    mResources->loadResources();
    mElements->associateResources(mResources);
  }
}
Beispiel #10
0
ResourceMark::~ResourceMark() {
  if (!enabled)
    return;
# ifdef ASSERT
  assert(area->nesting> 0, "nesting must be positive");
  area->nesting--;
# endif
  if (PrintResourceAllocation) {
    lprintf("deallocating to mark %#lx\n", top);
  }
  ResourceAreaChunk* prevc;
  ResourceAreaChunk* c;
  for (c = area->chunk; c != chunk; c = prevc) {
    // deallocate all chunks behind marked chunk
    prevc = c->prev;
    resources.addToFreeList(c);
  }
  area->chunk = c;
  if (c == NULL) {
    top = NULL;
    return;
  }
  c->freeTo(top);
  if (top == c->bottom) {
    // this chunk is completely unused - deallocate it
    area->chunk = c->prev;
    resources.addToFreeList(c);
  }
}
Beispiel #11
0
int main(int argc, char *argv[]) {
  Q_INIT_RESOURCE(resources);

  QGuiApplication app(argc, argv);
  app.setApplicationName("osmand-qt");
  app.setApplicationVersion("0.1");

  __CoreResourcesEmbeddedBundle__FakeReferences();
  shared_ptr<const CoreResourcesEmbeddedBundle> bundle =
    CoreResourcesEmbeddedBundle::loadFromCurrentExecutable();
  InitializeCore(bundle);

  qmlRegisterType<MapCanvas>("OsmAndQt", 1, 0, "MapCanvas");
  qmlRegisterUncreatableType<Resources>("OsmAndQt", 1, 0, "Resources", "");
  qmlRegisterUncreatableType<ResourceModel>("OsmAndQt", 1, 0, "ResourceModel", "");

  Resources resources;
  resources.downloadIfNecessary(QList<QString>()
              << "world_basemap.map.obf"
              << "austria_europe.map.obf"
              );

  QQmlApplicationEngine engine;
  engine.rootContext()->setContextProperty("contextResources", &resources);
  engine.load(QUrl("qrc:/src/Main.qml"));

  qobject_cast<QQuickWindow *>(engine.rootObjects().value(0))->show();

  return app.exec();
}
Beispiel #12
0
Resources JSONFormatter::parse( const Bytes& value )
{
    auto json = json::parse( String::to_string( value ) );
    
    if ( json.count( "data" ) == 0 )
    {
        throw domain_error( "Root property must be named 'data'." );
    }
    
    auto data = json[ "data" ];
    Resources resources;
    
    if ( data.is_array( ) )
    {
        for ( const auto object : data )
        {
            if ( not object.is_object( ) )
            {
                throw domain_error( "Root array child elements must be objects." );
            }
            
            resources.push_back( parse_object( object ) );
        }
    }
    else if ( data.is_object( ) )
    {
        resources.push_back( parse_object( data ) );
    }
    else
    {
        throw domain_error( "Root property must be unordered set or object." );
    }
    
    return resources;
}
Beispiel #13
0
TEST(ResourcesTest, ScalarSubtraction)
{
  Resource cpus1 = Resources::parse("cpus", "50", "*").get();
  Resource mem1 = Resources::parse("mem", "4096", "*").get();

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

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

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

  Resources diff = r1 - r2;

  EXPECT_FALSE(diff.empty());
  EXPECT_EQ(49.5, diff.get<Value::Scalar>("cpus").get().value());
  EXPECT_EQ(3072, diff.get<Value::Scalar>("mem").get().value());

  Resources r = r1;
  r -= r2;

  EXPECT_EQ(49.5, diff.get<Value::Scalar>("cpus").get().value());
  EXPECT_EQ(3072, diff.get<Value::Scalar>("mem").get().value());

  r = r1;
  r -= r1;

  EXPECT_TRUE(r.empty());
}
Beispiel #14
0
TEST(ResourcesTest, ScalarAddition)
{
  Resource cpus1 = Resources::parse("cpus", "1", "*").get();
  Resource mem1 = Resources::parse("mem", "5", "*").get();

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

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

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

  Resources sum = r1 + r2;

  EXPECT_FALSE(sum.empty());
  EXPECT_EQ(3, sum.get<Value::Scalar>("cpus").get().value());
  EXPECT_EQ(15, sum.get<Value::Scalar>("mem").get().value());

  Resources r = r1;
  r += r2;

  EXPECT_FALSE(r.empty());
  EXPECT_EQ(3, r.get<Value::Scalar>("cpus").get().value());
  EXPECT_EQ(15, r.get<Value::Scalar>("mem").get().value());
}
Beispiel #15
0
void
SFMLInputs::init( EntityManager &em) {
  Inputs::init( em);
  Resources *resources = em.getComponent<Resources>();
  SFMLVisualContext &vc = (SFMLVisualContext &) resources->getVisualContext();
  window_ = &vc.getRenderWindow();
  state_ = new SFMLInputState(vc, window_);
}
Beispiel #16
0
void newMatch(void)
{
    buildMaze(glmaze, Graph_Space, tileSpace, Tilesize,
              Resources_Manager.texture("wall.tga"),
              Resources_Manager.texture("floor.tga"),
              Resources_Manager.texture("ceil.tga"), &Config_Info);
    restartMatch();
}
Beispiel #17
0
    Resources* assign(int n)
    {
        Resources* r = new Resources;

        for(int i = 0; i < n; ++i) {
            r->push_back(mResources->back());
            mResources->pop_back();
        }
        return r;
    }
Beispiel #18
0
TEST(ResourcesTest, RangesSubtraction4)
{
  Resources resources = Resources::parse("ports:[50000-60000]").get();

  Resources resourcesOffered;
  resourcesOffered += resources;
  resourcesOffered -= resources;

  EXPECT_TRUE(resourcesOffered.empty());
  EXPECT_NONE(resourcesOffered.get<Value::Ranges>("ports"));
}
  void resourceOffers(const vector<Offer>& offers)
  {
    foreach (const Offer& offer, offers) {
      cout << "Received offer " << offer.id() << " with "
           << Resources(offer.resources())
           << endl;

      static const Resources TASK_RESOURCES = Resources::parse(
          "cpus:" + stringify(CPUS_PER_TASK) +
          ";mem:" + stringify(MEM_PER_TASK)).get();

      Resources remaining = offer.resources();

      // Launch tasks.
      vector<TaskInfo> tasks;
      while (tasksLaunched < totalTasks &&
             remaining.flatten().contains(TASK_RESOURCES)) {
        int taskId = tasksLaunched++;

        cout << "Launching task " << taskId << " using offer "
             << offer.id() << endl;

        TaskInfo task;
        task.set_name("Task " + lexical_cast<string>(taskId));
        task.mutable_task_id()->set_value(
            lexical_cast<string>(taskId));
        task.mutable_agent_id()->MergeFrom(offer.agent_id());
        task.mutable_executor()->MergeFrom(executor);

        Option<Resources> resources =
          remaining.find(TASK_RESOURCES.flatten(framework.role()));

        CHECK_SOME(resources);

        task.mutable_resources()->CopyFrom(resources.get());

        remaining -= resources.get();

        tasks.push_back(task);
      }

      Call call;
      CHECK(framework.has_id());
      call.mutable_framework_id()->CopyFrom(framework.id());
      call.set_type(Call::ACCEPT);

      Call::Accept* accept = call.mutable_accept();
      accept->add_offer_ids()->CopyFrom(offer.id());

      Offer::Operation* operation = accept->add_operations();
      operation->set_type(Offer::Operation::LAUNCH);
      foreach (const TaskInfo& taskInfo, tasks) {
        operation->mutable_launch()->add_task_infos()->CopyFrom(taskInfo);
      }
Beispiel #20
0
void restartMatch(void)
{
    gettimeofday(&Initial_Timer, NULL);

    MatrixCoord startGraphCoord = MatrixCoord(0, 0);
    MatrixCoord goalGraphCoord = MatrixCoord(Graph_Space.size().x-1, Graph_Space.size().y-1);

    for (unsigned int i=0; i<Player_List.size(); ++i) {
        if (Player_List[i]) {
            delete Player_List[i];
        }
    }
    Player_List.clear();
    Player_List = std::vector<PlayerBase*>(Config_Info.playerConfigs.size());

    float runSpeed = 0.2f;

    for (unsigned int i=0; i<Config_Info.playerConfigs.size(); ++i) {
        if (Config_Info.playerConfigs[i].type == HUMAN) {
            human = new Human(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                              startGraphCoord, goalGraphCoord, Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                              glmaze.aabb, Tilesize);
            Player_List[i] = human;
            humanIndex = i;
        }
        else if (Config_Info.playerConfigs[i].type == AI_DFS) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         randomDFSPath(Graph_Space, startGraphCoord, goalGraphCoord), Tilesize);
        }
        else if (Config_Info.playerConfigs[i].type == AI_SMART) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         smartEnhancePath(randomDFSPath(Graph_Space, startGraphCoord, goalGraphCoord)), Tilesize);
        }
        else if (Config_Info.playerConfigs[i].type == AI_DUMB) {
            Player_List[i] = new AIRobot(Config_Info.playerConfigs[i].name, Config_Info.playerConfigs[i].color, runSpeed,
                                         Resources_Manager.mesh("robot.obj"), Resources_Manager.texture("comp.tga"),
                                         dumbPath(Graph_Space, startGraphCoord, goalGraphCoord), Tilesize);
        }
    }
    finishedPlayers = std::vector<int>(Config_Info.playerConfigs.size(), 0);

    glm::vec3 startcone = tileSpaceToWorldSpace(MatrixCoord(1,1), Tilesize, Tilesize/2.0f);
    glm::vec3 endcone = tileSpaceToWorldSpace(tileSpace.size()-MatrixCoord(2,2), Tilesize, Tilesize/2.0f);
    cone1 = Cone(Resources_Manager.mesh("cone.obj"), Resources_Manager.texture("startmark.tga"), startcone);
    cone2 = Cone(Resources_Manager.mesh("cone.obj"), Resources_Manager.texture("finishmark.tga"), endcone);

    winners.clear();
    toggleCameraButton->show = false;
    Camera_Mode = humanIndex;

}
    MainActor()
    {
        //create simple Sprite
        spSprite button = new Sprite();

        //setup it:
        //set button.png image. Resource 'button' defined in 'res.xml'
        button->setResAnim(gameResources.getResAnim("button"));

        //centered button at screen
        Vector2 pos = getStage()->getSize() / 2 - button->getSize() / 2;
        button->setPosition(pos);

        //handle click to button
        EventCallback cb = CLOSURE(this, &MainActor::buttonClicked);
        button->addEventListener(TouchEvent::CLICK, cb);

#ifdef CLOSURE_FUNCTION //if your compiler supports lambda

        button->addEventListener(TouchEvent::CLICK, [](Event * e)->void
        {
            log::messageln("button clicked");
        });

#endif

        //attach button as child to current actor
        addChild(button);

        _button = button;


        //second part

        //create TextField Actor
        spTextField text = new TextField();
        //attach it as child to button
        text->addTo(button);
        //centered in button
        text->setPosition(button->getSize() / 2);

        //initialize text style
        TextStyle style;
        style.font = gameResources.getResFont("main")->getFont();
        style.color = Color::White;
        style.vAlign = TextStyle::VALIGN_MIDDLE;
        style.hAlign = TextStyle::HALIGN_CENTER;

        text->setStyle(style);
        text->setText("Click\nMe!");

        _text = text;
    }
Beispiel #22
0
  virtual void resourceOffers(SchedulerDriver* driver,
                              const vector<Offer>& offers)
  {
    for (size_t i = 0; i < offers.size(); i++) {
      const Offer& offer = offers[i];
      Resources remaining = offer.resources();

      static Resources TASK_RESOURCES = Resources::parse(
          "cpus:" + stringify<float>(CPUS_PER_TASK) +
          ";mem:" + stringify<size_t>(MEM_PER_TASK)).get();

      size_t maxTasks = 0;
      while (remaining.flatten().contains(TASK_RESOURCES)) {
        maxTasks++;
        remaining -= TASK_RESOURCES;
      }

      // Launch tasks.
      vector<TaskInfo> tasks;
      for (size_t i = 0; i < maxTasks / 2 && crawlQueue.size() > 0; i++) {
        string url = crawlQueue.front();
        crawlQueue.pop();
        string urlId = "C" + stringify<size_t>(processed[url]);
        TaskInfo task;
        task.set_name("Crawler " + urlId);
        task.mutable_task_id()->set_value(urlId);
        task.mutable_slave_id()->MergeFrom(offer.slave_id());
        task.mutable_executor()->MergeFrom(crawler);
        task.mutable_resources()->MergeFrom(TASK_RESOURCES);
        task.set_data(url);
        tasks.push_back(task);
        tasksLaunched++;
        cout << "Crawler " << urlId << " " << url << endl;
      }
      for (size_t i = maxTasks/2; i < maxTasks && renderQueue.size() > 0; i++) {
        string url = renderQueue.front();
        renderQueue.pop();
        string urlId = "R" + stringify<size_t>(processed[url]);
        TaskInfo task;
        task.set_name("Renderer " + urlId);
        task.mutable_task_id()->set_value(urlId);
        task.mutable_slave_id()->MergeFrom(offer.slave_id());
        task.mutable_executor()->MergeFrom(renderer);
        task.mutable_resources()->MergeFrom(TASK_RESOURCES);
        task.set_data(url);
        tasks.push_back(task);
        tasksLaunched++;
        cout << "Renderer " << urlId << " " << url << endl;
      }

      driver->launchTasks(offer.id(), tasks);
    }
  }
Beispiel #23
0
// 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();
}
Beispiel #24
0
void DRFSorter::add(const SlaveID& slaveId, const Resources& resources)
{
  if (!resources.empty()) {
    total_.resources[slaveId] += resources;
    total_.scalarQuantities += resources.createStrippedScalarQuantity();

    // We have to recalculate all shares when the total resources
    // change, but we put it off until sort is called so that if
    // something else changes before the next allocation we don't
    // recalculate everything twice.
    dirty = true;
  }
}
Beispiel #25
0
	// ------------------------------------------------------
	// 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));
				}
			}
		}	
	}
SpaceObject::SpaceObject(sf::Texture &t, Resources &res, int health, int speed) : explosionTexture(res.getImg()->getExplosion_t())
{
	//Create graphical object
	this->sprite.setTexture(t);

	//Set properties values
	this->health = health;
	this->speed = speed;

	//Set the explosion sound buffer
	this->explosionSound.setBuffer(res.getExplosionSnd());
	this->explosionSound.setVolume(res.getConfigXML()->getSettings()->getVolumeSound());
}
Beispiel #27
0
TEST(ResourcesTest, BadResourcesNotAllocatable)
{
  Resource cpus;
  cpus.set_type(Resource::SCALAR);
  cpus.mutable_scalar()->set_value(1);
  Resources r;
  r += cpus;
  EXPECT_EQ(0, r.allocatable().size());
  cpus.set_name("cpus");
  cpus.mutable_scalar()->set_value(0);
  r += cpus;
  EXPECT_EQ(0, r.allocatable().size());
}
Beispiel #28
0
TEST(ResourcesTest, FlattenRoles)
{
  Resource cpus1 = Resources::parse("cpus", "1", "role1").get();
  Resource cpus2 = Resources::parse("cpus", "2", "role2").get();
  Resource mem1 = Resources::parse("mem", "5", "role1").get();

  Resources r;
  r += cpus1;
  r += cpus2;
  r += mem1;

  EXPECT_EQ(r.flatten(), Resources::parse("cpus:3;mem:5").get());
}
Beispiel #29
0
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());
}
    void ThreadLoader::unload()
    {
        for (resources::iterator i = _resources.begin(); i != _resources.end(); ++i)
        {
            Resources* res = *i;
            res->unload();
        }

        for (ress::iterator i = _ress.begin(); i != _ress.end(); ++i)
        {
            Resource* res = *i;
            res->unload();
        }
    }