HADOOP-16453. Update how exceptions are handled in NetUtils. Contributed by Lisheng Sun.
This commit is contained in:
parent
cf5d8957ee
commit
6b4564f1d5
@ -804,7 +804,11 @@ public static IOException wrapException(final String destHost,
|
|||||||
+ ";"
|
+ ";"
|
||||||
+ see("SocketException"));
|
+ see("SocketException"));
|
||||||
} else {
|
} else {
|
||||||
// Return instance of same type if Exception has a String constructor
|
// 1. Return instance of same type with exception msg if Exception has a
|
||||||
|
// String constructor.
|
||||||
|
// 2. Return instance of same type if Exception doesn't have a String
|
||||||
|
// constructor.
|
||||||
|
// Related HADOOP-16453.
|
||||||
return wrapWithMessage(exception,
|
return wrapWithMessage(exception,
|
||||||
"DestHost:destPort " + destHost + ":" + destPort
|
"DestHost:destPort " + destHost + ":" + destPort
|
||||||
+ " , LocalHost:localPort " + localHost
|
+ " , LocalHost:localPort " + localHost
|
||||||
@ -832,9 +836,9 @@ private static <T extends IOException> T wrapWithMessage(
|
|||||||
Constructor<? extends Throwable> ctor = clazz.getConstructor(String.class);
|
Constructor<? extends Throwable> ctor = clazz.getConstructor(String.class);
|
||||||
Throwable t = ctor.newInstance(msg);
|
Throwable t = ctor.newInstance(msg);
|
||||||
return (T)(t.initCause(exception));
|
return (T)(t.initCause(exception));
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
return exception;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LOG.trace("Unable to wrap exception of type {}: it has no (String) "
|
|
||||||
+ "constructor", clazz, e);
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1582,11 +1582,10 @@ public void testRpcResponseLimit() throws Throwable {
|
|||||||
try {
|
try {
|
||||||
call(client, 0, addr, conf);
|
call(client, 0, addr, conf);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Throwable t = ioe.getCause();
|
Assert.assertNotNull(ioe);
|
||||||
Assert.assertNotNull(t);
|
Assert.assertEquals(RpcException.class, ioe.getClass());
|
||||||
Assert.assertEquals(RpcException.class, t.getClass());
|
|
||||||
Assert.assertEquals("RPC response exceeds maximum data length",
|
Assert.assertEquals("RPC response exceeds maximum data length",
|
||||||
t.getMessage());
|
ioe.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Assert.fail("didn't get limit exceeded");
|
Assert.fail("didn't get limit exceeded");
|
||||||
|
@ -279,11 +279,9 @@ public void testWrapKerbAuthException() throws Throwable {
|
|||||||
@Test
|
@Test
|
||||||
public void testWrapIOEWithNoStringConstructor() throws Throwable {
|
public void testWrapIOEWithNoStringConstructor() throws Throwable {
|
||||||
IOException e = new CharacterCodingException();
|
IOException e = new CharacterCodingException();
|
||||||
IOException wrapped = verifyExceptionClass(e, IOException.class);
|
IOException wrapped =
|
||||||
assertInException(wrapped, "Failed on local exception");
|
verifyExceptionClass(e, CharacterCodingException.class);
|
||||||
assertNotInException(wrapped, NetUtils.HADOOP_WIKI);
|
assertEquals(null, wrapped.getMessage());
|
||||||
assertInException(wrapped, "Host Details ");
|
|
||||||
assertRemoteDetailsIncluded(wrapped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -295,11 +293,8 @@ private TestIOException(String cause){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
IOException e = new TestIOException();
|
IOException e = new TestIOException();
|
||||||
IOException wrapped = verifyExceptionClass(e, IOException.class);
|
IOException wrapped = verifyExceptionClass(e, TestIOException.class);
|
||||||
assertInException(wrapped, "Failed on local exception");
|
assertEquals(null, wrapped.getMessage());
|
||||||
assertNotInException(wrapped, NetUtils.HADOOP_WIKI);
|
|
||||||
assertInException(wrapped, "Host Details ");
|
|
||||||
assertRemoteDetailsIncluded(wrapped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user