// succeed to delete second ledger
failedToDeleteLedgersTest(2);
}
private void failedToDeleteLedgersTest(int numLedgers) throws Exception {
final ByteString topic = ByteString.copyFromUtf8("TestFailedToDeleteLedger");
final int serviceDownCount = 1;
List<Message> msgs = new ArrayList<Message>();
for (int i=0; i<numLedgers; i++) {
acquireTopic(topic);
msgs.addAll(publishMessages(topic, 2));
releaseTopic(topic);
}
// acquire topic again to force a new ledger
acquireTopic(topic);
logger.info("Consumed messages.");
metadataManagerFactory.setServiceDownCount(serviceDownCount);
// failed consumed
consumedUntil(topic, 2L * numLedgers);
// Wait until ledger ranges is updated.
Thread.sleep(2000L);
logger.info("Released topic with an empty ledger.");
// release topic to force an empty ledger
releaseTopic(topic);
// publish 2 more messages, these message expected to be id 3 and 4
acquireTopic(topic);
logger.info("Published more messages.");
msgs.addAll(publishMessages(topic, 2));
releaseTopic(topic);
// acquire topic again
acquireTopic(topic);
LinkedBlockingQueue<Boolean> statusQueue =
new LinkedBlockingQueue<Boolean>();
manager.scanMessages(new RangeScanRequest(topic, numLedgers * 2 + 1, 2, Long.MAX_VALUE,
new RangeScanVerifier(subMessages(msgs, numLedgers * 2, numLedgers * 2 + 1), null), statusQueue));
Boolean b = statusQueue.poll(10 * readDelay, TimeUnit.MILLISECONDS);
assertTrue("Should succeed to scan messages after deleted consumed ledger.", b);
// consumed
consumedUntil(topic, (numLedgers + 1) * 2L);
// Wait until ledger ranges is updated.
Thread.sleep(2000L);
Semaphore latch = new Semaphore(1);
latch.acquire();
tpManager.readTopicPersistenceInfo(topic, new Callback<Versioned<LedgerRanges>>() {
@Override
public void operationFinished(Object ctx, Versioned<LedgerRanges> ranges) {
if (null == ranges || ranges.getValue().getRangesList().size() > 1) {
failureException = new PubSubException.NoTopicPersistenceInfoException("Invalid persistence info found for topic " + topic.toStringUtf8());
((Semaphore)ctx).release();
return;
}
failureException = null;
((Semaphore)ctx).release();