Search in sources :

Example 1 with FederationResponse

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

the class ObjectMapperUtil method assertBaseSerialization.

private static <T> void assertBaseSerialization(Object object) {
    Class<?> clazz = object.getClass();
    if (object instanceof FederationRequest)
        clazz = FederationRequest.class;
    else if (object instanceof FederationResponse) {
        clazz = FederationResponse.class;
    }
    try (BlockAllocator allocator = new BlockAllocatorImpl()) {
        // check SerDe write, SerDe read
        ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
        ObjectMapper serDe = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
        serDe.writeValue(serDeOut, object);
        byte[] serDeOutput = serDeOut.toByteArray();
        assertEquals(object, serDe.readValue(new ByteArrayInputStream(serDeOutput), clazz));
    } catch (IOException | AssertionError ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) FederationResponse(com.amazonaws.athena.connector.lambda.request.FederationResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 2 with FederationResponse

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

the class ObjectMapperUtil method assertSerializationBackwardsCompatibleV3toV2.

private static <T> void assertSerializationBackwardsCompatibleV3toV2(Object object) {
    Class<?> clazz = object.getClass();
    if (object instanceof FederationRequest)
        clazz = FederationRequest.class;
    else if (object instanceof FederationResponse) {
        clazz = FederationResponse.class;
    }
    try (BlockAllocator allocator = new BlockAllocatorImpl()) {
        // check SerDe write, SerDe read
        ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
        ObjectMapper serDeV3 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_THREE);
        ObjectMapper serDeV2 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
        serDeV3.writeValue(serDeOut, object);
        byte[] serDeOutput = serDeOut.toByteArray();
        assertEquals(object, serDeV2.readValue(new ByteArrayInputStream(serDeOutput), clazz));
    } catch (IOException | AssertionError ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) FederationResponse(com.amazonaws.athena.connector.lambda.request.FederationResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 3 with FederationResponse

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

the class ObjectMapperUtil method assertSerializationForwardsCompatibleV2toV3.

private static <T> void assertSerializationForwardsCompatibleV2toV3(Object object) {
    Class<?> clazz = object.getClass();
    if (object instanceof FederationRequest)
        clazz = FederationRequest.class;
    else if (object instanceof FederationResponse) {
        clazz = FederationResponse.class;
    }
    try (BlockAllocator allocator = new BlockAllocatorImpl()) {
        // check SerDe write, SerDe read
        ByteArrayOutputStream serDeOut = new ByteArrayOutputStream();
        ObjectMapper serDeV3 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_THREE);
        ObjectMapper serDeV2 = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
        serDeV2.writeValue(serDeOut, object);
        byte[] serDeOutput = serDeOut.toByteArray();
        assertEquals(object, serDeV3.readValue(new ByteArrayInputStream(serDeOutput), clazz));
    } catch (IOException | AssertionError ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) FederationResponse(com.amazonaws.athena.connector.lambda.request.FederationResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 4 with FederationResponse

use of com.amazonaws.athena.connector.lambda.request.FederationResponse in project foundry-athena-query-federation-connector by palantir.

the class FoundryRecordHandlerTest method assetRoundTripSerializable.

private void assetRoundTripSerializable(FederationResponse response) throws JsonProcessingException {
    FederationResponse other = objectMapper.readValue(objectMapper.writeValueAsString(response), FederationResponse.class);
    assertThat(other).isNotNull();
}
Also used : FederationResponse(com.amazonaws.athena.connector.lambda.request.FederationResponse)

Aggregations

FederationResponse (com.amazonaws.athena.connector.lambda.request.FederationResponse)4 BlockAllocator (com.amazonaws.athena.connector.lambda.data.BlockAllocator)3 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)3 FederationRequest (com.amazonaws.athena.connector.lambda.request.FederationRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3