@SuppressWarnings("deprecation")
@Test(timeout=60000)
public void testReadTimeout() throws Exception {
final AtomicBoolean completed = new AtomicBoolean(false);
LedgerHandle writelh = bkc.createLedger(3,3,digestType, "testPasswd".getBytes());
String tmp = "Foobar";
final int numEntries = 10;
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
Set<InetSocketAddress> beforeSet = new HashSet<InetSocketAddress>();
for (InetSocketAddress addr : writelh.getLedgerMetadata().getEnsemble(numEntries)) {
beforeSet.add(addr);
}
final InetSocketAddress bookieToSleep
= writelh.getLedgerMetadata().getEnsemble(numEntries).get(0);
int sleeptime = baseClientConf.getReadTimeout()*3;
CountDownLatch latch = sleepBookie(bookieToSleep, sleeptime);
latch.await();
writelh.asyncAddEntry(tmp.getBytes(),
new AddCallback() {
public void addComplete(int rc, LedgerHandle lh,
long entryId, Object ctx) {
completed.set(true);
}
}, null);
Thread.sleep((baseClientConf.getReadTimeout()*3)*1000);
Assert.assertTrue("Write request did not finish", completed.get());
Set<InetSocketAddress> afterSet = new HashSet<InetSocketAddress>();
for (InetSocketAddress addr : writelh.getLedgerMetadata().getEnsemble(numEntries+1)) {
afterSet.add(addr);
}
beforeSet.removeAll(afterSet);
Assert.assertTrue("Bookie set should not match", beforeSet.size() != 0);
}