HDFS-9478. Reason for failing ipc.FairCallQueue contruction should be thrown. (Contributed by Ajith S)
This commit is contained in:
parent
026b84bf70
commit
9c4631b6f1
|
@ -19,6 +19,7 @@
|
|||
package org.apache.hadoop.ipc;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -70,6 +71,9 @@ public class CallQueueManager<E> {
|
|||
return ctor.newInstance(maxLen, ns, conf);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(theClass.getName()
|
||||
+ " could not be constructed.", e.getCause());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
|
@ -79,6 +83,9 @@ public class CallQueueManager<E> {
|
|||
return ctor.newInstance(maxLen);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(theClass.getName()
|
||||
+ " could not be constructed.", e.getCause());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
|
@ -88,6 +95,9 @@ public class CallQueueManager<E> {
|
|||
return ctor.newInstance();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(theClass.getName()
|
||||
+ " could not be constructed.", e.getCause());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.apache.hadoop.ipc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -219,4 +221,27 @@ public class TestCallQueueManager {
|
|||
|
||||
assertEquals(totalCallsConsumed, totalCallsCreated);
|
||||
}
|
||||
|
||||
public static class ExceptionFakeCall {
|
||||
|
||||
public ExceptionFakeCall() {
|
||||
throw new IllegalArgumentException("Exception caused by constructor.!!");
|
||||
}
|
||||
}
|
||||
|
||||
private static final Class<? extends BlockingQueue<ExceptionFakeCall>> exceptionQueueClass = CallQueueManager
|
||||
.convertQueueClass(ExceptionFakeCall.class, ExceptionFakeCall.class);
|
||||
|
||||
@Test
|
||||
public void testInvocationException() throws InterruptedException {
|
||||
try {
|
||||
new CallQueueManager<ExceptionFakeCall>(exceptionQueueClass, false, 10,
|
||||
"", null);
|
||||
fail();
|
||||
} catch (RuntimeException re) {
|
||||
assertTrue(re.getCause() instanceof IllegalArgumentException);
|
||||
assertEquals("Exception caused by constructor.!!", re.getCause()
|
||||
.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue