BewareMyPower commented on code in PR #21745:
URL: https://github.com/apache/pulsar/pull/21745#discussion_r1436976157
##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactionTest.java:
##########
@@ -2012,4 +2014,70 @@ public void testCompactionDuplicate() throws Exception {
}
}
}
+
+ @Test
+ public void testDeleteCompactedLedger() throws Exception {
+ String topicName =
"persistent://my-property/use/my-ns/testDeleteCompactedLedger";
+
+ final String subName = "my-sub";
+ @Cleanup
+ Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
+ .enableBatching(false).topic(topicName).create();
+
+
pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).readCompacted(true).subscribe().close();
+
+ for (int i = 0; i < 10; i++) {
+ producer.newMessage().key(String.valueOf(i %
2)).value(String.valueOf(i)).sendAsync();
+ }
+ producer.flush();
+
+ compact(topicName);
+
+ MutableLong compactedLedgerId = new MutableLong(-1);
+ Awaitility.await().untilAsserted(() -> {
+ PersistentTopicInternalStats stats =
admin.topics().getInternalStats(topicName);
+ Assert.assertNotEquals(stats.compactedLedger.ledgerId, -1L);
+ compactedLedgerId.setValue(stats.compactedLedger.ledgerId);
+ Assert.assertEquals(stats.compactedLedger.entries, 2L);
+ });
+
+ // delete compacted ledger
+ admin.topics().deleteSubscription(topicName, "__compaction");
+
+ Awaitility.await().untilAsserted(() -> {
+ PersistentTopicInternalStats stats =
admin.topics().getInternalStats(topicName);
+ Assert.assertEquals(stats.compactedLedger.ledgerId, -1L);
+ Assert.assertEquals(stats.compactedLedger.entries, -1L);
+ try {
+ pulsarTestContext.getBookKeeperClient()
+ .openLedger(compactedLedgerId.getValue(),
BookKeeper.DigestType.CRC32C, new byte[]{});
+ Assert.fail("Should fail");
+ } catch (BKException.BKNoSuchLedgerExistsException e) {
+ // ignore it
+ }
+ });
+
+ compact(topicName);
+
+ MutableLong compactedLedgerId2 = new MutableLong(-1);
+ Awaitility.await().untilAsserted(() -> {
+ PersistentTopicInternalStats stats =
admin.topics().getInternalStats(topicName);
+ Assert.assertNotEquals(stats.compactedLedger.ledgerId, -1L);
+ compactedLedgerId2.setValue(stats.compactedLedger.ledgerId);
+ Assert.assertEquals(stats.compactedLedger.entries, 2L);
+ });
+
+ producer.close();
+ admin.topics().delete(topicName);
+
+ Awaitility.await().untilAsserted(() -> {
+ try {
+ pulsarTestContext.getBookKeeperClient()
+ .openLedger(compactedLedgerId2.getValue(),
BookKeeper.DigestType.CRC32C, new byte[]{});
+ Assert.fail("Should fail");
+ } catch (BKException.BKNoSuchLedgerExistsException e) {
+ // ignore it
+ }
+ });
Review Comment:
```suggestion
Awaitility.await().untilAsserted(() ->
assertThrows(BKException.BKNoSuchLedgerExistsException.class,
() -> pulsarTestContext.getBookKeeperClient().openLedger(
compactedLedgerId2.getValue(),
BookKeeper.DigestType.CRC32, new byte[]{})));
```
##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactionTest.java:
##########
@@ -2012,4 +2014,70 @@ public void testCompactionDuplicate() throws Exception {
}
}
}
+
+ @Test
+ public void testDeleteCompactedLedger() throws Exception {
+ String topicName =
"persistent://my-property/use/my-ns/testDeleteCompactedLedger";
+
+ final String subName = "my-sub";
+ @Cleanup
+ Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
+ .enableBatching(false).topic(topicName).create();
+
+
pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).readCompacted(true).subscribe().close();
+
+ for (int i = 0; i < 10; i++) {
+ producer.newMessage().key(String.valueOf(i %
2)).value(String.valueOf(i)).sendAsync();
+ }
+ producer.flush();
+
+ compact(topicName);
+
+ MutableLong compactedLedgerId = new MutableLong(-1);
+ Awaitility.await().untilAsserted(() -> {
+ PersistentTopicInternalStats stats =
admin.topics().getInternalStats(topicName);
+ Assert.assertNotEquals(stats.compactedLedger.ledgerId, -1L);
+ compactedLedgerId.setValue(stats.compactedLedger.ledgerId);
+ Assert.assertEquals(stats.compactedLedger.entries, 2L);
+ });
+
+ // delete compacted ledger
+ admin.topics().deleteSubscription(topicName, "__compaction");
+
+ Awaitility.await().untilAsserted(() -> {
+ PersistentTopicInternalStats stats =
admin.topics().getInternalStats(topicName);
+ Assert.assertEquals(stats.compactedLedger.ledgerId, -1L);
+ Assert.assertEquals(stats.compactedLedger.entries, -1L);
+ try {
+ pulsarTestContext.getBookKeeperClient()
+ .openLedger(compactedLedgerId.getValue(),
BookKeeper.DigestType.CRC32C, new byte[]{});
+ Assert.fail("Should fail");
+ } catch (BKException.BKNoSuchLedgerExistsException e) {
+ // ignore it
+ }
Review Comment:
```suggestion
assertThrows(BKException.BKNoSuchLedgerExistsException.class, ()
-> pulsarTestContext.getBookKeeperClient()
.openLedger(compactedLedgerId.getValue(),
BookKeeper.DigestType.CRC32C, new byte[]{}));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]