Search in sources :

Example 1 with AvaticaSeverity

use of org.apache.calcite.avatica.AvaticaSeverity in project calcite-avatica by apache.

the class AvaticaClientRuntimeExceptionTest method testGetters.

@Test
public void testGetters() {
    final String errorMsg = "My error message";
    final int errorCode = 10;
    final String sqlState = "abc12";
    final AvaticaSeverity severity = AvaticaSeverity.ERROR;
    final List<String> stacktraces = Arrays.asList("my stack trace");
    final RpcMetadataResponse metadata = new RpcMetadataResponse("localhost:8765");
    AvaticaClientRuntimeException e = new AvaticaClientRuntimeException(errorMsg, errorCode, sqlState, severity, stacktraces, metadata);
    assertEquals(errorMsg, e.getMessage());
    assertEquals(errorCode, e.getErrorCode());
    assertEquals(severity, e.getSeverity());
    assertEquals(stacktraces, e.getServerExceptions());
    assertEquals(metadata, e.getRpcMetadata());
}
Also used : AvaticaSeverity(org.apache.calcite.avatica.AvaticaSeverity) AvaticaClientRuntimeException(org.apache.calcite.avatica.AvaticaClientRuntimeException) RpcMetadataResponse(org.apache.calcite.avatica.remote.Service.RpcMetadataResponse) Test(org.junit.Test)

Example 2 with AvaticaSeverity

use of org.apache.calcite.avatica.AvaticaSeverity in project calcite-avatica by apache.

the class ErrorResponseTest method testToClientRTE.

@Test
public void testToClientRTE() {
    final String message = "There was an error";
    final int code = 23;
    final String state = "a1b2c";
    final AvaticaSeverity severity = AvaticaSeverity.ERROR;
    final List<String> exceptions = Arrays.asList("Server Stacktrace 1", "Server Stacktace 2");
    final RpcMetadataResponse metadata = new RpcMetadataResponse("localhost:8765");
    final ErrorResponse resp = new ErrorResponse(message, code, state, severity, exceptions, metadata);
    AvaticaClientRuntimeException exception = resp.toException();
    assertTrue("Expected error message to end with '" + resp.errorMessage + "', but was '" + exception.getMessage() + "'", exception.getMessage().endsWith(resp.errorMessage));
    assertEquals(resp.errorCode, exception.getErrorCode());
    assertEquals(resp.severity, exception.getSeverity());
    assertEquals(resp.sqlState, exception.getSqlState());
    assertEquals(resp.exceptions, exception.getServerExceptions());
    assertEquals(resp.rpcMetadata, exception.getRpcMetadata());
}
Also used : AvaticaSeverity(org.apache.calcite.avatica.AvaticaSeverity) AvaticaClientRuntimeException(org.apache.calcite.avatica.AvaticaClientRuntimeException) RpcMetadataResponse(org.apache.calcite.avatica.remote.Service.RpcMetadataResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Test(org.junit.Test)

Example 3 with AvaticaSeverity

use of org.apache.calcite.avatica.AvaticaSeverity in project calcite-avatica by apache.

the class ErrorResponseTest method testEquality.

@Test
public void testEquality() {
    final String message = "There was an error";
    final int code = 23;
    final String state = "a1b2c";
    final AvaticaSeverity severity = AvaticaSeverity.ERROR;
    final List<String> exceptions = Arrays.asList("Server Stacktrace 1", "Server Stacktace 2");
    final RpcMetadataResponse metadata = new RpcMetadataResponse("localhost:8765");
    assertEquals(new ErrorResponse(message, code, state, severity, exceptions, metadata), new ErrorResponse(message, code, state, severity, exceptions, metadata));
}
Also used : AvaticaSeverity(org.apache.calcite.avatica.AvaticaSeverity) RpcMetadataResponse(org.apache.calcite.avatica.remote.Service.RpcMetadataResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Test(org.junit.Test)

Example 4 with AvaticaSeverity

use of org.apache.calcite.avatica.AvaticaSeverity in project calcite-avatica by apache.

the class AbstractHandler method unwrapException.

/**
   * Unwrap Avatica-specific context about a given exception.
   *
   * @param e A caught exception throw by Avatica implementation.
   * @return An {@link ErrorResponse}.
   */
ErrorResponse unwrapException(Exception e) {
    // By default, we know nothing extra.
    int errorCode = ErrorResponse.UNKNOWN_ERROR_CODE;
    String sqlState = ErrorResponse.UNKNOWN_SQL_STATE;
    AvaticaSeverity severity = AvaticaSeverity.UNKNOWN;
    String errorMsg = null;
    // Extract the contextual information if we have it. We may not.
    if (e instanceof AvaticaRuntimeException) {
        AvaticaRuntimeException rte = (AvaticaRuntimeException) e;
        errorCode = rte.getErrorCode();
        sqlState = rte.getSqlState();
        severity = rte.getSeverity();
        errorMsg = rte.getErrorMessage();
    } else if (e instanceof NoSuchConnectionException) {
        errorCode = ErrorResponse.MISSING_CONNECTION_ERROR_CODE;
        severity = AvaticaSeverity.ERROR;
        errorMsg = e.getMessage();
    } else {
        // Try to construct a meaningful error message when the server impl doesn't provide one.
        errorMsg = getCausalChain(e);
    }
    return new ErrorResponse(e, errorMsg, errorCode, sqlState, severity, metadata);
}
Also used : AvaticaSeverity(org.apache.calcite.avatica.AvaticaSeverity) NoSuchConnectionException(org.apache.calcite.avatica.NoSuchConnectionException) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse)

Aggregations

AvaticaSeverity (org.apache.calcite.avatica.AvaticaSeverity)4 ErrorResponse (org.apache.calcite.avatica.remote.Service.ErrorResponse)3 RpcMetadataResponse (org.apache.calcite.avatica.remote.Service.RpcMetadataResponse)3 Test (org.junit.Test)3 AvaticaClientRuntimeException (org.apache.calcite.avatica.AvaticaClientRuntimeException)2 NoSuchConnectionException (org.apache.calcite.avatica.NoSuchConnectionException)1