Skip to content

Commit

Permalink
[fix][flaky-test]ConsumedLedgersTrimTest (apache#17116)
Browse files Browse the repository at this point in the history
  • Loading branch information
poorbarcode authored Aug 18, 2022
1 parent 4b98b23 commit f6fd6b7
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ protected void cleanup() throws Exception {
super.internalCleanup();
}

@Override
protected void doInitConf() throws Exception {
super.doInitConf();
super.conf.setDefaultRetentionSizeInMB(-1);
super.conf.setDefaultRetentionTimeInMinutes(-1);
}

@Test
public void TestConsumedLedgersTrim() throws Exception {
conf.setRetentionCheckIntervalInSeconds(1);
Expand Down Expand Up @@ -96,7 +103,6 @@ public void TestConsumedLedgersTrim() throws Exception {
assertNotNull(msg);
consumer.acknowledge(msg);
}
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), msgNum / 2);

//no traffic, but consumed ledger will be cleaned
Thread.sleep(1500);
Expand All @@ -123,7 +129,7 @@ public void testConsumedLedgersTrimNoSubscriptions() throws Exception {
PersistentTopic persistentTopic = (PersistentTopic) pulsar.getBrokerService().getOrCreateTopic(topicName).get();
ManagedLedgerConfig managedLedgerConfig = persistentTopic.getManagedLedger().getConfig();
managedLedgerConfig.setRetentionSizeInMB(-1);
managedLedgerConfig.setRetentionTime(1, TimeUnit.SECONDS);
managedLedgerConfig.setRetentionTime(-1, TimeUnit.SECONDS);
managedLedgerConfig.setMaxEntriesPerLedger(1000);
managedLedgerConfig.setMinimumRolloverTime(1, TimeUnit.MILLISECONDS);
MessageId initialMessageId = persistentTopic.getLastMessageId().get();
Expand All @@ -150,15 +156,15 @@ public void testConsumedLedgersTrimNoSubscriptions() throws Exception {
assertEquals(messageIdAfterRestart, messageIdBeforeRestart);

persistentTopic = (PersistentTopic) pulsar.getBrokerService().getOrCreateTopic(topicName).get();
managedLedger = (ManagedLedgerImpl) persistentTopic.getManagedLedger();
// now we have two ledgers, the first is expired but is contains the lastMessageId
// the second is empty and should be kept as it is the current tail
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), 2);
managedLedgerConfig = persistentTopic.getManagedLedger().getConfig();
managedLedgerConfig.setRetentionSizeInMB(-1);
managedLedgerConfig.setRetentionTime(1, TimeUnit.SECONDS);
managedLedgerConfig.setMaxEntriesPerLedger(1);
managedLedgerConfig.setMinimumRolloverTime(1, TimeUnit.MILLISECONDS);
managedLedger = (ManagedLedgerImpl) persistentTopic.getManagedLedger();
// now we have two ledgers, the first is expired but is contains the lastMessageId
// the second is empty and should be kept as it is the current tail
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), 2);

// force trimConsumedLedgers
Thread.sleep(3000);
Expand Down

0 comments on commit f6fd6b7

Please sign in to comment.