コード例 #1
0
public class NotifyingSchedulingFilterTest extends EasyMockTest {

  private static final ITaskConfig TASK =
      ITaskConfig.build(new TaskConfig().setNumCpus(1).setRamMb(1024).setDiskMb(1024));
  private static final TaskGroupKey GROUP_KEY = TaskGroupKey.from(TASK);
  private static final UnusedResource RESOURCE =
      new UnusedResource(
          ResourceSlot.from(TASK).withOverhead(TaskExecutors.NO_OVERHEAD_EXECUTOR),
          IHostAttributes.build(
              new HostAttributes().setHost("host").setMode(MaintenanceMode.NONE)));
  private static final ResourceRequest REQUEST =
      new ResourceRequest(TASK, AttributeAggregate.EMPTY);

  private static final Veto VETO_1 = Veto.insufficientResources("ram", 1);
  private static final Veto VETO_2 = Veto.insufficientResources("ram", 2);

  private SchedulingFilter filter;
  private EventSink eventSink;
  private SchedulingFilter delegate;

  @Before
  public void setUp() {
    delegate = createMock(SchedulingFilter.class);
    eventSink = createMock(EventSink.class);
    filter = new NotifyingSchedulingFilter(delegate, eventSink);
  }

  @Test
  public void testEvents() {
    Set<Veto> vetoes = ImmutableSet.of(VETO_1, VETO_2);
    expect(delegate.filter(RESOURCE, REQUEST)).andReturn(vetoes);
    eventSink.post(new Vetoed(GROUP_KEY, vetoes));

    control.replay();

    assertEquals(vetoes, filter.filter(RESOURCE, REQUEST));
  }

  @Test
  public void testNoVetoes() {
    Set<Veto> vetoes = ImmutableSet.of();
    expect(delegate.filter(RESOURCE, REQUEST)).andReturn(vetoes);

    control.replay();

    assertEquals(vetoes, filter.filter(RESOURCE, REQUEST));
  }
}
コード例 #2
0
  @Test
  public void testVetoGroups() {
    control.replay();

    assertEquals(VetoGroup.EMPTY, Veto.identifyGroup(ImmutableSet.of()));

    assertEquals(
        VetoGroup.STATIC,
        Veto.identifyGroup(
            ImmutableSet.of(
                Veto.constraintMismatch("denied"),
                Veto.insufficientResources("ram", 100),
                Veto.maintenance("draining"))));

    assertEquals(
        VetoGroup.DYNAMIC, Veto.identifyGroup(ImmutableSet.of(Veto.unsatisfiedLimit("denied"))));

    assertEquals(
        VetoGroup.MIXED,
        Veto.identifyGroup(
            ImmutableSet.of(
                Veto.insufficientResources("ram", 100), Veto.unsatisfiedLimit("denied"))));
  }