testPusherStatus(PusherStatus.LOW_MEMORY, 500L, 2000L, 2, 2 * 500L);
}
private void testPusherStatus(PusherStatus status, long shortSleep,
long longSleep, int retries, long expectedDelay) throws Exception {
SystemClock clock = new SystemClock();
String connectorName = getName();
Document document = ConnectorTestUtils.createSimpleDocument("foo");
MockPusher pusher = new MockPusher();
DocumentAcceptorImpl documentAcceptor =
new DocumentAcceptorImpl(connectorName, pusher);
documentAcceptor.setSleepIntervals(shortSleep, longSleep, retries);
// Initial document feed should go unimpeded.
long startTime = clock.getTimeMillis();
documentAcceptor.take(document);
long stopTime = clock.getTimeMillis();
assertEquals(1, pusher.getTotalDocs());
assertEquals(PusherStatus.OK, pusher.getPusherStatus());
assertTrue("Delay too long " + (stopTime - startTime),
shortSleep > (stopTime - startTime));
// If pusher returns not-ready status, documentAcceptor should sleep.
pusher.setPusherStatus(status);
startTime = clock.getTimeMillis();
documentAcceptor.take(document);
stopTime = clock.getTimeMillis();
assertEquals(2, pusher.getTotalDocs());
assertTrue("Delay " + (stopTime - startTime),
expectedDelay <= (stopTime - startTime));
// Once the Pusher is OK, there should be no delays.
pusher.setPusherStatus(PusherStatus.OK);
startTime = clock.getTimeMillis();
documentAcceptor.take(document);
stopTime = clock.getTimeMillis();
assertEquals(3, pusher.getTotalDocs());
assertTrue("Delay " + (stopTime - startTime),
shortSleep > (stopTime - startTime));
}