Search in sources :

Example 16 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class JNDIIntegrationTest method assertBeanBinding.

private void assertBeanBinding(WildFlyCamelContext camelctx) throws NamingException, Exception {
    InitialContext inicxt = new InitialContext();
    String bindingName = CamelConstants.CAMEL_CONTEXT_BINDING_NAME + "/" + camelctx.getName();
    Context jndictx = camelctx.getNamingContext();
    jndictx.bind("helloBean", new HelloBean());
    try {
        camelctx.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:start").bean("helloBean");
            }
        });
        camelctx.start();
        try {
            // Assert that the context is bound into JNDI after start
            CamelContext lookup = (CamelContext) inicxt.lookup(bindingName);
            Assert.assertSame(camelctx, lookup);
            ProducerTemplate producer = camelctx.createProducerTemplate();
            String result = producer.requestBody("direct:start", "Kermit", String.class);
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            camelctx.stop();
        }
        // Assert that the context is unbound from JNDI after stop
        try {
            // Removing an msc service is asynchronous
            Thread.sleep(200);
            inicxt.lookup(bindingName);
            Assert.fail("NameNotFoundException expected");
        } catch (NameNotFoundException ex) {
        // expected
        }
    } finally {
        jndictx.unbind("helloBean");
    }
}
Also used : InitialContext(javax.naming.InitialContext) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Context(javax.naming.Context) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) NameNotFoundException(javax.naming.NameNotFoundException) HelloBean(org.wildfly.camel.test.common.types.HelloBean) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException)

Example 17 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class CloudWatchIntegrationTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() throws Exception {
    AmazonCloudWatchClient cwClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", cwClient);
    List<Metric> staleMetrics = cwClient.listMetrics(new ListMetricsRequest().withNamespace(NAMESPACE)).getMetrics().stream().filter(metric -> !metric.getMetricName().startsWith(CloudWatchIntegrationTest.class.getSimpleName()) || System.currentTimeMillis() - AWSUtils.toEpochMillis(metric.getMetricName()) > // 
    AWSUtils.TWO_WEEKS).collect(Collectors.toList());
    if (staleMetrics.size() > 0) {
        Assert.fail("Found '" + CloudWatchIntegrationTest.class.getName() + "-*' metrics older than two weeks: " + staleMetrics);
    }
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("cwClient", cwClient);
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:metrics").to("aws-cw://" + NAMESPACE + "?amazonCwClient=#cwClient");
        }
    });
    camelctx.start();
    try {
        Map<String, Object> headers = new HashMap<>();
        headers.put(CwConstants.METRIC_NAME, METRIC_NAME);
        headers.put(CwConstants.METRIC_DIMENSION_NAME, DIM_NAME);
        headers.put(CwConstants.METRIC_DIMENSION_VALUE, DIM_VALUE);
        ListMetricsRequest request = new ListMetricsRequest().withNamespace(NAMESPACE).withMetricName(METRIC_NAME).withDimensions(new DimensionFilter().withName(DIM_NAME).withValue(DIM_VALUE));
        List<Metric> metrics = Collections.emptyList();
        ProducerTemplate producer = camelctx.createProducerTemplate();
        for (int i = 100; i < 105 && metrics.size() == 0; i++) {
            producer.sendBodyAndHeaders("direct:metrics", new Double(i), headers);
            metrics = cwClient.listMetrics(request).getMetrics();
            System.out.println("metrics #" + i + ": " + metrics);
            Thread.sleep(1000);
        }
    // It may take several minutes for the metric to show up
    // Assert.assertEquals(1, metrics.size());
    } finally {
        camelctx.stop();
    }
}
Also used : ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) EmptyAsset(org.jboss.shrinkwrap.api.asset.EmptyAsset) AWSUtils(org.wildfly.camel.test.common.aws.AWSUtils) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CloudWatchClientProducer(org.wildfly.camel.test.aws.subA.CloudWatchClientProducer) CloudWatchClientProvider(org.wildfly.camel.test.aws.subA.CloudWatchClientProducer.CloudWatchClientProvider) Inject(javax.inject.Inject) CamelAware(org.wildfly.extension.camel.CamelAware) Map(java.util.Map) BasicCredentialsProvider(org.wildfly.camel.test.common.aws.BasicCredentialsProvider) ProducerTemplate(org.apache.camel.ProducerTemplate) Assume(org.junit.Assume) Metric(com.amazonaws.services.cloudwatch.model.Metric) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Test(org.junit.Test) AmazonCloudWatchClient(com.amazonaws.services.cloudwatch.AmazonCloudWatchClient) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Collectors(java.util.stream.Collectors) CloudWatchUtils(org.wildfly.camel.test.common.aws.CloudWatchUtils) DimensionFilter(com.amazonaws.services.cloudwatch.model.DimensionFilter) List(java.util.List) RouteBuilder(org.apache.camel.builder.RouteBuilder) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) CwConstants(org.apache.camel.component.aws.cw.CwConstants) Assert(org.junit.Assert) Collections(java.util.Collections) ProducerTemplate(org.apache.camel.ProducerTemplate) AmazonCloudWatchClient(com.amazonaws.services.cloudwatch.AmazonCloudWatchClient) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) DimensionFilter(com.amazonaws.services.cloudwatch.model.DimensionFilter) Metric(com.amazonaws.services.cloudwatch.model.Metric) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 18 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext 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)

Example 19 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class SDBIntegrationTest method putAndGetAttributes.

@Test
@SuppressWarnings("unchecked")
public void putAndGetAttributes() throws Exception {
    AmazonSimpleDBClient sdbClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sdbClient);
    assertNoStaleDomain(sdbClient, "before");
    try {
        try {
            SDBUtils.createDomain(sdbClient, domainName);
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("sdbClient", sdbClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sdb://" + domainName + "?amazonSDBClient=#sdbClient");
                }
            });
            camelctx.start();
            try {
                ReplaceableAttribute attr = new ReplaceableAttribute("SomeName", "SomeValue", true);
                ProducerTemplate producer = camelctx.createProducerTemplate();
                Exchange exchange = producer.send("direct:start", new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
                        exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, Collections.singletonList(attr));
                    }
                });
                Assert.assertNull(exchange.getException());
                int retries = 10;
                List<Attribute> result = Collections.emptyList();
                while (result.isEmpty() && 0 < retries--) {
                    exchange = producer.send("direct:start", new Processor() {

                        public void process(Exchange exchange) throws Exception {
                            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.GetAttributes);
                            exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        }
                    });
                    Assert.assertNull(exchange.getException());
                    result = exchange.getIn().getHeader(SdbConstants.ATTRIBUTES, List.class);
                    System.out.println(retries + ": " + result);
                    Thread.sleep(500);
                }
                Assert.assertEquals(1, result.size());
                Assert.assertEquals(attr.getName(), result.get(0).getName());
                Assert.assertEquals(attr.getValue(), result.get(0).getValue());
            } finally {
                camelctx.stop();
            }
        } finally {
            sdbClient.deleteDomain(new DeleteDomainRequest(domainName));
        }
    } finally {
        assertNoStaleDomain(sdbClient, "after");
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Exchange(org.apache.camel.Exchange) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) List(java.util.List) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 20 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class SWFIntegrationTest method deciderAndWorker.

@Test
public void deciderAndWorker() throws Exception {
    AmazonSimpleWorkflowClient swfClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", swfClient);
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("swfClient", swfClient);
    camelctx.addRoutes(new RouteBuilder() {

        public void configure() {
            String options = "amazonSWClient=#swfClient&domainName=" + SWFUtils.DOMAIN + "&activityList=swf-alist&workflowList=swf-wlist&version=1.0";
            from("aws-swf://activity?" + options + "&eventName=processActivities").log("FOUND ACTIVITY TASK ${body}").setBody(constant("1")).to("mock:worker");
            from("aws-swf://workflow?" + options + "&eventName=processWorkflows").log("FOUND WORKFLOW TASK ${body}").filter(header(SWFConstants.ACTION).isEqualTo(SWFConstants.EXECUTE_ACTION)).to("aws-swf://activity?" + options + "&eventName=processActivities").setBody(constant("Message two")).to("aws-swf://activity?" + options + "&eventName=processActivities").log("SENT ACTIVITY TASK ${body}").to("mock:decider");
            from("direct:start").to("aws-swf://workflow?" + options + "&eventName=processWorkflows").log("SENT WORKFLOW TASK ${body}").to("mock:starter");
        }
    });
    MockEndpoint decider = camelctx.getEndpoint("mock:decider", MockEndpoint.class);
    MockEndpoint worker = camelctx.getEndpoint("mock:worker", MockEndpoint.class);
    MockEndpoint starter = camelctx.getEndpoint("mock:starter", MockEndpoint.class);
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", "Hello world!");
        starter.expectedMessageCount(1);
        decider.expectedMinimumMessageCount(1);
        worker.expectedMessageCount(2);
        String workflowId = starter.getReceivedExchanges().get(0).getIn().getHeader(SWFConstants.WORKFLOW_ID, String.class);
        Assert.assertNotNull(SWFConstants.WORKFLOW_ID + " not null", workflowId);
        SWFUtils.terminateWorkflowExecution(swfClient, workflowId);
    } finally {
        camelctx.stop();
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonSimpleWorkflowClient(com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClient) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Aggregations

WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)26 Test (org.junit.Test)20 RouteBuilder (org.apache.camel.builder.RouteBuilder)18 ProducerTemplate (org.apache.camel.ProducerTemplate)14 Exchange (org.apache.camel.Exchange)8 Context (javax.naming.Context)6 Processor (org.apache.camel.Processor)6 HashMap (java.util.HashMap)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 CamelContext (org.apache.camel.CamelContext)3 Before (org.junit.Before)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)2 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)2 List (java.util.List)2 InitialContext (javax.naming.InitialContext)2 CamelContextFactory (org.wildfly.extension.camel.CamelContextFactory)2 AmazonCloudWatchClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchClient)1 DimensionFilter (com.amazonaws.services.cloudwatch.model.DimensionFilter)1