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

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

Source:RPCExceptionHandler.java Github

copy

Full Screen

...103 String type = p.getType().getFullTypeNameWithGenericType();104 // skip to handle root TException here105 if (rpcType == RPCType.THRIFT && type.equals(THRIFT_EXCEPTION_ROOT))106 continue;107 if (isInstanceOf(e, type)){108 p.setValueBasedOnInstance(e);109 dto.exceptionDto = p.getDto();110 dto.type = RPCExceptionType.CUSTOMIZED_EXCEPTION;111 return true;112 }113 }114 return false;115 }116 private static boolean handleTException(Object e, RPCExceptionInfoDto dto) {117 Method getType = null;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