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

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

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

      // schedule something on an arbitrary instance
      SimpleSlot s1 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(new Instance[0])), false).get();

      // figure out how we use the location hints
      Instance first = (Instance) s1.getOwner();
      Instance second = first != i1 ? i1 : i2;
      Instance third = first == i3 ? i2 : i3;

      // something that needs to go to the first instance again
      SimpleSlot s2 =
          scheduler
              .allocateSlot(new ScheduledUnit(getTestVertex(s1.getTaskManagerLocation())), false)
              .get();
      assertEquals(first, s2.getOwner());

      // first or second --> second, because first is full
      SimpleSlot s3 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(first, second)), false).get();
      assertEquals(second, s3.getOwner());

      // first or third --> third (because first is full)
      SimpleSlot s4 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(first, third)), false).get();
      SimpleSlot s5 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(first, third)), false).get();
      assertEquals(third, s4.getOwner());
      assertEquals(third, s5.getOwner());

      // first or third --> second, because all others are full
      SimpleSlot s6 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(first, third)), false).get();
      assertEquals(second, s6.getOwner());

      // release something on the first and second instance
      s2.releaseSlot();
      s6.releaseSlot();

      SimpleSlot s7 =
          scheduler.allocateSlot(new ScheduledUnit(getTestVertex(first, third)), false).get();
      assertEquals(first, s7.getOwner());

      assertEquals(1, scheduler.getNumberOfUnconstrainedAssignments());
      assertEquals(1, scheduler.getNumberOfNonLocalizedAssignments());
      assertEquals(5, scheduler.getNumberOfLocalizedAssignments());
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }