Search in sources :

Example 36 with SocketTimeoutException

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

the class TestDFSClientRetries method testClientDNProtocolTimeout.

/** Test that timeout occurs when DN does not respond to RPC.
   * Start up a server and ask it to sleep for n seconds. Make an
   * RPC to the server and set rpcTimeout to less than n and ensure
   * that socketTimeoutException is obtained
   */
@Test
public void testClientDNProtocolTimeout() throws IOException {
    final Server server = new TestServer(1, true);
    server.start();
    final InetSocketAddress addr = NetUtils.getConnectAddress(server);
    DatanodeID fakeDnId = DFSTestUtil.getLocalDatanodeID(addr.getPort());
    ExtendedBlock b = new ExtendedBlock("fake-pool", new Block(12345L));
    LocatedBlock fakeBlock = new LocatedBlock(b, new DatanodeInfo[0]);
    ClientDatanodeProtocol proxy = null;
    try {
        proxy = DFSUtilClient.createClientDatanodeProtocolProxy(fakeDnId, conf, 500, false, fakeBlock);
        proxy.getReplicaVisibleLength(new ExtendedBlock("bpid", 1));
        fail("Did not get expected exception: SocketTimeoutException");
    } catch (SocketTimeoutException e) {
        LOG.info("Got the expected Exception: SocketTimeoutException");
    } finally {
        if (proxy != null) {
            RPC.stopProxy(proxy);
        }
        server.stop();
    }
}
Also used : DatanodeID(org.apache.hadoop.hdfs.protocol.DatanodeID) SocketTimeoutException(java.net.SocketTimeoutException) Server(org.apache.hadoop.ipc.Server) InetSocketAddress(java.net.InetSocketAddress) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock) Block(org.apache.hadoop.hdfs.protocol.Block) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) ClientDatanodeProtocol(org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol) Test(org.junit.Test)

Example 37 with SocketTimeoutException

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

the class TestWebHdfsTimeouts method testConnectTimeout.

/**
   * Expect connect timeout, because the connection backlog is consumed.
   */
@Test(timeout = TEST_TIMEOUT)
public void testConnectTimeout() throws Exception {
    consumeConnectionBacklog();
    try {
        fs.listFiles(new Path("/"), false);
        fail("expected timeout");
    } catch (SocketTimeoutException e) {
        GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority() + ": connect timed out", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 38 with SocketTimeoutException

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

the class TestWebHdfsTimeouts method testTwoStepWriteConnectTimeout.

/**
   * On the second step of two-step write, expect connect timeout accessing the
   * redirect location, because the connection backlog is consumed.
   */
@Test(timeout = TEST_TIMEOUT)
public void testTwoStepWriteConnectTimeout() throws Exception {
    startSingleTemporaryRedirectResponseThread(true);
    OutputStream os = null;
    try {
        os = fs.create(new Path("/file"));
        fail("expected timeout");
    } catch (SocketTimeoutException e) {
        GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority() + ": connect timed out", e);
    } finally {
        IOUtils.cleanup(LOG, os);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SocketTimeoutException(java.net.SocketTimeoutException) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 39 with SocketTimeoutException

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

the class TestWebHdfsTimeouts method testRedirectConnectTimeout.

/**
   * After a redirect, expect connect timeout accessing the redirect location,
   * because the connection backlog is consumed.
   */
@Test(timeout = TEST_TIMEOUT)
public void testRedirectConnectTimeout() throws Exception {
    startSingleTemporaryRedirectResponseThread(true);
    try {
        fs.getFileChecksum(new Path("/file"));
        fail("expected timeout");
    } catch (SocketTimeoutException e) {
        GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority() + ": connect timed out", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 40 with SocketTimeoutException

use of java.net.SocketTimeoutException 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)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)389 IOException (java.io.IOException)211 Test (org.junit.Test)95 SocketException (java.net.SocketException)53 Socket (java.net.Socket)52 InputStream (java.io.InputStream)46 ServerSocket (java.net.ServerSocket)43 InetSocketAddress (java.net.InetSocketAddress)39 UnknownHostException (java.net.UnknownHostException)37 ConnectException (java.net.ConnectException)36 MalformedURLException (java.net.MalformedURLException)30 URL (java.net.URL)30 OutputStream (java.io.OutputStream)27 DatagramPacket (java.net.DatagramPacket)25 HttpURLConnection (java.net.HttpURLConnection)25 ArrayList (java.util.ArrayList)23 File (java.io.File)22 HashMap (java.util.HashMap)22 InterruptedIOException (java.io.InterruptedIOException)21 EOFException (java.io.EOFException)19