How to use getExceptionType method of org.evomaster.client.java.controller.problem.rpc.RPCExceptionHandler class

Best EvoMaster code snippet using org.evomaster.client.java.controller.problem.rpc.RPCExceptionHandler.getExceptionType

Source:RPCExceptionHandler.java Github

copy

Full Screen

...118 try {119 getType = e.getClass().getDeclaredMethod("getType");120 getType.setAccessible(true);121 int type = (int) getType.invoke(e);122 dto.type = getExceptionType(extract(e), type);123 return true;124 } catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException ex) {125 SimpleLogger.error("Fail to get type of TException with getType() "+ex.getMessage());126 }127 return false;128 }129 private static String getExceptionMessage(Object e) {130 Method getMessage = null;131 try {132 getMessage = e.getClass().getMethod("getMessage");133 getMessage.setAccessible(true);134 return (String) getMessage.invoke(e);135 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {136 SimpleLogger.error("Error: fail to get message of the exception with "+ex.getMessage());137 return null;138 }139 }140 private static Object getExceptionCause(Object e) {141 Method getCause = null;142 try {143 getCause = e.getClass().getMethod("getCause");144 getCause.setAccessible(true);145 Object exp = getCause.invoke(e);146 if (exp != null) return exp;147 getCause = e.getClass().getMethod("getUndeclaredThrowable");148 getCause.setAccessible(true);149 return getCause.invoke(e);150 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {151 SimpleLogger.error("Error: fail to get message of the exception with "+ex.getMessage());152 return null;153 }154 }155 private static boolean isRootThriftException(Object e) throws ClassNotFoundException {156 return Class.forName(THRIFT_EXCEPTION_ROOT).isInstance(e);157 }158 private static boolean isInstanceOf(Object e, String name) throws ClassNotFoundException {159 return Class.forName(name).isInstance(e);160 }161 /**162 * Note that now we only support categorize exception for thrift163 * @param e is the exception instance164 * @return a category165 * @throws ClassNotFoundException could not find the TException of the thrift166 */167 private static RPCExceptionCategory extract(Object e) throws ClassNotFoundException {168 if (isInstanceOf(e, "org.apache.thrift.TApplicationException"))169 return RPCExceptionCategory.APPLICATION;170 if (isInstanceOf(e, "org.apache.thrift.protocol.TProtocolException"))171 return RPCExceptionCategory.PROTOCOL;172 if (isInstanceOf(e, "org.apache.thrift.transport.TTransportException"))173 return RPCExceptionCategory.TRANSPORT;174 return RPCExceptionCategory.OTHERS;175 }176 private static RPCExceptionType getExceptionType(RPCExceptionCategory category, int intValue){177 for (RPCExceptionType type: RPCExceptionType.values()){178 if (type.intValue == intValue && type.category == category) return type;179 }180 return null;181 }182}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run EvoMaster automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful