Search in sources :

Example 41 with InetSocketAddress

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) InetAddress(java.net.InetAddress) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with InetSocketAddress

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) InetAddress(java.net.InetAddress) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 43 with InetSocketAddress

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());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) RunOptions(org.apache.flink.client.cli.RunOptions) Test(org.junit.Test)

Example 44 with InetSocketAddress

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());
}
Also used : ClusterClient(org.apache.flink.client.program.ClusterClient) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) CliFrontend(org.apache.flink.client.CliFrontend) File(java.io.File) RunOptions(org.apache.flink.client.cli.RunOptions) FlinkYarnSessionCli(org.apache.flink.yarn.cli.FlinkYarnSessionCli) Test(org.junit.Test)

Example 45 with InetSocketAddress

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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Text(org.apache.hadoop.io.Text) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2586 Test (org.junit.Test)595 IOException (java.io.IOException)592 Socket (java.net.Socket)345 InetAddress (java.net.InetAddress)242 SocketAddress (java.net.SocketAddress)176 ServerSocket (java.net.ServerSocket)170 ArrayList (java.util.ArrayList)168 Configuration (org.apache.hadoop.conf.Configuration)140 ByteBuffer (java.nio.ByteBuffer)129 UnknownHostException (java.net.UnknownHostException)122 InputStream (java.io.InputStream)102 OutputStream (java.io.OutputStream)101 SocketChannel (java.nio.channels.SocketChannel)101 SocketException (java.net.SocketException)89 File (java.io.File)88 HashMap (java.util.HashMap)78 URI (java.net.URI)72 Proxy (java.net.Proxy)65 SocketTimeoutException (java.net.SocketTimeoutException)65