Search in sources :

Example 81 with InetSocketAddress

use of java.net.InetSocketAddress in project hadoop by apache.

the class TestRPC method testServerAddress.

@Test
public void testServerAddress() throws IOException {
    Server server;
    server = setupTestServer(conf, 5);
    try {
        InetSocketAddress bindAddr = NetUtils.getConnectAddress(server);
        assertEquals(InetAddress.getLocalHost(), bindAddr.getAddress());
    } finally {
        stop(server, null);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 82 with InetSocketAddress

use of java.net.InetSocketAddress in project hadoop by apache.

the class TestIPC method testIpcConnectTimeout.

@Test(timeout = 60000)
public void testIpcConnectTimeout() throws IOException {
    // start server
    Server server = new TestServer(1, true);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    //Intentionally do not start server to get a connection timeout
    // start client
    Client.setConnectTimeout(conf, 100);
    Client client = new Client(LongWritable.class, conf);
    // set the rpc timeout to twice the MIN_SLEEP_TIME
    try {
        call(client, new LongWritable(RANDOM.nextLong()), addr, MIN_SLEEP_TIME * 2, conf);
        fail("Expected an exception to have been thrown");
    } catch (SocketTimeoutException e) {
        LOG.info("Get a SocketTimeoutException ", e);
    }
    client.stop();
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Example 83 with InetSocketAddress

use of java.net.InetSocketAddress in project hadoop by apache.

the class TestIPC method testIpcAfterStopping.

@Test(timeout = 30000, expected = IOException.class)
public void testIpcAfterStopping() throws IOException {
    // start server
    Server server = new TestServer(5, false);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();
    // start client
    Client client = new Client(LongWritable.class, conf);
    call(client, addr, 0, conf);
    client.stop();
    // This call should throw IOException.
    call(client, addr, 0, conf);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 84 with InetSocketAddress

use of java.net.InetSocketAddress in project hadoop by apache.

the class TestIPC method testIpcWithServiceClass.

/**
   * Check service class byte in IPC header is correct on wire.
   */
@Test(timeout = 60000)
public void testIpcWithServiceClass() throws IOException {
    // start server
    Server server = new TestServer(5, false);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();
    // start client
    Client.setConnectTimeout(conf, 10000);
    callAndVerify(server, addr, 0, true);
    // Service Class is low to -128 as byte on wire.
    // -128 shouldn't be casted on wire but -129 should.
    callAndVerify(server, addr, -128, true);
    callAndVerify(server, addr, -129, false);
    // Service Class is up to 127.
    // 127 shouldn't be casted on wire but 128 should.
    callAndVerify(server, addr, 127, true);
    callAndVerify(server, addr, 128, false);
    server.stop();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 85 with InetSocketAddress

use of java.net.InetSocketAddress in project hadoop by apache.

the class TestIPC method testInitialCallRetryCount.

/**
   * Test if the rpc server gets the default retry count (0) from client.
   */
@Test(timeout = 60000)
public void testInitialCallRetryCount() throws IOException {
    // Override client to store the call id
    final Client client = new Client(LongWritable.class, conf);
    // Attach a listener that tracks every call ID received by the server.
    final TestServer server = new TestServer(1, false);
    server.callListener = new Runnable() {

        @Override
        public void run() {
            // we have not set the retry count for the client, thus on the server
            // side we should see retry count as 0
            Assert.assertEquals(0, Server.getCallRetryCount());
        }
    };
    try {
        InetSocketAddress addr = NetUtils.getConnectAddress(server);
        server.start();
        final SerialCaller caller = new SerialCaller(client, addr, 10);
        caller.run();
        assertFalse(caller.failed);
    } finally {
        client.stop();
        server.stop();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

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