Search in sources :

Example 6 with AllocatedEvaluator

use of org.apache.reef.driver.evaluator.AllocatedEvaluator in project heron by twitter.

the class HeronMasterDriverTest method fitBiggestContainerIgnoresCoresIfMissing.

@Test
public void fitBiggestContainerIgnoresCoresIfMissing() {
    Set<HeronMasterDriver.HeronWorker> workers = new HashSet<>();
    workers.add(new HeronMasterDriver.HeronWorker(1, 3, ByteAmount.fromGigabytes(3)));
    AllocatedEvaluator mockEvaluator = createMockEvaluator("test", 1, ByteAmount.fromGigabytes(3));
    Optional<HeronMasterDriver.HeronWorker> result = spyDriver.findLargestFittingWorker(mockEvaluator, workers, false);
    Assert.assertFalse(result.isPresent());
    result = spyDriver.findLargestFittingWorker(mockEvaluator, workers, true);
    assertTrue(result.isPresent());
    assertEquals(1, result.get().getWorkerId());
}
Also used : HashSet(java.util.HashSet) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with AllocatedEvaluator

use of org.apache.reef.driver.evaluator.AllocatedEvaluator in project heron by twitter.

the class HeronMasterDriverTest method onNextAllocatedEvaluatorDiscardsExtraWorker.

@Test
public void onNextAllocatedEvaluatorDiscardsExtraWorker() throws Exception {
    AllocatedEvaluator mockEvaluator = createMockEvaluator("test", 1, ByteAmount.fromMegabytes(123));
    assertFalse(spyDriver.lookupByEvaluatorId("test").isPresent());
    spyDriver.new ContainerAllocationHandler().onNext(mockEvaluator);
    assertFalse(spyDriver.lookupByEvaluatorId("test").isPresent());
    verify(mockEvaluator, never()).submitContext(any(Configuration.class));
}
Also used : Configuration(org.apache.reef.tang.Configuration) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with AllocatedEvaluator

use of org.apache.reef.driver.evaluator.AllocatedEvaluator in project heron by twitter.

the class HeronMasterDriverTest method verifyFittingContainer.

private void verifyFittingContainer(Set<HeronMasterDriver.HeronWorker> containers, int ram, int cores, int expectedContainer) {
    EvaluatorDescriptor evaluatorDescriptor = mock(EvaluatorDescriptor.class);
    AllocatedEvaluator mockEvaluator = mock(AllocatedEvaluator.class);
    when(mockEvaluator.getEvaluatorDescriptor()).thenReturn(evaluatorDescriptor);
    when(evaluatorDescriptor.getMemory()).thenReturn(ram);
    when(evaluatorDescriptor.getNumberOfCores()).thenReturn(cores);
    Optional<HeronMasterDriver.HeronWorker> worker = spyDriver.findLargestFittingWorker(mockEvaluator, containers, false);
    assertTrue(worker.isPresent());
    assertEquals(expectedContainer, worker.get().getWorkerId());
}
Also used : EvaluatorDescriptor(org.apache.reef.driver.evaluator.EvaluatorDescriptor) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator)

Example 9 with AllocatedEvaluator

use of org.apache.reef.driver.evaluator.AllocatedEvaluator in project heron by twitter.

the class HeronMasterDriverTest method onNextFailedEvaluatorRestartsContainer.

@Test
public void onNextFailedEvaluatorRestartsContainer() throws Exception {
    int numContainers = 3;
    AllocatedEvaluator[] mockEvaluators = createApplicationWithContainers(numContainers);
    FailedEvaluator mockFailedContainer = mock(FailedEvaluator.class);
    when(mockFailedContainer.getId()).thenReturn("e1");
    verify(spyDriver, never()).requestContainerForWorker(anyInt(), anyHeronWorker());
    spyDriver.new FailedContainerHandler().onNext(mockFailedContainer);
    for (int id = 0; id < numContainers; id++) {
        if (id == 1) {
            verify(spyDriver, times(1)).requestContainerForWorker(eq(id), anyHeronWorker());
            assertFalse(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
            continue;
        }
        verify(mockEvaluators[id], never()).close();
        assertEquals(Integer.valueOf(id), spyDriver.lookupByEvaluatorId("e" + id).get());
    }
}
Also used : FailedEvaluator(org.apache.reef.driver.evaluator.FailedEvaluator) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with AllocatedEvaluator

use of org.apache.reef.driver.evaluator.AllocatedEvaluator in project heron by twitter.

the class HeronMasterDriverTest method killWorkersTerminatesSpecificContainers.

@Test
public void killWorkersTerminatesSpecificContainers() throws Exception {
    int numContainers = 5;
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    for (int id = 0; id < numContainers; id++) {
        containers.add(PackingTestUtils.testContainerPlan(id));
    }
    PackingPlan packingPlan = new PackingPlan("packing", containers);
    spyDriver.scheduleHeronWorkers(packingPlan);
    for (int id = 0; id < numContainers; id++) {
        verify(spyDriver, times(1)).requestContainerForWorker(eq(id), anyHeronWorker());
        assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
    }
    verify(mockRequestor, times(numContainers)).submit(any(EvaluatorRequest.class));
    AllocatedEvaluator[] mockEvaluators = createApplicationWithContainers(numContainers);
    Set<PackingPlan.ContainerPlan> containersTobeDeleted = new HashSet<>();
    containersTobeDeleted.add(PackingTestUtils.testContainerPlan(2));
    containersTobeDeleted.add(PackingTestUtils.testContainerPlan(3));
    spyDriver.killWorkers(containersTobeDeleted);
    for (int id = 0; id < numContainers; id++) {
        if (id == 2 || id == 3) {
            verify(mockEvaluators[id], times(1)).close();
            assertFalse(spyDriver.lookupByContainerPlan(id).isPresent());
            assertFalse(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
            continue;
        }
        verify(mockEvaluators[id], never()).close();
        assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
        assertTrue(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
    }
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AllocatedEvaluator (org.apache.reef.driver.evaluator.AllocatedEvaluator)11 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 HashSet (java.util.HashSet)3 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)2 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)2 EvaluatorDescriptor (org.apache.reef.driver.evaluator.EvaluatorDescriptor)2 Configuration (org.apache.reef.tang.Configuration)2 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)1 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)1 FailedEvaluator (org.apache.reef.driver.evaluator.FailedEvaluator)1