public void testInsistentRetry() {
final MockClock m = new MockClock(0);
EventSink failWhale = new EventSink.Base() {
public ReportEvent getMetrics() {
return new ReportEvent("failwhale-report");
}
@Override
public void open() throws IOException {
// Forward by 100ms, should cause IOD to try eleven times then give up
m.forward(100);
throw new IOException("fail open");
}
};
Clock.setClock(m);
// max 1s, backoff initially at 10ms, with a maxSingleSleep 1000ms and a
// cumulative cap of 1000ms
InsistentOpenDecorator<EventSink> sink = new InsistentOpenDecorator<EventSink>(
failWhale, 1000, 10, 1000);
try {
sink.open();
} catch (IOException e1) {
ReportEvent rpt = sink.getMetrics();
assertEquals(new Long(1), rpt
.getLongMetric(InsistentOpenDecorator.A_REQUESTS));
assertEquals(new Long(0), rpt
.getLongMetric(InsistentOpenDecorator.A_SUCCESSES));
// 11 attempts - one each at 100 * x for x in [0,1,2,3,4,5,6,7,8,9,10]
// Retry trigger in IOD only fails when time > max, but passes when time =
// max.
assertEquals(new Long(11), rpt
.getLongMetric(InsistentOpenDecorator.A_ATTEMPTS));
assertEquals(new Long(11), rpt
.getLongMetric(InsistentOpenDecorator.A_RETRIES));
Clock.resetDefault();
return; // success
}
fail("Ehr? Somehow the failwhale succeeded!");