Search in sources :

Example 6 with PingRequest

use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.

the class UserDefinedFunctionHandler method handleRequest.

@Override
public final void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
    try (BlockAllocator allocator = new BlockAllocatorImpl()) {
        ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
        try (FederationRequest rawRequest = objectMapper.readValue(inputStream, FederationRequest.class)) {
            if (rawRequest instanceof PingRequest) {
                try (PingResponse response = doPing((PingRequest) rawRequest)) {
                    assertNotNull(response);
                    objectMapper.writeValue(outputStream, response);
                }
                return;
            }
            if (!(rawRequest instanceof UserDefinedFunctionRequest)) {
                throw new RuntimeException("Expected a UserDefinedFunctionRequest but found " + rawRequest.getClass());
            }
            doHandleRequest(allocator, objectMapper, (UserDefinedFunctionRequest) rawRequest, outputStream);
        } catch (Exception ex) {
            throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
        }
    }
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) UserDefinedFunctionRequest(com.amazonaws.athena.connector.lambda.udf.UserDefinedFunctionRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) PingResponse(com.amazonaws.athena.connector.lambda.request.PingResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 7 with PingRequest

use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.

the class CompositeHandlerTest method doPing.

@Test
public void doPing() throws Exception {
    PingRequest req = mock(PingRequest.class);
    when(req.getCatalogName()).thenReturn("catalog");
    when(req.getQueryId()).thenReturn("queryId");
    compositeHandler.handleRequest(allocator, req, new ByteArrayOutputStream(), objectMapper);
    verify(mockMetadataHandler, times(1)).doPing(any(PingRequest.class));
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 8 with PingRequest

use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.

the class PingRequestSerDeTest method testForwardsCompatibility.

@Test
public void testForwardsCompatibility() throws IOException {
    logger.info("testForwardsCompatibility: enter");
    String expectedSerDeFile = utils.getResourceOrFail("serde", "PingRequestForwardsCompatible.json");
    expectedSerDeText = utils.readAllAsString(expectedSerDeFile).trim();
    InputStream input = new ByteArrayInputStream(expectedSerDeText.getBytes());
    PingRequest actual = (PingRequest) mapper.readValue(input, FederationRequest.class);
    logger.info("testForwardsCompatibility: deserialized[{}]", actual);
    assertEquals(expected, actual);
    assertEquals(expected.getIdentity().getArn(), actual.getIdentity().getArn());
    logger.info("testForwardsCompatibility: exit");
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest) Test(org.junit.Test)

Example 9 with PingRequest

use of com.amazonaws.athena.connector.lambda.request.PingRequest in project aws-athena-query-federation by awslabs.

the class PingRequestSerDeTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    expected = new PingRequest(federatedIdentity, "test-catalog", "test-query-id");
    String expectedSerDeFile = utils.getResourceOrFail("serde", "PingRequest.json");
    expectedSerDeText = utils.readAllAsString(expectedSerDeFile).trim();
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) Before(org.junit.Before)

Aggregations

PingRequest (com.amazonaws.athena.connector.lambda.request.PingRequest)9 FederationRequest (com.amazonaws.athena.connector.lambda.request.FederationRequest)5 PingResponse (com.amazonaws.athena.connector.lambda.request.PingResponse)5 BlockAllocator (com.amazonaws.athena.connector.lambda.data.BlockAllocator)3 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Test (org.junit.Test)3 MetadataRequest (com.amazonaws.athena.connector.lambda.metadata.MetadataRequest)2 RecordRequest (com.amazonaws.athena.connector.lambda.records.RecordRequest)2 UserDefinedFunctionRequest (com.amazonaws.athena.connector.lambda.udf.UserDefinedFunctionRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Before (org.junit.Before)1