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