private static boolean needsConversion(final DremioPBError error) { return incompatibleErrorTypes.contains(error.getErrorType()); }
@Test public void testBuildSystemException() { String message = "This is an exception"; UserException uex = UserException.systemError(new Exception(new RuntimeException(message))).build(logger); Assert.assertTrue(uex.getOriginalMessage().contains(message)); Assert.assertTrue(uex.getOriginalMessage().contains("RuntimeException")); DremioPBError error = uex.getOrCreatePBError(true); Assert.assertEquals(ErrorType.SYSTEM, error.getErrorType()); }
setErrorType(other.getErrorType());
Assert.assertEquals(DremioPBError.ErrorType.RESOURCE, error.getErrorType()); Assert.assertTrue("Error message isn't related to memory error", uex.getMessage().contains(UserException.MEMORY_ERROR_MSG));
private void testSingleMode(String fileName) throws Exception{ test(SINGLE_MODE); CoordinationProtos.NodeEndpoint endpoint = nodes[0].getContext().getEndpoint(); String controlsString = "{\"injections\":[{" + "\"address\":\"" + endpoint.getAddress() + "\"," + "\"port\":\"" + endpoint.getUserPort() + "\"," + "\"type\":\"exception\"," + "\"siteClass\":\"" + "com.dremio.exec.physical.impl.ScanBatch" + "\"," + "\"desc\":\"" + "next-allocate" + "\"," + "\"nSkip\":0," + "\"nFire\":1," + "\"exceptionClass\":\"" + OutOfMemoryException.class.getName() + "\"" + "}]}"; ControlsInjectionUtil.setControls(client, controlsString); String query = getFile(fileName); try { test(query); } catch(UserException uex) { DremioPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(DremioPBError.ErrorType.RESOURCE, error.getErrorType()); Assert.assertTrue("Error message isn't related to memory error", uex.getMessage().contains(UserException.MEMORY_ERROR_MSG)); } }
public void writeTo(io.protostuff.Output output, com.dremio.exec.proto.UserBitShared.DremioPBError message) throws java.io.IOException { if(message.hasErrorId()) output.writeString(1, message.getErrorId(), false); if(message.hasEndpoint()) output.writeObject(2, message.getEndpoint(), com.dremio.exec.proto.SchemaCoordinationProtos.NodeEndpoint.WRITE, false); if(message.hasErrorType()) output.writeEnum(3, message.getErrorType().getNumber(), false); if(message.hasMessage()) output.writeString(4, message.getMessage(), false); if(message.hasException()) output.writeObject(5, message.getException(), com.dremio.exec.proto.SchemaUserBitShared.ExceptionWrapper.WRITE, false); for(com.dremio.exec.proto.UserBitShared.ParsingError parsingError : message.getParsingErrorList()) output.writeObject(6, parsingError, com.dremio.exec.proto.SchemaUserBitShared.ParsingError.WRITE, true); if(message.hasOriginalMessage()) output.writeString(1001, message.getOriginalMessage(), false); for(String context : message.getContextList()) output.writeString(1002, context, true); if(message.hasTypeSpecificContext()) output.writeByteArray(1003, message.getTypeSpecificContext().toByteArray(), false); } public boolean isInitialized(com.dremio.exec.proto.UserBitShared.DremioPBError message)
public static DremioPBError convertIfNecessary(final DremioPBError error) { if (!needsConversion(error)) { return error; } switch (error.getErrorType()) { case SCHEMA_CHANGE: case SOURCE_BAD_STATE: return DremioPBError.newBuilder(error).setErrorType(ErrorType.DATA_READ).build(); case REFLECTION_ERROR: return DremioPBError.newBuilder(error).setErrorType(ErrorType.SYSTEM).build(); case OUT_OF_MEMORY: case IO_EXCEPTION: case CONCURRENT_MODIFICATION: case INVALID_DATASET_METADATA: return DremioPBError.newBuilder(error).setErrorType(ErrorType.RESOURCE).build(); default: // we most likely forgot to add the type to this switch block throw new IllegalStateException("Unhandled error type: " + error.getErrorType()); } }
@Test public void testUpdateErrorType() throws Exception { RpcCompatibilityEncoder encoder = new RpcCompatibilityEncoder(); ChannelHandlerContext context = mock(ChannelHandlerContext.class); DremioPBError error = DremioPBError.newBuilder() .setErrorType(ErrorType.IO_EXCEPTION) .setMessage("test message") .build(); OutboundRpcMessage message = new OutboundRpcMessage(RpcMode.RESPONSE_FAILURE, RpcType.RESP_QUERY_PROFILE, 12, error); List<Object> out = new ArrayList<>(); encoder.encode(context, message, out); assertEquals(1, out.size()); OutboundRpcMessage received = (OutboundRpcMessage) out.get(0); assertEquals(RpcMode.RESPONSE_FAILURE, received.mode); assertEquals(12, received.coordinationId); DremioPBError newError = (DremioPBError) received.pBody; assertEquals(ErrorType.RESOURCE, newError.getErrorType()); assertEquals("test message", newError.getMessage()); }
private UserRemoteException(DremioPBError error) { super(error.getErrorType(), "Dremio Remote Exception", null, error.getTypeSpecificContext()); this.error = error; }
@Test public void testBuildUserExceptionWithCauseAndMessage() { String messageA = "Test message A"; String messageB = "Test message B"; UserException uex = UserException.dataWriteError(new RuntimeException(messageA)).message(messageB).build(logger); DremioPBError error = uex.getOrCreatePBError(false); // passed message should override the cause message Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertEquals(messageB, uex.getOriginalMessage()); }
@Test public void testBuildUserExceptionWithCause() { String message = "Test message"; UserException uex = UserException.dataWriteError(new RuntimeException(message)).build(logger); DremioPBError error = uex.getOrCreatePBError(false); // cause message should be used Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertEquals(message, uex.getOriginalMessage()); }
@Test @Ignore public void testExceptionHandling() throws Exception { try { test("select * from cp.\"jsoninput/DRILL-2350.json\""); } catch(UserException e) { Assert.assertEquals(UserBitShared.DremioPBError.ErrorType.UNSUPPORTED_OPERATION, e.getOrCreatePBError(false).getErrorType()); String s = e.getMessage(); assertEquals("Expected Unsupported Operation Exception.", true, s.contains("Dremio does not support lists of different types.")); } }
private static PreparedStatement createPrepareStmt(String query, boolean expectFailure, ErrorType errorType) throws Exception { CreatePreparedStatementResp resp = client.createPreparedStatement(query).get(); assertTrue("status field was not set", resp.hasStatus()); assertEquals(expectFailure ? RequestStatus.FAILED : RequestStatus.OK, resp.getStatus()); if (expectFailure) { assertEquals(errorType, resp.getError().getErrorType()); } return resp.getPreparedStatement(); }
@Test public void testBuildUserExceptionWithFormattedMessage() { String format = "This is test #%d"; UserException uex = UserException.connectionError().message(format, 5).build(logger); DremioPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(ErrorType.CONNECTION, error.getErrorType()); Assert.assertEquals(String.format(format, 5), uex.getOriginalMessage()); }
@Test public void testBuildUserExceptionWithMessage() { String message = "Test message"; UserException uex = UserException.dataWriteError().message(message).build(logger); DremioPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertEquals(message, uex.getOriginalMessage()); }