use of java.net.InetAddress in project flink by apache.
the class ConnectionUtilsTest method testReturnLocalHostAddressUsingHeuristics.
@Test
public void testReturnLocalHostAddressUsingHeuristics() throws Exception {
try (ServerSocket blocker = new ServerSocket(0, 1, InetAddress.getLocalHost())) {
// the "blocker" server socket simply does not accept connections
// this address is consequently "unreachable"
InetSocketAddress unreachable = new InetSocketAddress("localhost", blocker.getLocalPort());
final long start = System.nanoTime();
InetAddress add = ConnectionUtils.findConnectingAddress(unreachable, 2000, 400);
// check that it did not take forever (max 30 seconds)
// this check can unfortunately not be too tight, or it will be flaky on some CI infrastructure
assertTrue(System.nanoTime() - start < 30_000_000_000L);
// we should have found a heuristic address
assertNotNull(add);
// make sure that we returned the InetAddress.getLocalHost as a heuristic
assertEquals(InetAddress.getLocalHost(), add);
}
}
use of java.net.InetAddress in project flink by apache.
the class ConnectionUtilsTest method testFindConnectingAddressWhenGetLocalHostThrows.
@Test
public void testFindConnectingAddressWhenGetLocalHostThrows() throws Exception {
PowerMockito.mockStatic(InetAddress.class);
Mockito.when(InetAddress.getLocalHost()).thenThrow(new UnknownHostException()).thenCallRealMethod();
final InetAddress loopbackAddress = Inet4Address.getByName("127.0.0.1");
Thread socketServerThread;
try (ServerSocket socket = new ServerSocket(0, 1, loopbackAddress)) {
// Make sure that the thread will eventually die even if something else goes wrong
socket.setSoTimeout(10_000);
socketServerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
socket.accept();
} catch (IOException e) {
// ignore
}
}
});
socketServerThread.start();
final InetSocketAddress socketAddress = new InetSocketAddress(loopbackAddress, socket.getLocalPort());
final InetAddress address = ConnectionUtils.findConnectingAddress(socketAddress, 2000, 400);
PowerMockito.verifyStatic();
// Make sure we got an address via alternative means
assertNotNull(address);
}
}
use of java.net.InetAddress 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 java.net.InetAddress 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());
}
}
use of java.net.InetAddress in project flink by apache.
the class ExecutionGraphTestUtils method getInstance.
public static Instance getInstance(final TaskManagerGateway gateway, final int numberOfSlots) throws Exception {
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);
return new Instance(gateway, connection, new InstanceID(), hardwareDescription, numberOfSlots);
}
Aggregations