/** @test multiple ways how to initiate the advice collaboration */
 void
 createCollaboration()
   {
     TheAdvised client1 ("topic1()");
     TheAdvisor server2 ("topic2()");
     
     int r1 (1 + (rand() % 1000));
     int r2 (1 + (rand() % 1000));
     
     server2.publish (r2);
     CHECK (client1.got(0));
     
     TheAdvised client2 ("topic2()");
     CHECK (client2.got(r2));
     
     TheAdvisor server1;
     CHECK (client1.got(0));
     
     server1.publish (r1);
     CHECK (client1.got(0));
     CHECK (client2.got(r2));
     
     server1.rebind ("topic1()");
     CHECK (client1.got(r1));
     CHECK (client2.got(r2));
   }
void SelectServerScene::onLButtonDown(int x, int y)
{
	if(x > 139 && x < (139+138)) // ABADDON Button
	{
		if(y > 176 && y < (176+19))
		{
			selectServerFocus = ABADDON;
			server1();
		}
	}

	if(x > 131 && x < (139+157)) // APOCALYPSE Button
	{
		if(y > 204 && y < (204+19))
		{
			selectServerFocus = APOCALYPSE;
			server2();
		}
	}

	if(x > 256 && x < (256+76)) // Cancel Button
	{
		if(y > 282 && y < (282+20))
		{
			cancel();
		}
	}
}
int main ()
{
   std::atomic <uint16_t> response_count (0);

   paxos::server::callback_type callback =
      [& response_count](int64_t, std::string const & workload) -> std::string
      {
         ++response_count;

         return "bar";
      };

   paxos::configuration configuration;
   configuration.set_strategy_factory (new test_strategy_factory (configuration.durable_storage ()));

   paxos::server server1 ("127.0.0.1", 1337, callback);
   paxos::server server2 ("127.0.0.1", 1338, callback);
   paxos::server server3 ("127.0.0.1", 1339, callback, configuration);
   paxos::client client;

   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   /*!
     This would be retried and shouldn't cause any troubles.
    */
   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   PAXOS_ASSERT_EQ (response_count, 2);

   PAXOS_INFO ("test succeeded");   
}
Example #4
0
    TEST_F(ServerCollectTest, touch)
    {
      srand(time(NULL));
      DataServerStatInfo info;
      memset(&info, 0, sizeof(info));
      info.status_ = DATASERVER_STATUS_ALIVE;
      info.id_ = 0xfffffff0;
      info.use_capacity_ = 0xffffff;
      info.total_capacity_ = 0xffffffff;
      time_t now = Func::get_monotonic_time();
      bool master   = true;
      bool writable = true;
      ServerCollect server(info, now);
      info.id_++;
      ServerCollect server2(info,now);
      ServerCollect* invalid_server = NULL;
      const int32_t BLOCK_COUNT = random() % 10000 + 40960;
      BlockCollect* blocks[BLOCK_COUNT];
      int32_t i = 0;
      for (i = 0; i < BLOCK_COUNT; ++i)
        blocks[i] = new BlockCollect(100 + i, now);

      for (i = 0; i < BLOCK_COUNT; ++i)
      {
        blocks[i]->add(writable, master, invalid_server, &server);
        EXPECT_TRUE(server.add(blocks[i], writable, master));
      }

      EXPECT_TRUE(server.writable_->size() > 0);
      EXPECT_EQ(0, server.hold_master_->size());
      EXPECT_EQ(BLOCK_COUNT, server.hold_->size());

      bool promote = false;
      int32_t count = 0;
      int64_t average_used_capacity = 0xfff;
      EXPECT_FALSE(server.touch(promote, count, average_used_capacity));
      count = 3;
      EXPECT_FALSE(server.touch(promote, count, average_used_capacity));
      count = 3;
      promote = true;
      EXPECT_TRUE(server.touch(promote, count, average_used_capacity));
      EXPECT_EQ(3, count);
      average_used_capacity = 0xffffff;
      EXPECT_TRUE(server.touch(promote, count, average_used_capacity));
      EXPECT_EQ(3, count);

      for (i = 0; i < BLOCK_COUNT; ++i)
      {
        blocks[i]->add(writable, master, invalid_server, &server2);
        server2.add(blocks[i], writable, master);
      }

      EXPECT_TRUE(server2.touch(promote, count, average_used_capacity));
      EXPECT_EQ(0, count);
      EXPECT_TRUE(server2.hold_master_->size() == 3);

      for (i = 0; i < BLOCK_COUNT; ++i)
        tbsys::gDelete(blocks[i]);
      EXPECT_EQ(BLOCK_COUNT, server.hold_->size());
    }
void SelectServerScene::onKeyDown(SDLKey Sym, SDLMod Mod, Uint16 Unicode)
{
	if(Sym == SDLK_ESCAPE)
	{
		Game::getInstance().changeScene(new MenuScene);
	}

	if(Sym == SDLK_RETURN)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			server1();
			break;
		case APOCALYPSE:
			server2();
			break;
		case CANCEL:
			cancel();
			break;
		}
	}

	if(Sym == SDLK_UP)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			selectServerFocus = CANCEL;
			break;
		case APOCALYPSE:
			selectServerFocus = ABADDON;
			break;
		case CANCEL:
			selectServerFocus = APOCALYPSE;
			break;
		}
	}

	if(Sym == SDLK_DOWN || Sym == SDLK_TAB)
	{
		switch(selectServerFocus)
		{
		case ABADDON:
			selectServerFocus = APOCALYPSE;
			break;
		case APOCALYPSE:
			selectServerFocus = CANCEL;
			break;
		case CANCEL:
			selectServerFocus = ABADDON;
			break;
		}
	}
}
Example #6
0
    TEST_F(ServerCollectTest, touch)
    {
      srand(time(NULL));
      DataServerStatInfo info;
      memset(&info, 0, sizeof(info));
      info.status_ = DATASERVER_STATUS_ALIVE;
      info.id_ = 0xfffffff0;
      info.use_capacity_ = 0xffffff;
      info.total_capacity_ = 0xffffffff;
      time_t now = Func::get_monotonic_time();
      bool master   = true;
      bool writable = true;
      ServerCollect server(layout_manager_, info, now);
      info.id_++;
      ServerCollect server2(layout_manager_, info,now);
      const int32_t BLOCK_COUNT = random() % 10000 + 40960;
      for (int32_t i = 0; i < BLOCK_COUNT; ++i)
      {
        BlockCollect* block = layout_manager_.get_block_manager().insert(100 + i, now);
        EXPECT_TRUE(NULL != block);
        block->add(writable, master, server.id(), now);
        EXPECT_EQ(TFS_SUCCESS, server.add(block->id(), writable, master));
      }
      EXPECT_TRUE(server.writable_->size() > 0);
      EXPECT_EQ(0, server.hold_master_->size());
      EXPECT_EQ(BLOCK_COUNT, server.hold_->size());

      bool promote = false;
      int32_t count = 0;
      int64_t average_used_capacity = 0xfff;
      EXPECT_FALSE(server.touch(promote, count, average_used_capacity));
      count = 3;
      EXPECT_FALSE(server.touch(promote, count, average_used_capacity));
      count = 3;
      promote = true;
      EXPECT_TRUE(server.touch(promote, count, average_used_capacity));
      EXPECT_EQ(3, count);
      average_used_capacity = 0xffffff;
      EXPECT_TRUE(server.touch(promote, count, average_used_capacity));
      EXPECT_EQ(3, count);

      for (int32_t i = 0; i < BLOCK_COUNT; ++i)
      {
        BlockCollect* block = layout_manager_.get_block_manager().get(100 + i);
        EXPECT_TRUE(NULL != block);
        block->add(writable, master, server2.id(), now);
        server2.add(block->id(), writable, master);
      }

      EXPECT_TRUE(server2.touch(promote, count, average_used_capacity));
      EXPECT_EQ(0, count);
      EXPECT_TRUE(server2.hold_master_->size() == 3);
      EXPECT_EQ(BLOCK_COUNT, server.hold_->size());
    }
Example #7
0
int main ()
{
   paxos::configuration configuration1;
   paxos::configuration configuration2;
   paxos::configuration configuration3;

   configuration1.durable_storage ().set_history_size (5);
   configuration2.durable_storage ().set_history_size (5);
   configuration3.durable_storage ().set_history_size (5);

   paxos::server::callback_type callback = 
      [](
         int64_t                promise_id,
         std::string const &    workload) -> std::string
      {
         return "bar";
      };

   paxos::client client;
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);
   paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);
   
   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   {
      paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
      server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
    
      /*!
        Issue 10 calls, so we can verify that the lowest proposal id is in fact 10.
       */
      for (size_t i = 0; i < 15; ++i)
      {
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
      }

      PAXOS_ASSERT_EQ (configuration1.durable_storage ().lowest_proposal_id (), 11);
      PAXOS_ASSERT_EQ (configuration2.durable_storage ().lowest_proposal_id (), 11);
      PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 11);
   }
   
   /*!
     Now, since one host in our quorum is currently down, logs should *not* be cleaned
     up further than the proposal that has been previously accepted by that host.
    */

   for (size_t i = 0; i < 30; ++i)
   {
      PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   }

   PAXOS_ASSERT_GE (configuration1.durable_storage ().lowest_proposal_id (), 15);
   PAXOS_ASSERT_GE (configuration2.durable_storage ().lowest_proposal_id (), 15);
   PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 11);

   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   {
      /*!
        And after our server is back online, the history can be cleared again.
       */

      paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
      server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
    
      for (size_t i = 0; i < 15; ++i)
      {
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
      }

      PAXOS_ASSERT_EQ (configuration1.durable_storage ().lowest_proposal_id (), 56);
      PAXOS_ASSERT_EQ (configuration2.durable_storage ().lowest_proposal_id (), 56);
      PAXOS_ASSERT_EQ (configuration3.durable_storage ().lowest_proposal_id (), 56);
   }


   
   PAXOS_INFO ("test succeeded");
}
Example #8
0
int main ()
{
   std::map <int64_t, uint16_t> responses;

   /*!
     Synchronizes access to responses
    */
   boost::mutex mutex;

   paxos::configuration configuration1;
   paxos::configuration configuration2;
   paxos::configuration configuration3;

   /*!
     Note that the configuration objects below outlive the server objects declared later in
     the test, thus providing semi-durable storage.
    */
   configuration1.set_durable_storage (
      new paxos::durable::heap ());
   configuration2.set_durable_storage (
      new paxos::durable::heap ());
   configuration3.set_durable_storage (
      new paxos::durable::heap ());

   paxos::server::callback_type callback = 
      [& responses,
       & mutex](
         int64_t                promise_id,
         std::string const &    workload) -> std::string
      {
         boost::mutex::scoped_lock lock (mutex);

         if (responses.find (promise_id) == responses.end ())
         {
            responses[promise_id] = 1;
         }
         else
         {
            responses[promise_id]++;
         }

         PAXOS_ASSERT (responses[promise_id] <= 3);

         return "bar";
      };

   paxos::client client;
   client.add  ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

   {
      paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);

      server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

      {
         paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);

         server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

         {
            paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);

            server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});

            PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
            PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
            PAXOS_ASSERT_EQ (all_responses_equal (responses, 3), true);
         }



         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
         PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
         PAXOS_ASSERT_EQ (all_responses_equal (responses, 3), false);
      }

      PAXOS_ASSERT_THROW (client.send ("foo").get (), paxos::exception::no_majority);
   }

   /*!
     Note that we're re-adding servers in reverse order here; this is to ensure that
     server3 doesn't become our leader while it's lagging behind.
    */
   paxos::server server3 ("127.0.0.1", 1339, callback, configuration3);
   server3.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   
   PAXOS_ASSERT_THROW (client.send ("foo").get (), paxos::exception::no_majority);

   paxos::server server2 ("127.0.0.1", 1338, callback, configuration2);
   server2.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});
   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");
   PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");

   paxos::server server1 ("127.0.0.1", 1337, callback, configuration1);
   server1.add ({{"127.0.0.1", 1337}, {"127.0.0.1", 1338}, {"127.0.0.1", 1339}});


   boost::this_thread::sleep (
      boost::posix_time::milliseconds (
         paxos::configuration ().timeout ()));

   do
   {
      PAXOS_ASSERT_EQ (client.send ("foo").get (), "bar");   
      
   } while (all_responses_equal (responses, 3) == false);

   PAXOS_INFO ("test succeeded");
}
Example #9
0
void minerRefuel(IMP)
{
    register Ship_t *rsh, *rp;
    ULONG shipNumber, mineNum;
    Ship_t saveShip;
    ULONG shEnergy, newEnergy;
    BOOL reduced;

    /* get the number of the miner */
    if (reqShip(IS, &mineNum, "Miner to refuel"))
    {
        rsh = &IS->is_request.rq_u.ru_ship;
        rp = &IS->is_request.rq_u.ru_shipPair[0];
        (void) skipBlanks(IS);
        reduced = FALSE;
        server(IS, rt_readShip, mineNum);
        if (rsh->sh_owner != IS->is_player.p_number)
        {
            err(IS, "you don't own that miner");
            return;
        }
        /* make sure the ship is a miner */
        if (rsh->sh_type != st_m)
        {
            err(IS, "that ship is not a miner");
            return;
        }
        /* make sure the ship is not on a planet */
        if (rsh->sh_planet != NO_ITEM)
        {
            err(IS, "miner is on the surface of a planet");
            return;
        }
        if (rsh->sh_dragger == NO_ITEM)
        {
            err(IS, "miner is not on a ship - alert system owner!");
            return;
        }
        shipNumber = rsh->sh_dragger;
        saveShip = *rsh;
        server(IS, rt_lockShip, shipNumber);
        updateShip(IS);
        server(IS, rt_unlockShip, shipNumber);
        if (rsh->sh_energy == 0)
        {
            err(IS, "the ship the miner is on has no energy");
            return;
        }
        shEnergy = umin(rsh->sh_energy, (USHORT) MAX_WORK - saveShip.sh_energy);
        if (shEnergy == 0)
        {
            err(IS, "the miner can not contain any more energy");
            return;
        }
        if (reqPosRange(IS, &newEnergy, shEnergy, "Transfer how many units"
            " of energy to the miner"))
        {
            server2(IS, rt_lockShipPair, mineNum, shipNumber);
            shEnergy = rp[1].sh_energy;
            if (shEnergy < newEnergy)
            {
                newEnergy = shEnergy;
                reduced = TRUE;
            }
            rp[0].sh_energy += newEnergy;
            rp[1].sh_energy -= newEnergy;
            server2(IS, rt_unlockShipPair, mineNum, shipNumber);
            if (reduced)
            {
                userN3(IS, "Actions have reduced the energy transfered to ",
                    newEnergy, " units\n");
            }
            else
            {
                userN3(IS, "Transfered ", newEnergy, " units\n");
            }
        }
        /* put out the dirty ship numbers */
        feShDirty(IS, mineNum);
        feShDirty(IS, shipNumber);
    }
}
Example #10
0
void minerEmpty(IMP)
{
    register Ship_t *rsh, *rp;
    ULONG shipNumber, mineNum;
    USHORT ore, bars;

    /* get the number of the miner */
    if (reqShip(IS, &mineNum, "Miner to empty"))
    {
        rsh = &IS->is_request.rq_u.ru_ship;
        rp = &IS->is_request.rq_u.ru_shipPair[0];
        (void) skipBlanks(IS);
        server(IS, rt_readShip, mineNum);
        if (rsh->sh_owner != IS->is_player.p_number)
        {
            err(IS, "you don't own that miner");
        }
        else if (rsh->sh_type != st_m)
        {
            err(IS, "that ship is not a miner");
        }
        /* make sure the ship is on a planet */
        else if (rsh->sh_planet != NO_ITEM)
        {
            err(IS, "miner is on the surface of a planet");
            return;
        }
        else
        {
            /* make sure the miner is in a ship */
            if (rsh->sh_dragger == NO_ITEM)
            {
                err(IS, "miner is not inside a ship - tell system owner!");
                return;
            }

            /* get the number of the ship the miner is on */
            shipNumber = rsh->sh_dragger;
            /* update the carrying ship */
            server(IS, rt_lockShip, shipNumber);
            updateShip(IS);
            server(IS, rt_unlockShip, shipNumber);

            /* now do the actual transfer */
            server2(IS, rt_lockShipPair, mineNum, shipNumber);
            /* get the maximum amount of ore that may be transfered */
            ore = umin(rp[0].sh_items[it_ore], (USHORT) MAX_WORK -
                rp[1].sh_items[it_ore]);
            /* remove that amount from the miner */
            rp[0].sh_items[it_ore] -= ore;
            /* get the maximum amount of bars that may be transfered */
            bars = umin(rp[0].sh_items[it_bars], (USHORT) MAX_WORK -
                rp[1].sh_items[it_bars]);
            /* remove that amount from the miner */
            rp[0].sh_items[it_bars] -= bars;
            /* now handle the weight */
            rp[0].sh_cargo -= (ore * IS->is_world.w_weight[it_ore]);
            rp[0].sh_cargo -= (bars * IS->is_world.w_weight[it_bars]);

            /* now put the items onto the carrying ship */
            rp[1].sh_items[it_ore] += ore;
            rp[1].sh_items[it_bars] += bars;
            server2(IS, rt_unlockShipPair, mineNum, shipNumber);

            /* see if we transfered anything */
            if ((ore == 0) && (bars == 0))
            {
                user(IS, "Unable to transfer anything from that miner\n");
            }
            else
            {
                userN3(IS, "Transfered ", ore, " units of ore ");
                userN3(IS, "and ", bars, " gold bars ");
                userN3(IS, "to ship ", shipNumber, "\n");
            }
            /* put out the dirty ship numbers */
            feShDirty(IS, mineNum);
            feShDirty(IS, shipNumber);
        }
    }
}