src/tests/slave_tests.cpp
TEST_F(SlaveTest, Shutdown)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);

  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
  ASSERT_SOME(slave);

  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, 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_EQ(1u, offers.get().size());

  Future<Nothing> offerRescinded;
  EXPECT_CALL(sched, offerRescinded(&driver, offers.get()[0].id()))
    .WillOnce(FutureSatisfy(&offerRescinded));

  Future<Nothing> slaveLost;
  EXPECT_CALL(sched, slaveLost(&driver, offers.get()[0].slave_id()))
    .WillOnce(FutureSatisfy(&slaveLost));

  // Stop the slave with explicit shutdown message so that the slave
  // unregisters.
  slave.get()->shutdown();
  slave->reset();

  AWAIT_READY(offerRescinded);
  AWAIT_READY(slaveLost);

  JSON::Object stats = Metrics();
  EXPECT_EQ(1, stats.values["master/slave_removals"]);
  EXPECT_EQ(1, stats.values["master/slave_removals/reason_unregistered"]);

  driver.stop();
  driver.join();
}
// This test ensures that when a slave shuts itself down, it
// unregisters itself and the master notifies the framework
// immediately and rescinds any offers.
This test ensures that when a slave shuts itself down, it
unregisters itself and the master notifies the framework
immediately and rescinds any offers.
This test ensures that when a slave shuts itself down it unregisters itself and the master notifies the framework immediately and rescinds any offers .
TEST_F(SlaveTest, Shutdown)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
  ASSERT_SOME(slave);
  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
  EXPECT_CALL(sched, registered(&driver, _, _));
  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); 
  driver.start();
  AWAIT_READY(offers);
  EXPECT_EQ(1u, offers.get().size());
  Future<Nothing> offerRescinded;
  EXPECT_CALL(sched, offerRescinded(&driver, offers.get()[0].id()))
    .WillOnce(FutureSatisfy(&offerRescinded));
  Future<Nothing> slaveLost;
  EXPECT_CALL(sched, slaveLost(&driver, offers.get()[0].slave_id()))
    .WillOnce(FutureSatisfy(&slaveLost));
  slave.get()->shutdown();
  slave->reset();
  AWAIT_READY(offerRescinded);
  AWAIT_READY(slaveLost);
  JSON::Object stats = Metrics();
  EXPECT_EQ(1, stats.values["master/slave_removals"]);
  EXPECT_EQ(1, stats.values["master/slave_removals/reason_unregistered"]);
  driver.stop();
  driver.join();
}
TEST_F ( SlaveTest , Shutdown ) { Try < Owned < cluster :: Master > > master = StartMaster ( ) ; ASSERT_SOME ( master ) ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) ) ; ASSERT_SOME ( slave ) ; MockScheduler sched ; MesosSchedulerDriver driver ( & sched , DEFAULT_FRAMEWORK_INFO , master . get ( ) -> pid , DEFAULT_CREDENTIAL ) ; EXPECT_CALL ( sched , registered ( & driver , _ , _ ) ) ; Future < vector < Offer > > offers ; EXPECT_CALL ( sched , resourceOffers ( & driver , _ ) ) . WillOnce ( FutureArg < 1 > ( & offers ) ) . WillRepeatedly ( Return ( ) ) ; driver . start ( ) ; AWAIT_READY ( offers ) ; EXPECT_EQ ( 1u , offers . get ( ) . size ( ) ) ; Future < Nothing > offerRescinded ; EXPECT_CALL ( sched , offerRescinded ( & driver , offers . get ( ) [ 0 ] . id ( ) ) ) . WillOnce ( FutureSatisfy ( & offerRescinded ) ) ; Future < Nothing > slaveLost ; EXPECT_CALL ( sched , slaveLost ( & driver , offers . get ( ) [ 0 ] . slave_id ( ) ) ) . WillOnce ( FutureSatisfy ( & slaveLost ) ) ; slave . get ( ) -> shutdown ( ) ; slave -> reset ( ) ; AWAIT_READY ( offerRescinded ) ; AWAIT_READY ( slaveLost ) ; JSON :: Object stats = Metrics ( ) ; EXPECT_EQ ( 1 , stats . values [ " " ] ) ; EXPECT_EQ ( 1 , stats . values [ " " ] ) ; driver . stop ( ) ; driver . join ( ) ; }
This test ensures that when a slave shuts itself down, it
unregisters itself and the master notifies the framework
immediately and rescinds any offers.
This test ensures that when a slave shuts itself down it unregisters itself and the master notifies the framework immediately and rescinds any offers .
// Ignore subsequent offers. // Stop the slave with explicit shutdown message so that the slave // unregisters.