public void testTarpit() throws ParseException {
long tarpitTime = 1000;
long tarpitTolerance = 100;
long startTime;
TarpitHandler handler = new TarpitHandler();
handler.setTarpitRcptCount(2);
handler.setTarpitSleepTime(tarpitTime);
// no tarpit used
startTime = System.currentTimeMillis();
handler.doRcpt(setupMockedSession(0),null,new MailAddress("test@test"));
assertTrue("No tarpit",
(System.currentTimeMillis() - startTime) < tarpitTime - tarpitTolerance);
// tarpit used
startTime = System.currentTimeMillis();
handler.doRcpt(setupMockedSession(3),null,new MailAddress("test@test"));
assertTrue("tarpit",
(System.currentTimeMillis() - startTime) >= tarpitTime - tarpitTolerance);
}