assertNull(result);
}
public void testTransactionsWithCommit() throws Exception
{
final MuleClient client = new MuleClient(muleContext);
final Map<String, Object> props = new HashMap<String, Object>();
props.put("JMSReplyTo", "replyTo.queue");
props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, "false");
props.put("transacted", "true");
// Empty reply queue
while (client.request("jms://replyTo.queue", 2000) != null)
{
// yum!
}
MuleTransactionConfig tc = new MuleTransactionConfig();
tc.setFactory(new JmsTransactionFactory());
tc.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
// This enpoint needs to be registered prior to use cause we need to set
// the transaction config so that the endpoint will "know" it is transacted
// and not close the session itself but leave it up to the transaction.
EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(
new URIBuilder("jms://test.queue", muleContext));
endpointBuilder.setTransactionConfig(tc);
endpointBuilder.setName("TransactedTest.Queue");
ImmutableEndpoint inboundEndpoint = muleContext.getRegistry()
.lookupEndpointFactory()
.getOutboundEndpoint(endpointBuilder);
client.getMuleContext().getRegistry().registerEndpoint(inboundEndpoint);
TransactionTemplate<Void> tt = new TransactionTemplate<Void>(tc, muleContext);
tt.execute(new TransactionCallback<Void>()
{
public Void doInTransaction() throws Exception
{
for (int i = 0; i < 100; i++)
{
client.send("jms://test.queue", "Test Client Dispatch message " + i, props);
}
return null;
}
});
for (int i = 0; i < 100; i++)
{
MuleMessage result = client.request("jms://replyTo.queue", 2000);
assertNotNull(result);
}
MuleMessage result = client.request("jms://replyTo.queue", 2000);
assertNull(result);
}