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");
}
}
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();
}
}
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");
}
}
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");
}
}
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();
}
}
Aggregations