}
@Test(timeout=60000)
public void testLedgerGC() throws Exception {
Client client = new HedwigClient(new MessageBoundClientConfiguration());
Publisher pub = client.getPublisher();
Subscriber sub = client.getSubscriber();
String ledgersPath = "/hedwig/standalone/topics/testGCTopic/ledgers";
ByteString topic = ByteString.copyFromUtf8("testGCTopic");
ByteString subid = ByteString.copyFromUtf8("testGCSubId");
sub.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH);
sub.closeSubscription(topic, subid);
for (int i = 1; i <= 100; i++) {
pub.publish(topic, Message.newBuilder().setBody(
ByteString.copyFromUtf8(String.valueOf(i))).build());
}
LedgerRanges r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
assertEquals("Should only have 1 ledger yet", 1, r.getRangesList().size());
long firstLedger = r.getRangesList().get(0).getLedgerId();
stopHubServers();
startHubServers();
pub.publish(topic, Message.newBuilder().setBody(
ByteString.copyFromUtf8(String.valueOf(0xdeadbeef))).build());
r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
assertEquals("Should have 2 ledgers after restart", 2, r.getRangesList().size());
for (int i = 100; i <= 200; i++) {
pub.publish(topic, Message.newBuilder().setBody(
ByteString.copyFromUtf8(String.valueOf(i))).build());
}
Thread.sleep(5000); // give GC a chance to happen
r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));