Skip to content

Commit

Permalink
Set topic created by AoP could not be auto-deleted in GC. (#103)
Browse files Browse the repository at this point in the history
### Motivation

Fix [https://github.com/streamnative/aop/issues/72](https://github.com/streamnative/aop/issues/72)

### Modifications

When a new topic created by AoP, set deleteWhileInactive in topic to false, so that the topic
could not be included in GC.
  • Loading branch information
zhanghaou authored Jun 13, 2020
1 parent 62c53f9 commit dc711b4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.service.AbstractTopic;
import org.apache.pulsar.broker.service.Topic;
import org.apache.pulsar.common.naming.TopicName;

Expand Down Expand Up @@ -61,6 +62,8 @@ public static CompletableFuture<Topic> getTopic(PulsarService pulsarService, Str
try {
if (topicOptional.isPresent()) {
Topic topic = topicOptional.get();
AbstractTopic abstractTopic = (AbstractTopic) topic;
abstractTopic.setDeleteWhileInactive(false);
topicCompletableFuture.complete(topic);
} else {
log.error("Get empty topic for name {}", topicName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.streamnative.pulsar.handlers.amqp.test;

import io.streamnative.pulsar.handlers.amqp.AmqpTopicManager;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.service.AbstractTopic;
import org.junit.Assert;
import org.testng.annotations.Test;

/**
* Unit test for Pulsar Topic.
*/
public class AmqpTopicManagerTest extends AmqpProtocolTestBase {

@Test
public void testDeleteWhileInactiveIsFalse() {
PulsarService pulsarService = connection.getPulsarService();
AbstractTopic abstractTopic = (AbstractTopic) AmqpTopicManager.getOrCreateTopic(pulsarService,
"public/vhost1/test", true);
Assert.assertFalse(abstractTopic.isDeleteWhileInactive());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.common.policies.data.ClusterData;
import org.apache.pulsar.common.policies.data.RetentionPolicies;
import org.apache.pulsar.common.policies.data.TenantInfo;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -73,8 +72,6 @@ public void setup() throws Exception {
String ns = "public/" + vhost;
if (!admin.namespaces().getNamespaces("public").contains(ns)) {
admin.namespaces().createNamespace(ns, 1);
admin.namespaces().setRetention(ns,
new RetentionPolicies(60, 1000));
}
}
checkPulsarServiceState();
Expand Down

0 comments on commit dc711b4

Please sign in to comment.