@Test public void testHftpSocketTimeout() throws Exception { Configuration conf = new Configuration(); ServerSocket socket = new ServerSocket(0, 1); URI uri = new URI( "hftp", null, InetAddress.getByName(null).getHostAddress(), socket.getLocalPort(), null, null, null); boolean timedout = false; HftpFileSystem fs = (HftpFileSystem) FileSystem.get(uri, conf); try { HttpURLConnection conn = fs.openConnection("/", ""); timedout = false; try { // this will consume the only slot in the backlog conn.getInputStream(); } catch (SocketTimeoutException ste) { timedout = true; assertEquals("Read timed out", ste.getMessage()); } finally { if (conn != null) { conn.disconnect(); } } assertTrue("read timedout", timedout); assertTrue("connect timedout", checkConnectTimeout(fs, false)); } finally { fs.close(); } }
@AfterClass public static void tearDown() throws IOException { hdfs.close(); hftpFs.close(); cluster.shutdown(); }