HDFS-9905. WebHdfsFileSystem#runWithRetry should display original stack trace on error. (Wei-Chiu Chuang via iwasakims)

cherry-picked from 6fcde2e38da04cae3aad6b13cf442af211f71506
This commit is contained in:
Masatake Iwasaki 2016-04-23 23:37:56 +09:00 committed by Eric Payne
parent 577466c1f2
commit 5a3fed0602
2 changed files with 20 additions and 11 deletions

View File

@ -641,8 +641,10 @@ private T runWithRetry() throws IOException {
node = url.getAuthority(); node = url.getAuthority();
} }
try { try {
ioe = ioe.getClass().getConstructor(String.class) IOException newIoe = ioe.getClass().getConstructor(String.class)
.newInstance(node + ": " + ioe.getMessage()); .newInstance(node + ": " + ioe.getMessage());
newIoe.setStackTrace(ioe.getStackTrace());
ioe = newIoe;
} catch (NoSuchMethodException | SecurityException } catch (NoSuchMethodException | SecurityException
| InstantiationException | IllegalAccessException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) { | IllegalArgumentException | InvocationTargetException e) {

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hdfs.web; package org.apache.hadoop.hdfs.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -43,6 +42,7 @@
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.authentication.client.ConnectionConfigurator; import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -115,7 +115,8 @@ public void testConnectTimeout() throws Exception {
fs.listFiles(new Path("/"), false); fs.listFiles(new Path("/"), false);
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority()
+ ": connect timed out",e);
} }
} }
@ -128,7 +129,8 @@ public void testReadTimeout() throws Exception {
fs.listFiles(new Path("/"), false); fs.listFiles(new Path("/"), false);
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority() +
": Read timed out", e);
} }
} }
@ -143,7 +145,8 @@ public void testAuthUrlConnectTimeout() throws Exception {
fs.getDelegationToken("renewer"); fs.getDelegationToken("renewer");
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(fs.getUri().getAuthority() +
": connect timed out", e);
} }
} }
@ -157,7 +160,8 @@ public void testAuthUrlReadTimeout() throws Exception {
fs.getDelegationToken("renewer"); fs.getDelegationToken("renewer");
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(
fs.getUri().getAuthority() + ": Read timed out", e);
} }
} }
@ -172,7 +176,8 @@ public void testRedirectConnectTimeout() throws Exception {
fs.getFileChecksum(new Path("/file")); fs.getFileChecksum(new Path("/file"));
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(
fs.getUri().getAuthority() + ": connect timed out", e);
} }
} }
@ -187,7 +192,8 @@ public void testRedirectReadTimeout() throws Exception {
fs.getFileChecksum(new Path("/file")); fs.getFileChecksum(new Path("/file"));
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(
fs.getUri().getAuthority() + ": Read timed out", e);
} }
} }
@ -203,7 +209,8 @@ public void testTwoStepWriteConnectTimeout() throws Exception {
os = fs.create(new Path("/file")); os = fs.create(new Path("/file"));
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); GenericTestUtils.assertExceptionContains(
fs.getUri().getAuthority() + ": connect timed out", e);
} finally { } finally {
IOUtils.cleanup(LOG, os); IOUtils.cleanup(LOG, os);
} }
@ -223,7 +230,7 @@ public void testTwoStepWriteReadTimeout() throws Exception {
os = null; os = null;
fail("expected timeout"); fail("expected timeout");
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
assertEquals("Read timed out", e.getMessage()); GenericTestUtils.assertExceptionContains("Read timed out", e);
} finally { } finally {
IOUtils.cleanup(LOG, os); IOUtils.cleanup(LOG, os);
} }