Search in sources :

Example 1 with StreamRecord

use of com.amazonaws.services.dynamodbv2.model.StreamRecord in project wildfly-camel by wildfly-extras.

the class DynamoDBStreamsIntegrationTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() throws Exception {
    AmazonDynamoDBClient ddbClient = ddbProvider.getClient();
    Assume.assumeNotNull("AWS client not null", ddbClient);
    DynamoDBUtils.assertNoStaleTables(ddbClient, "before");
    try {
        try {
            TableDescription description = DynamoDBUtils.createTable(ddbClient, tableName);
            Assert.assertEquals("ACTIVE", description.getTableStatus());
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("ddbClientB", ddbClient);
            camelctx.getNamingContext().bind("dbsClientB", dbsProvider.getClient());
            camelctx.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientB");
                    from("aws-ddbstream://" + tableName + "?amazonDynamoDbStreamsClient=#dbsClientB").to("seda:end");
                }
            });
            PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
            pollingConsumer.start();
            camelctx.start();
            try {
                DynamoDBUtils.putItem(camelctx, "Book 103 Title");
                String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Title", result);
                Exchange exchange = pollingConsumer.receive(3000);
                Assert.assertNull(exchange);
                DynamoDBUtils.updItem(camelctx, "Book 103 Update");
                result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Update", result);
                exchange = pollingConsumer.receive(3000);
                StreamRecord record = exchange.getIn().getBody(Record.class).getDynamodb();
                Map<String, AttributeValue> oldImage = record.getOldImage();
                Map<String, AttributeValue> newImage = record.getNewImage();
                Assert.assertEquals("Book 103 Title", oldImage.get("Title").getS());
                Assert.assertEquals("Book 103 Update", newImage.get("Title").getS());
            } finally {
                camelctx.stop();
            }
        } finally {
            DynamoDBUtils.deleteTable(ddbClient, tableName);
        }
    } finally {
        DynamoDBUtils.assertNoStaleTables(ddbClient, "after");
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) RouteBuilder(org.apache.camel.builder.RouteBuilder) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Exchange(org.apache.camel.Exchange) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) Record(com.amazonaws.services.dynamodbv2.model.Record) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Aggregations

AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 Record (com.amazonaws.services.dynamodbv2.model.Record)1 StreamRecord (com.amazonaws.services.dynamodbv2.model.StreamRecord)1 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)1 Exchange (org.apache.camel.Exchange)1 PollingConsumer (org.apache.camel.PollingConsumer)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 Test (org.junit.Test)1 WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)1