|
38 | 38 | import lombok.Cleanup;
|
39 | 39 | import lombok.extern.slf4j.Slf4j;
|
40 | 40 | import org.apache.bookkeeper.client.BookKeeper;
|
| 41 | +import org.apache.bookkeeper.mledger.ManagedLedgerConfig; |
41 | 42 | import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
|
42 | 43 | import org.apache.pulsar.client.api.Message;
|
43 | 44 | import org.apache.pulsar.client.api.MessageId;
|
44 | 45 | import org.apache.pulsar.client.api.Producer;
|
45 | 46 | import org.apache.pulsar.client.api.PulsarClient;
|
46 | 47 | import org.apache.pulsar.client.api.Reader;
|
47 | 48 | import org.apache.pulsar.client.api.Schema;
|
| 49 | +import org.apache.pulsar.common.naming.SystemTopicNames; |
| 50 | +import org.apache.pulsar.common.naming.TopicName; |
48 | 51 | import org.apache.pulsar.common.policies.data.ClusterData;
|
| 52 | +import org.apache.pulsar.common.policies.data.RetentionPolicies; |
49 | 53 | import org.apache.pulsar.common.policies.data.TenantInfoImpl;
|
50 | 54 | import org.awaitility.Awaitility;
|
| 55 | +import org.testng.Assert; |
51 | 56 | import org.testng.annotations.AfterMethod;
|
52 | 57 | import org.testng.annotations.BeforeMethod;
|
53 | 58 | import org.testng.annotations.Test;
|
@@ -212,6 +217,49 @@ public void testCompactionRetentionOnTopicCreationWithTopicPolicies() throws Exc
|
212 | 217 | );
|
213 | 218 | }
|
214 | 219 |
|
| 220 | + @Test |
| 221 | + public void testRetentionPolicesForSystemTopic() throws Exception { |
| 222 | + String namespace = "my-tenant/my-ns"; |
| 223 | + String topicPrefix = "persistent://" + namespace + "/"; |
| 224 | + admin.namespaces().setRetention(namespace, new RetentionPolicies(-1, -1)); |
| 225 | + // Check event topics and transaction internal topics. |
| 226 | + for (String eventTopic : SystemTopicNames.EVENTS_TOPIC_NAMES) { |
| 227 | + checkSystemTopicRetentionPolicy(topicPrefix + eventTopic); |
| 228 | + } |
| 229 | + checkSystemTopicRetentionPolicy(topicPrefix + SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN); |
| 230 | + checkSystemTopicRetentionPolicy(topicPrefix + SystemTopicNames.TRANSACTION_COORDINATOR_LOG); |
| 231 | + checkSystemTopicRetentionPolicy(topicPrefix + SystemTopicNames.PENDING_ACK_STORE_SUFFIX); |
| 232 | + |
| 233 | + // Check common topics. |
| 234 | + checkCommonTopicRetentionPolicy(topicPrefix + "my-topic" + System.nanoTime()); |
| 235 | + // Specify retention policies for system topic. |
| 236 | + pulsar.getConfiguration().setTopicLevelPoliciesEnabled(true); |
| 237 | + pulsar.getConfiguration().setSystemTopicEnabled(true); |
| 238 | + admin.topics().createNonPartitionedTopic(topicPrefix + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT); |
| 239 | + admin.topicPolicies().setRetention(topicPrefix + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT, |
| 240 | + new RetentionPolicies(10, 10)); |
| 241 | + Awaitility.await().untilAsserted(() -> { |
| 242 | + checkTopicRetentionPolicy(topicPrefix + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT, |
| 243 | + new RetentionPolicies(10, 10)); |
| 244 | + }); |
| 245 | + } |
| 246 | + |
| 247 | + private void checkSystemTopicRetentionPolicy(String topicName) throws Exception { |
| 248 | + checkTopicRetentionPolicy(topicName, new RetentionPolicies(0, 0)); |
| 249 | + |
| 250 | + } |
| 251 | + |
| 252 | + private void checkCommonTopicRetentionPolicy(String topicName) throws Exception { |
| 253 | + checkTopicRetentionPolicy(topicName, new RetentionPolicies(-1, -1)); |
| 254 | + } |
| 255 | + |
| 256 | + private void checkTopicRetentionPolicy(String topicName, RetentionPolicies retentionPolicies) throws Exception { |
| 257 | + ManagedLedgerConfig config = pulsar.getBrokerService() |
| 258 | + .getManagedLedgerConfig(TopicName.get(topicName)).get(); |
| 259 | + Assert.assertEquals(config.getRetentionSizeInMB(), retentionPolicies.getRetentionSizeInMB()); |
| 260 | + Assert.assertEquals(config.getRetentionTimeMillis(),retentionPolicies.getRetentionTimeInMinutes() * 60000L); |
| 261 | + } |
| 262 | + |
215 | 263 | private void testCompactionCursorRetention(String topic) throws Exception {
|
216 | 264 | Set<String> keys = Sets.newHashSet("a", "b", "c");
|
217 | 265 | Set<String> keysToExpire = Sets.newHashSet("x1", "x2");
|
|
0 commit comments