}
protected void runSimpleTest(final boolean syncSend, final boolean syncReceive) throws Exception {
// final int numMessages = 1;
final int numMessages = NUM_MESSAGES;
final SenderComponent sender = new SenderComponent();
sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
final Receiver receiver;
final Map delivered = new ConcurrentHashMap();
if (syncReceive) {
receiver = new ReceiverComponent() {
public void onMessageExchange(MessageExchange exchange) throws MessagingException {
try {
if (delivered.get(exchange.getExchangeId()) == null) {
AbstractPersistenceTest.LOGGER.info("Message delivery rolled back: {}", exchange.getExchangeId());
delivered.put(exchange.getExchangeId(), Boolean.TRUE);
tm.setRollbackOnly();
} else {
AbstractPersistenceTest.LOGGER.info("Message delivery accepted: {}", exchange.getExchangeId());
super.onMessageExchange(exchange);
}
} catch (Exception e) {
throw new MessagingException(e);
}
}
};
} else {
receiver = new AsyncReceiverPojo() {
public void onMessageExchange(MessageExchange exchange) throws MessagingException {
try {
if (delivered.get(exchange.getExchangeId()) == null) {
LOGGER.info("Message delivery rolled back: {}", exchange.getExchangeId());
delivered.put(exchange.getExchangeId(), Boolean.TRUE);
tm.setRollbackOnly();
exchange.setStatus(ExchangeStatus.DONE);
getContext().getDeliveryChannel().send(exchange);
} else {
LOGGER.info("Message delivery accepted: {}", exchange.getExchangeId());
super.onMessageExchange(exchange);
}
} catch (Exception e) {
throw new MessagingException(e);
}
}
};
}
senderContainer.activateComponent(new ActivationSpec("sender", sender));
senderContainer.activateComponent(new ActivationSpec("receiver", receiver));
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
sender.sendMessages(numMessages, syncSend);
} catch (JBIException e) {
throw new RuntimeJBIException(e);
}
return null;
}