@Test
  public void testScheduleWithDyingInstances() {
    try {
      Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());

      Instance i1 = getRandomInstance(2);
      Instance i2 = getRandomInstance(2);
      Instance i3 = getRandomInstance(1);

      scheduler.newInstanceAvailable(i1);
      scheduler.newInstanceAvailable(i2);
      scheduler.newInstanceAvailable(i3);

      List<SimpleSlot> slots = new ArrayList<SimpleSlot>();
      slots.add(scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get());
      slots.add(scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get());
      slots.add(scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get());
      slots.add(scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get());
      slots.add(scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get());

      i2.markDead();

      for (SimpleSlot slot : slots) {
        if (slot.getOwner() == i2) {
          assertTrue(slot.isCanceled());
        } else {
          assertFalse(slot.isCanceled());
        }

        slot.releaseSlot();
      }

      assertEquals(3, scheduler.getNumberOfAvailableSlots());

      i1.markDead();
      i3.markDead();

      // cannot get another slot, since all instances are dead
      try {
        scheduler.allocateSlot(new ScheduledUnit(getDummyTask()), false).get();
        fail("Scheduler served a slot from a dead instance");
      } catch (NoResourceAvailableException e) {
        // fine
      } catch (Exception e) {
        fail("Wrong exception type.");
      }

      // now the latest, the scheduler should have noticed (through the lazy mechanisms)
      // that all instances have vanished
      assertEquals(0, scheduler.getNumberOfInstancesWithAvailableSlots());
      assertEquals(0, scheduler.getNumberOfAvailableSlots());
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Exemplo n.º 2
0
  @Test
  public void testInstanceDies() {
    try {
      ResourceID resourceID = ResourceID.generate();
      HardwareDescription hardwareDescription =
          new HardwareDescription(
              4, 2L * 1024 * 1024 * 1024, 1024 * 1024 * 1024, 512 * 1024 * 1024);
      InetAddress address = InetAddress.getByName("127.0.0.1");
      TaskManagerLocation connection = new TaskManagerLocation(resourceID, address, 10001);

      Instance instance =
          new Instance(
              new ActorTaskManagerGateway(DummyActorGateway.INSTANCE),
              connection,
              new InstanceID(),
              hardwareDescription,
              3);

      assertEquals(3, instance.getNumberOfAvailableSlots());

      SimpleSlot slot1 = instance.allocateSimpleSlot(new JobID());
      SimpleSlot slot2 = instance.allocateSimpleSlot(new JobID());
      SimpleSlot slot3 = instance.allocateSimpleSlot(new JobID());

      instance.markDead();

      assertEquals(0, instance.getNumberOfAllocatedSlots());
      assertEquals(0, instance.getNumberOfAvailableSlots());

      assertTrue(slot1.isCanceled());
      assertTrue(slot2.isCanceled());
      assertTrue(slot3.isCanceled());
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }