Search in sources :

Example 6 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition in project nhin-d by DirectProject.

the class VariableTimeoutCondition method getTimeout.

/**
	 * {@inheritDoc}
	 */
@Override
public long getTimeout(Collection<Tx> txs, long exchangeStartTime) {
    TxTimeoutCondition conditionToUse = null;
    final Tx messageToTrack = getMessageToTrack(txs);
    // the general timeout condition
    if (messageToTrack == null)
        conditionToUse = generalExpression;
    else
        conditionToUse = isRelAndTimelyRequired(messageToTrack) ? timelyExpression : generalExpression;
    return conditionToUse.getTimeout(txs, exchangeStartTime);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition)

Example 7 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition in project nhin-d by DirectProject.

the class BasicTxAggregator_aggregateTest method testAggregate_emptyExchanged_addTx.

@Test
public void testAggregate_emptyExchanged_addTx() {
    TxTimeoutCondition timoutCondition = mock(TxTimeoutCondition.class);
    TxCompletionCondition condition = mock(TxCompletionCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(condition, timoutCondition);
    CamelContext context = mock(CamelContext.class);
    DefaultExchange newExchange = new DefaultExchange(context);
    Tx tx = mock(Tx.class);
    newExchange.getIn().setBody(tx);
    Exchange ex = aggr.aggregate(null, newExchange);
    @SuppressWarnings("unchecked") Collection<Tx> txs = ex.getIn().getBody(Collection.class);
    assertEquals(1, txs.size());
    assertEquals(tx, txs.iterator().next());
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) Test(org.junit.Test)

Example 8 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition in project nhin-d by DirectProject.

the class BasicTxAggregator_constructionTest method costructAggregator.

@Test
public void costructAggregator() {
    TxTimeoutCondition timoutCondition = mock(TxTimeoutCondition.class);
    TxCompletionCondition condition = mock(TxCompletionCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(condition, timoutCondition);
    assertNotNull(aggr);
    assertEquals(timoutCondition, aggr.timeoutCondition);
    assertEquals(condition, aggr.completionCondition);
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) Test(org.junit.Test)

Example 9 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition in project nhin-d by DirectProject.

the class BasicTxAggregator_getAggregationTimeTest method testIsComplete_txsExists_propertyExists_assertTimeoutValue.

@SuppressWarnings("unchecked")
@Test
public void testIsComplete_txsExists_propertyExists_assertTimeoutValue() {
    final Date theDate = new Date();
    TxTimeoutCondition condition = mock(TxTimeoutCondition.class);
    when(condition.getTimeout((Collection<Tx>) any(), eq(theDate.getTime()))).thenReturn(Long.valueOf(1000));
    BasicTxAggregator aggr = new BasicTxAggregator(null, condition);
    Tx tx = mock(Tx.class);
    Collection<Tx> oldTxs = new ArrayList<Tx>();
    oldTxs.add(tx);
    Message msg = mock(Message.class);
    when(msg.getBody(Collection.class)).thenReturn(oldTxs);
    Exchange exchange = mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    when(exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class)).thenReturn(theDate);
    assertEquals(Long.valueOf(1000), aggr.getAggregationTime(exchange));
    verify(exchange, times(1)).getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) Message(org.apache.camel.Message) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 10 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition in project nhin-d by DirectProject.

the class BasicTxAggregator_getAggregationTimeTest method testGetAggregationTime_emptyTxs_assertNull.

@Test
public void testGetAggregationTime_emptyTxs_assertNull() {
    TxTimeoutCondition condition = mock(TxTimeoutCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(null, condition);
    Message msg = mock(Message.class);
    when(msg.getBody(Collection.class)).thenReturn(null);
    Exchange exchange = mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    assertNull(aggr.getAggregationTime(exchange));
    verify(exchange, never()).getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) Test(org.junit.Test)

Aggregations

TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)13 Test (org.junit.Test)12 Tx (org.nhindirect.common.tx.model.Tx)8 ArrayList (java.util.ArrayList)6 Exchange (org.apache.camel.Exchange)5 Message (org.apache.camel.Message)3 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)3 CamelContext (org.apache.camel.CamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Date (java.util.Date)1