Search in sources :

Example 91 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class TestRecoveryMonitorRoute method postProcessTest.

@Override
public void postProcessTest() throws Exception {
    super.postProcessTest();
    final AggregationDAO dao = (AggregationDAO) context.getRegistry().lookup("shortRecoveryIntervalAggregationDAO");
    dao.purgeAll();
    assertEquals(0, dao.getAggregationKeys().size());
    assertEquals(0, dao.getAggregationCompletedKeys().size());
    // pre populate some recovery data
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    final Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com,ah4626@direct.securehealthemail.com", "");
    final Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(originalMessage);
    final ConcurrentJPAAggregationRepository repo = (ConcurrentJPAAggregationRepository) context.getRegistry().lookup("monitoringRepo");
    repo.add(context, originalMessageId, exchange);
    repo.remove(context, originalMessageId, exchange);
    // lock the row to create a delay and ensure we recover 
    // exchange ids that return null at some point
    repo.recover(context, exchange.getExchangeId());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) AggregationDAO(org.nhindirect.monitor.dao.AggregationDAO) ConcurrentJPAAggregationRepository(org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository)

Example 92 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class TestTimedOutMonitorRoute method testTimeoutReliableMessage_conditionNotComplete_assertTimedOut.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertTimedOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // no MDN sent... messages should timeout after 2 seconds
    // sleep 3 seconds to make sure it completes
    Thread.sleep(3000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    // make sure there is only 1 message in the exchange
    @SuppressWarnings("unchecked") Collection<Tx> messages = exchange.getIn().getBody(Collection.class);
    assertEquals(1, messages.size());
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 93 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class TestTimedOutMonitorRoute method testTimeoutReliableMessage_conditionNotComplete_assertTimedOutAndAggregatedTimeoutDecayed.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertTimedOutAndAggregatedTimeoutDecayed() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // sleep .5 second then send the next part of the message
    Thread.sleep(500);
    // send MDN processed to original message
    Tx mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Processed);
    template.sendBody("direct:start", mdnMessage);
    // no MDN sent... messages should timeout after 1 second from now
    // sleep 2 seconds to make sure it completes
    Thread.sleep(2000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    // make sure there are 2 messages in the exchange
    @SuppressWarnings("unchecked") Collection<Tx> messages = exchange.getIn().getBody(Collection.class);
    assertEquals(2, messages.size());
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    // make sure the aggregated timeout decayed properly... it should now be < 500 ms
    assertTrue((Long) exchange.getProperty(Exchange.AGGREGATED_TIMEOUT) < 500);
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 94 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class TestTimedOutMonitorRoute method testTimeoutNonReliableMessage_conditionNotComplete_assertTimedOut.

@Test
public void testTimeoutNonReliableMessage_conditionNotComplete_assertTimedOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "");
    template.sendBody("direct:start", originalMessage);
    // no MDN sent... messages should timeout after 2 seconds
    // sleep 3 seconds to make sure it completes
    Thread.sleep(3000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 95 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_emptyDetails_assertNullId.

@Test
public void testEvaluate_emptyDetails_assertNullId() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertNull(exp.evaluate(exchange, String.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78