if(slm!=null) {
l = slm.acquireLock(shard);
}
// Consumer
MessageQueueDispatcher dispatcher = new MessageQueueDispatcher.Builder()
.withBatchSize(25)
.withCallback(new Function<MessageContext, Boolean>() {
@Override
public Boolean apply(MessageContext message) {
count.incrementAndGet();
return true;
}
})
.withMessageQueue(scheduler)
.withConsumerCount(10)
.withProcessorThreadCount(10)
.withAckInterval(20, TimeUnit.MILLISECONDS)
.withPollingInterval(15, TimeUnit.MILLISECONDS)
.build();
// Start the consumer
dispatcher.start();
// Release the lock
if(slm!=null) {
// Wait
Thread.sleep(1000);
slm.releaseLock(l);
}
// Wait another 10 seconds and then stop the dispatcher
Thread.sleep(1000);
dispatcher.stop();
assertEquals(queuedCount, count.intValue());
// Check the busy lock count
if(slm!=null) {
System.out.println("Lock attempts " + slm.getLockAttempts());