final Object lock = new Object();
// TODO check if MockTaskProcessor can be used here
final DefaultTaskFactory _defaultTaskFactory = new DefaultTaskFactory(getConfiguration());
addDisposable(_defaultTaskFactory);
DefaultTaskProcessor _taskProcessor = new DefaultTaskProcessor(getConfiguration(), _defaultTaskFactory)
{
public void processMessageInternal(Message event)
{
synchronized (lock)
{
try
{
long _recvTime = System.currentTimeMillis();
assertEquals("unexpected event", event, _event);
assertTrue("received too late", _recvTime <= _time.getTime());
_received.add(event);
} finally
{
lock.notifyAll();
}
}
}
};
_taskProcessor.processMessage(_event);
long timeoutF = System.currentTimeMillis() + timeout;
synchronized(lock)
{
while (!_received.contains(_event) && System.currentTimeMillis() < timeoutF)
{
lock.wait(timeout);
}
}
if (receive)
{
assertTrue("should have received something", _received.contains(_event));
}
else
{
assertTrue("shouldn't", !_received.contains(_event));
}
_taskProcessor.dispose();
}