Search in sources :

Example 6 with Response

use of org.apache.calcite.avatica.remote.Service.Response in project calcite-avatica by apache.

the class AbstractHandlerTest method testFailedResponseSerialization.

@Test
public void testFailedResponseSerialization() throws IOException {
    @SuppressWarnings("unchecked") final AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
    final Request request = Mockito.mock(Request.class);
    final Response response = Mockito.mock(Response.class);
    final IOException exception = new IOException();
    final ErrorResponse errorResponse = Mockito.mock(ErrorResponse.class);
    final String serializedErrorResponse = "An ErrorResponse";
    // Accept a serialized request
    Mockito.when(handler.apply(Mockito.anyString())).thenCallRealMethod();
    // Deserialize it back into a POJO
    Mockito.when(handler.decode(Mockito.anyString())).thenReturn(request);
    // Construct the Response for that Request
    Mockito.when(request.accept(Mockito.nullable(Service.class))).thenReturn(response);
    // Throw an IOException when serializing the Response.
    Mockito.when(handler.encode(response)).thenThrow(exception);
    Mockito.when(handler.convertToErrorResponse(exception)).thenCallRealMethod();
    // Convert the IOException into an ErrorResponse
    Mockito.when(handler.unwrapException(exception)).thenReturn(errorResponse);
    Mockito.when(handler.encode(errorResponse)).thenReturn(serializedErrorResponse);
    HandlerResponse<String> handlerResp = handler.apply("this is mocked out");
    assertEquals(500, handlerResp.getStatusCode());
    assertEquals(serializedErrorResponse, handlerResp.getResponse());
}
Also used : HandlerResponse(org.apache.calcite.avatica.remote.Handler.HandlerResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Response(org.apache.calcite.avatica.remote.Service.Response) Request(org.apache.calcite.avatica.remote.Service.Request) IOException(java.io.IOException) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Test(org.junit.Test)

Example 7 with Response

use of org.apache.calcite.avatica.remote.Service.Response in project calcite-avatica by apache.

the class ProtobufTranslationImplTest method parameters.

@Parameters
public static List<Object[]> parameters() {
    List<Object[]> params = new ArrayList<>();
    // The impl we're testing
    ProtobufTranslationImpl translation = new ProtobufTranslationImpl();
    // Identity transformation for Requests
    RequestFunc requestFunc = new RequestFunc(translation);
    // Identity transformation for Responses
    ResponseFunc responseFunc = new ResponseFunc(translation);
    List<Request> requests = getRequests();
    List<Request> requestsWithNulls = getRequestsWithNulls();
    List<Response> responses = getResponses();
    // Requests
    for (Request request : requests) {
        params.add(new Object[] { request, requestFunc });
    }
    // Requests with nulls in parameters
    for (Request request : requestsWithNulls) {
        params.add(new Object[] { request, requestFunc });
    }
    // Responses
    for (Response response : responses) {
        params.add(new Object[] { response, responseFunc });
    }
    return params;
}
Also used : CloseConnectionResponse(org.apache.calcite.avatica.remote.Service.CloseConnectionResponse) PrepareResponse(org.apache.calcite.avatica.remote.Service.PrepareResponse) FetchResponse(org.apache.calcite.avatica.remote.Service.FetchResponse) RpcMetadataResponse(org.apache.calcite.avatica.remote.Service.RpcMetadataResponse) ExecuteBatchResponse(org.apache.calcite.avatica.remote.Service.ExecuteBatchResponse) DatabasePropertyResponse(org.apache.calcite.avatica.remote.Service.DatabasePropertyResponse) OpenConnectionResponse(org.apache.calcite.avatica.remote.Service.OpenConnectionResponse) RollbackResponse(org.apache.calcite.avatica.remote.Service.RollbackResponse) CloseStatementResponse(org.apache.calcite.avatica.remote.Service.CloseStatementResponse) Response(org.apache.calcite.avatica.remote.Service.Response) CreateStatementResponse(org.apache.calcite.avatica.remote.Service.CreateStatementResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) ConnectionSyncResponse(org.apache.calcite.avatica.remote.Service.ConnectionSyncResponse) ResultSetResponse(org.apache.calcite.avatica.remote.Service.ResultSetResponse) ExecuteResponse(org.apache.calcite.avatica.remote.Service.ExecuteResponse) SyncResultsResponse(org.apache.calcite.avatica.remote.Service.SyncResultsResponse) CommitResponse(org.apache.calcite.avatica.remote.Service.CommitResponse) ArrayList(java.util.ArrayList) ExecuteRequest(org.apache.calcite.avatica.remote.Service.ExecuteRequest) TablesRequest(org.apache.calcite.avatica.remote.Service.TablesRequest) CloseStatementRequest(org.apache.calcite.avatica.remote.Service.CloseStatementRequest) FetchRequest(org.apache.calcite.avatica.remote.Service.FetchRequest) PrepareRequest(org.apache.calcite.avatica.remote.Service.PrepareRequest) CreateStatementRequest(org.apache.calcite.avatica.remote.Service.CreateStatementRequest) CloseConnectionRequest(org.apache.calcite.avatica.remote.Service.CloseConnectionRequest) CatalogsRequest(org.apache.calcite.avatica.remote.Service.CatalogsRequest) SyncResultsRequest(org.apache.calcite.avatica.remote.Service.SyncResultsRequest) Request(org.apache.calcite.avatica.remote.Service.Request) ConnectionSyncRequest(org.apache.calcite.avatica.remote.Service.ConnectionSyncRequest) SchemasRequest(org.apache.calcite.avatica.remote.Service.SchemasRequest) TableTypesRequest(org.apache.calcite.avatica.remote.Service.TableTypesRequest) DatabasePropertyRequest(org.apache.calcite.avatica.remote.Service.DatabasePropertyRequest) PrepareAndExecuteBatchRequest(org.apache.calcite.avatica.remote.Service.PrepareAndExecuteBatchRequest) TypeInfoRequest(org.apache.calcite.avatica.remote.Service.TypeInfoRequest) CommitRequest(org.apache.calcite.avatica.remote.Service.CommitRequest) PrepareAndExecuteRequest(org.apache.calcite.avatica.remote.Service.PrepareAndExecuteRequest) OpenConnectionRequest(org.apache.calcite.avatica.remote.Service.OpenConnectionRequest) ColumnsRequest(org.apache.calcite.avatica.remote.Service.ColumnsRequest) RollbackRequest(org.apache.calcite.avatica.remote.Service.RollbackRequest) Parameters(org.junit.runners.Parameterized.Parameters)

Example 8 with Response

use of org.apache.calcite.avatica.remote.Service.Response in project calcite-avatica by apache.

the class AbstractHandlerTest method testExceptionUnwrappingWithoutContext.

@Test
public void testExceptionUnwrappingWithoutContext() {
    @SuppressWarnings("unchecked") AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
    Mockito.when(handler.unwrapException(Mockito.any(Exception.class))).thenCallRealMethod();
    Exception e = new RuntimeException();
    Response resp = handler.unwrapException(e);
    assertTrue("Response should be ErrorResponse, but was " + resp.getClass(), resp instanceof ErrorResponse);
    ErrorResponse errorResp = (ErrorResponse) resp;
    assertEquals(ErrorResponse.UNKNOWN_ERROR_CODE, errorResp.errorCode);
    assertEquals(AvaticaSeverity.UNKNOWN, errorResp.severity);
    assertEquals(Arrays.asList(exceptionToString(e)), errorResp.exceptions);
    e = new AvaticaRuntimeException();
    resp = handler.unwrapException(e);
    assertTrue("Response should be ErrorResponse, but was " + resp.getClass(), resp instanceof ErrorResponse);
    errorResp = (ErrorResponse) resp;
    assertEquals(ErrorResponse.UNKNOWN_ERROR_CODE, errorResp.errorCode);
    assertEquals(AvaticaSeverity.UNKNOWN, errorResp.severity);
    assertEquals(Arrays.asList(exceptionToString(e)), errorResp.exceptions);
}
Also used : HandlerResponse(org.apache.calcite.avatica.remote.Handler.HandlerResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Response(org.apache.calcite.avatica.remote.Service.Response) IOException(java.io.IOException) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Test(org.junit.Test)

Example 9 with Response

use of org.apache.calcite.avatica.remote.Service.Response in project calcite-avatica by apache.

the class AbstractHandlerTest method testFailedErrorResponseSerialization.

@Test
public void testFailedErrorResponseSerialization() throws IOException {
    @SuppressWarnings("unchecked") final AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
    final Request request = Mockito.mock(Request.class);
    final Response response = Mockito.mock(Response.class);
    final IOException exception = new IOException();
    final ErrorResponse errorResponse = Mockito.mock(ErrorResponse.class);
    // Accept a serialized request
    Mockito.when(handler.apply(Mockito.anyString())).thenCallRealMethod();
    // Deserialize it back into a POJO
    Mockito.when(handler.decode(Mockito.anyString())).thenReturn(request);
    // Construct the Response for that Request
    Mockito.when(request.accept(Mockito.any(Service.class))).thenReturn(response);
    // Throw an IOException when serializing the Response.
    Mockito.when(handler.encode(response)).thenThrow(exception);
    // Convert the IOException into an ErrorResponse
    Mockito.when(handler.unwrapException(exception)).thenReturn(errorResponse);
    // Fail to serialize the ErrorResponse
    Mockito.when(handler.encode(errorResponse)).thenThrow(exception);
    try {
        handler.apply("this is mocked out");
    } catch (RuntimeException e) {
        assertEquals(exception, e.getCause());
    }
}
Also used : HandlerResponse(org.apache.calcite.avatica.remote.Handler.HandlerResponse) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Response(org.apache.calcite.avatica.remote.Service.Response) Request(org.apache.calcite.avatica.remote.Service.Request) IOException(java.io.IOException) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse) Test(org.junit.Test)

Aggregations

Response (org.apache.calcite.avatica.remote.Service.Response)9 ErrorResponse (org.apache.calcite.avatica.remote.Service.ErrorResponse)8 IOException (java.io.IOException)6 Test (org.junit.Test)6 HandlerResponse (org.apache.calcite.avatica.remote.Handler.HandlerResponse)4 Request (org.apache.calcite.avatica.remote.Service.Request)4 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 CloseConnectionResponse (org.apache.calcite.avatica.remote.Service.CloseConnectionResponse)2 CloseStatementResponse (org.apache.calcite.avatica.remote.Service.CloseStatementResponse)2 CommitResponse (org.apache.calcite.avatica.remote.Service.CommitResponse)2 ConnectionSyncResponse (org.apache.calcite.avatica.remote.Service.ConnectionSyncResponse)2 CreateStatementResponse (org.apache.calcite.avatica.remote.Service.CreateStatementResponse)2 DatabasePropertyResponse (org.apache.calcite.avatica.remote.Service.DatabasePropertyResponse)2 ExecuteBatchResponse (org.apache.calcite.avatica.remote.Service.ExecuteBatchResponse)2 ExecuteResponse (org.apache.calcite.avatica.remote.Service.ExecuteResponse)2 FetchResponse (org.apache.calcite.avatica.remote.Service.FetchResponse)2 OpenConnectionResponse (org.apache.calcite.avatica.remote.Service.OpenConnectionResponse)2 PrepareResponse (org.apache.calcite.avatica.remote.Service.PrepareResponse)2 ResultSetResponse (org.apache.calcite.avatica.remote.Service.ResultSetResponse)2