use of java.net.InetSocketAddress 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.InetSocketAddress 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.InetSocketAddress in project flink by apache.
the class CliFrontendYarnAddressConfigurationTest method testManualOptionsOverridesYarn.
@Test
public void testManualOptionsOverridesYarn() throws Exception {
File emptyFolder = temporaryFolder.newFolder();
File testConfFile = new File(emptyFolder.getAbsolutePath(), "flink-conf.yaml");
Files.createFile(testConfFile.toPath());
TestCLI frontend = new TestCLI(emptyFolder.getAbsolutePath());
RunOptions options = CliFrontendParser.parseRunCommand(new String[] { "-m", "10.221.130.22:7788" });
frontend.retrieveClient(options);
Configuration config = frontend.getConfiguration();
InetSocketAddress expectedAddress = InetSocketAddress.createUnresolved("10.221.130.22", 7788);
checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
}
use of java.net.InetSocketAddress in project flink by apache.
the class FlinkYarnSessionCliTest method testCorrectSettingOfMaxSlots.
@Test
public void testCorrectSettingOfMaxSlots() throws Exception {
File confFile = tmp.newFile("flink-conf.yaml");
File jarFile = tmp.newFile("test.jar");
new CliFrontend(tmp.getRoot().getAbsolutePath());
String[] params = new String[] { "-yn", "2", "-ys", "3", jarFile.getAbsolutePath() };
RunOptions runOptions = CliFrontendParser.parseRunCommand(params);
FlinkYarnSessionCli yarnCLI = new TestCLI("y", "yarn");
AbstractYarnClusterDescriptor descriptor = yarnCLI.createDescriptor("", runOptions.getCommandLine());
// each task manager has 3 slots but the parallelism is 7. Thus the slots should be increased.
Assert.assertEquals(3, descriptor.getTaskManagerSlots());
Assert.assertEquals(2, descriptor.getTaskManagerCount());
Configuration config = new Configuration();
CliFrontend.setJobManagerAddressInConfig(config, new InetSocketAddress("test", 9000));
ClusterClient client = new TestingYarnClusterClient(descriptor, config);
Assert.assertEquals(6, client.getMaxSlots());
}
use of java.net.InetSocketAddress in project hadoop by apache.
the class KMSClientProvider method getDelegationTokenService.
private Text getDelegationTokenService() throws IOException {
URL url = new URL(kmsUrl);
InetSocketAddress addr = new InetSocketAddress(url.getHost(), url.getPort());
Text dtService = SecurityUtil.buildTokenService(addr);
return dtService;
}
Aggregations