diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java index 96f8822a72b01..355036bdb25ce 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java @@ -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); @@ -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); @@ -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(); @@ -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);