We are using the Scheduled Executor, and with some operation systems... a scheduler.schedule(in 30 seconds) is calling our Runnable in less time than you are supposed to. I have seen this issue happening on Windows quite a lot actually.
Make sure you understand the schedule time is based on the server's time (not on the client's time). Sync your client time against your servers.
We have recently done a lot of improvements on 2.4.0, and I don't think you would hit this issue again as we now validate the time of the time and don't trust the ScheduledExecutor any longer.
if you update your OS you won't see this issue.. it's usually a kernel issue around real time and not having the waits being respected.
Or if you could use 2.4.0 which is not trusting this behaviour any longer.
I've tried this code using 2.2.eap5 on MAC without the patch on 2.4.0 and it worked. which is pretty much your test converted to java.
public void testSomething() throws Exception
{
// then we create a client as normal
ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession receiverSession = sessionFactory.createSession(true, true, 0);
ClientSession senderSession = sessionFactory.createSession(true, true, 0);
String queue = "atestq";
ClientSession.QueueQuery query = senderSession.queueQuery(new SimpleString(queue));
if (query == null || !query.isExists()) senderSession.createQueue(queue, queue, false);
ClientProducer producer = senderSession.createProducer(queue);
ClientMessage message = senderSession.createMessage(false);
message.getBodyBuffer().writeString("This is my string........");
long original = System.currentTimeMillis();
long deliverytime = System.currentTimeMillis() + 30000;
message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, deliverytime);
System.out.println("Message Sent " + deliverytime);
senderSession.start();
producer.send(message);
receiverSession.start();
ClientConsumer consumer = receiverSession.createConsumer(queue);
ClientMessage message2 = consumer.receive(50000);
String messageBody = message2.getBodyBuffer().readString();
System.out.println("received message: " + messageBody + " after" + ((System.currentTimeMillis() - original) / 1000) + " seconds ");
assert (messageBody.equals("This is my string........"));
message2.acknowledge();
}
I have just raised a feature request within HornetQ for this.