use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class ExecutionVertexLocalityTest method testNoLocalityInputLargeAllToAll.
/**
* This test validates that vertices with too many input streams do not have a location
* preference any more.
*/
@Test
public void testNoLocalityInputLargeAllToAll() throws Exception {
final int parallelism = 100;
final ExecutionGraph graph = createTestGraph(parallelism, true);
// set the location for all sources to a distinct location
for (int i = 0; i < parallelism; i++) {
ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
TaskManagerLocation location = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 10000 + i);
initializeLocation(source, location);
}
// validate that the target vertices have no location preference
for (int i = 0; i < parallelism; i++) {
ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
Iterator<TaskManagerLocation> preference = target.getPreferredLocations().iterator();
assertFalse(preference.hasNext());
}
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class ExecutionVertexLocalityTest method testLocalityBasedOnState.
/**
* This test validates that stateful vertices schedule based in the state's location
* (which is the prior execution's location).
*/
@Test
public void testLocalityBasedOnState() throws Exception {
final int parallelism = 10;
final TaskManagerLocation[] locations = new TaskManagerLocation[parallelism];
final ExecutionGraph graph = createTestGraph(parallelism, false);
// set the location for all sources and targets
for (int i = 0; i < parallelism; i++) {
ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
TaskManagerLocation randomLocation = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 10000 + i);
TaskManagerLocation location = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 20000 + i);
locations[i] = location;
initializeLocation(source, randomLocation);
initializeLocation(target, location);
setState(source.getCurrentExecutionAttempt(), ExecutionState.CANCELED);
setState(target.getCurrentExecutionAttempt(), ExecutionState.CANCELED);
}
// mimic a restart: all vertices get re-initialized without actually being executed
for (ExecutionJobVertex ejv : graph.getVerticesTopologically()) {
ejv.resetForNewExecution();
}
// set new location for the sources and some state for the targets
for (int i = 0; i < parallelism; i++) {
// source location
ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
TaskManagerLocation randomLocation = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 30000 + i);
initializeLocation(source, randomLocation);
// target state
ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
target.getCurrentExecutionAttempt().setInitialState(mock(TaskStateHandles.class));
}
// validate that the target vertices have the state's location as the location preference
for (int i = 0; i < parallelism; i++) {
ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
Iterator<TaskManagerLocation> preference = target.getPreferredLocations().iterator();
assertTrue(preference.hasNext());
assertEquals(locations[i], preference.next());
assertFalse(preference.hasNext());
}
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class AvailableSlotsTest method createAllocatedSlot.
static AllocatedSlot createAllocatedSlot(final ResourceID resourceId) {
TaskManagerLocation mockTaskManagerLocation = mock(TaskManagerLocation.class);
when(mockTaskManagerLocation.getResourceID()).thenReturn(resourceId);
TaskManagerGateway mockTaskManagerGateway = mock(TaskManagerGateway.class);
return new AllocatedSlot(new AllocationID(), new JobID(), mockTaskManagerLocation, 0, DEFAULT_TESTING_PROFILE, mockTaskManagerGateway);
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class InstanceManagerTest method testInstanceRegistering.
@Test
public void testInstanceRegistering() {
try {
InstanceManager cm = new InstanceManager();
final int dataPort = 20000;
HardwareDescription hardwareDescription = HardwareDescription.extractFromSystem(4096);
InetAddress address = InetAddress.getByName("127.0.0.1");
// register three instances
ResourceID resID1 = ResourceID.generate();
ResourceID resID2 = ResourceID.generate();
ResourceID resID3 = ResourceID.generate();
TaskManagerLocation ici1 = new TaskManagerLocation(resID1, address, dataPort);
TaskManagerLocation ici2 = new TaskManagerLocation(resID2, address, dataPort + 15);
TaskManagerLocation ici3 = new TaskManagerLocation(resID3, address, dataPort + 30);
final JavaTestKit probe1 = new JavaTestKit(system);
final JavaTestKit probe2 = new JavaTestKit(system);
final JavaTestKit probe3 = new JavaTestKit(system);
cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe1.getRef(), leaderSessionID)), ici1, hardwareDescription, 1);
cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe2.getRef(), leaderSessionID)), ici2, hardwareDescription, 2);
cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe3.getRef(), leaderSessionID)), ici3, hardwareDescription, 5);
assertEquals(3, cm.getNumberOfRegisteredTaskManagers());
assertEquals(8, cm.getTotalNumberOfSlots());
Collection<Instance> instances = cm.getAllRegisteredInstances();
Set<TaskManagerLocation> taskManagerLocations = new HashSet<TaskManagerLocation>();
for (Instance instance : instances) {
taskManagerLocations.add(instance.getTaskManagerLocation());
}
assertTrue(taskManagerLocations.contains(ici1));
assertTrue(taskManagerLocations.contains(ici2));
assertTrue(taskManagerLocations.contains(ici3));
cm.shutdown();
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
Assert.fail("Test erroneous: " + e.getMessage());
}
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class InstanceManagerTest method testShutdown.
@Test
public void testShutdown() {
try {
InstanceManager cm = new InstanceManager();
cm.shutdown();
try {
ResourceID resID = ResourceID.generate();
HardwareDescription resources = HardwareDescription.extractFromSystem(4096);
InetAddress address = InetAddress.getByName("127.0.0.1");
TaskManagerLocation ici = new TaskManagerLocation(resID, address, 20000);
JavaTestKit probe = new JavaTestKit(system);
cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe.getRef(), leaderSessionID)), ici, resources, 1);
fail("Should raise exception in shutdown state");
} catch (IllegalStateException e) {
// expected
}
assertFalse(cm.reportHeartBeat(new InstanceID()));
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
Assert.fail("Test erroneous: " + e.getMessage());
}
}
Aggregations