public void testReceiveTimeoutPreservation() throws Exception
{
final long timeToWaitForReceive = 5000;
final Latch receiverLatch = new Latch();
// start the receiver thread
Thread receiverThread = new Thread(new Runnable()
{
public void run()
{
try
{
long t1 = System.currentTimeMillis();
expectedMessage = queueConsumer.receive(timeToWaitForReceive);
effectiveReceiveTime = System.currentTimeMillis() - t1;
}
catch(Exception e)
{
log.trace("receive() exits with an exception", e);
}
finally
{
receiverLatch.release();
}
}
}, "receiver thread");
receiverThread.start();
final Latch senderLatch = new Latch();
// start the sender thread
Thread senderThread = new Thread(new Runnable()
{
public void run()
{
try
{
// wait for 3 secs
Thread.sleep(3000);
// send an expired message
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, -1);
JBossMessage jbm = ((MessageProxy)m).getMessage();
if (!jbm.isExpired())
{
log.error("The message " + m + " should have expired");
testFailed = true;
return;
}
}
catch(Exception e)
{
log.error("This exception will fail the test", e);
testFailed = true;
}
finally
{
senderLatch.release();
}
}
}, "sender thread");
senderThread.start();
senderLatch.acquire();
receiverLatch.acquire();
if (testFailed)
{
fail("Test failed by the sender thread. Watch for exception in logs");