Search in sources :

Example 26 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class InstanceTest method testInstanceDies.

@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());
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) InetAddress(java.net.InetAddress) JobID(org.apache.flink.api.common.JobID) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Example 27 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotPoolTest method testAllocationFulfilledByReturnedSlot.

@Test
public void testAllocationFulfilledByReturnedSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future1 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    Future<SimpleSlot> future2 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future1.isDone());
    assertFalse(future2.isDone());
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway, times(2)).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final List<SlotRequest> slotRequests = slotRequestArgumentCaptor.getAllValues();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequests.get(0).getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot1 = future1.get(1, TimeUnit.SECONDS);
    assertTrue(future1.isDone());
    assertFalse(future2.isDone());
    // return this slot to pool
    slot1.releaseSlot();
    // second allocation fulfilled by previous slot returning
    SimpleSlot slot2 = future2.get(1, TimeUnit.SECONDS);
    assertTrue(future2.isDone());
    assertNotEquals(slot1, slot2);
    assertTrue(slot1.isReleased());
    assertTrue(slot2.isAlive());
    assertEquals(slot1.getTaskManagerID(), slot2.getTaskManagerID());
    assertEquals(slot1.getSlotNumber(), slot2.getSlotNumber());
    assertEquals(slotPool.getAllocatedSlots().get(slot1.getAllocatedSlot().getSlotAllocationId()), slot2);
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) Time(org.apache.flink.api.common.time.Time) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotPoolTest method testOfferSlot.

@Test
public void testOfferSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future.isDone());
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final SlotRequest slotRequest = slotRequestArgumentCaptor.getValue();
    // slot from unregistered resource
    AllocatedSlot invalid = createAllocatedSlot(new ResourceID("unregistered"), slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertFalse(slotPool.offerSlot(invalid));
    AllocatedSlot notRequested = createAllocatedSlot(resourceID, new AllocationID(), jobId, DEFAULT_TESTING_PROFILE);
    // we'll also accept non requested slots
    assertTrue(slotPool.offerSlot(notRequested));
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    // accepted slot
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot = future.get(1, TimeUnit.SECONDS);
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    // duplicated offer with using slot
    assertTrue(slotPool.offerSlot(allocatedSlot));
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    // duplicated offer with free slot
    slot.releaseSlot();
    assertTrue(slot.isReleased());
    assertTrue(slotPool.offerSlot(allocatedSlot));
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) Time(org.apache.flink.api.common.time.Time) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) UUID(java.util.UUID) Test(org.junit.Test)

Example 29 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotPoolTest method testAllocateWithFreeSlot.

@Test
public void testAllocateWithFreeSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future1 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future1.isDone());
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final SlotRequest slotRequest = slotRequestArgumentCaptor.getValue();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot1 = future1.get(1, TimeUnit.SECONDS);
    assertTrue(future1.isDone());
    // return this slot to pool
    slot1.releaseSlot();
    Future<SimpleSlot> future2 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    // second allocation fulfilled by previous slot returning
    SimpleSlot slot2 = future2.get(1, TimeUnit.SECONDS);
    assertTrue(future2.isDone());
    assertNotEquals(slot1, slot2);
    assertTrue(slot1.isReleased());
    assertTrue(slot2.isAlive());
    assertEquals(slot1.getTaskManagerID(), slot2.getTaskManagerID());
    assertEquals(slot1.getSlotNumber(), slot2.getSlotNumber());
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) Time(org.apache.flink.api.common.time.Time) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) UUID(java.util.UUID) Test(org.junit.Test)

Example 30 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotPoolTest method testAllocateSimpleSlot.

@Test
public void testAllocateSimpleSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    ScheduledUnit task = mock(ScheduledUnit.class);
    Future<SimpleSlot> future = slotPool.allocateSlot(task, DEFAULT_TESTING_PROFILE, null);
    assertFalse(future.isDone());
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final SlotRequest slotRequest = slotRequestArgumentCaptor.getValue();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot = future.get(1, TimeUnit.SECONDS);
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    assertEquals(resourceID, slot.getTaskManagerID());
    assertEquals(jobId, slot.getJobID());
    assertEquals(slotPool.getSlotOwner(), slot.getOwner());
    assertEquals(slotPool.getAllocatedSlots().get(slot.getAllocatedSlot().getSlotAllocationId()), slot);
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) Time(org.apache.flink.api.common.time.Time) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)74 Test (org.junit.Test)48 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)25 Time (org.apache.flink.api.common.time.Time)18 UUID (java.util.UUID)16 JobID (org.apache.flink.api.common.JobID)16 Configuration (org.apache.flink.configuration.Configuration)14 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)13 JavaTestKit (akka.testkit.JavaTestKit)12 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)12 InetAddress (java.net.InetAddress)11 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)10 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)10 TestingHighAvailabilityServices (org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices)10 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)10 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)9 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)9 ActorTaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway)9 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)9 TestingSerialRpcService (org.apache.flink.runtime.rpc.TestingSerialRpcService)9