Skip to content

Commit

Permalink
[fix][broker] Fix creating system namespace topic failure. (#14949)
Browse files Browse the repository at this point in the history
(cherry picked from commit f3b87b6)
  • Loading branch information
Technoboy- authored and codelipenghui committed Apr 19, 2022
1 parent b3cddf2 commit bfeee50
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.pulsar.broker.PulsarService.isTransactionSystemTopic;
import static org.apache.pulsar.common.events.EventsTopicNames.checkTopicIsEventsNames;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -2708,7 +2707,7 @@ public boolean isAllowAutoTopicCreation(final String topic) {

public boolean isAllowAutoTopicCreation(final TopicName topicName) {
//System topic can always be created automatically
if (pulsar.getConfiguration().isSystemTopicEnabled() && checkTopicIsEventsNames(topicName)) {
if (pulsar.getConfiguration().isSystemTopicEnabled() && isSystemTopic(topicName)) {
return true;
}
AutoTopicCreationOverride autoTopicCreationOverride = getAutoTopicCreationOverride(topicName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@
package org.apache.pulsar.broker.systopic;

import com.google.common.collect.Sets;
import lombok.Cleanup;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.pulsar.broker.service.BrokerTestBase;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.SubscriptionInitialPosition;
import org.apache.pulsar.client.api.SubscriptionType;
import org.apache.pulsar.common.events.EventsTopicNames;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.policies.data.TenantInfo;
import org.apache.pulsar.common.policies.data.TenantInfoImpl;
import org.apache.pulsar.common.util.FutureUtil;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@Test(groups = "broker")
public class PartitionedSystemTopicTest extends BrokerTestBase {
Expand Down Expand Up @@ -104,4 +111,28 @@ public void testConsumerCreationWhenEnablingTopicPolicy() throws Exception {
}
}

@Test
public void testProduceAndConsumeUnderSystemNamespace() throws Exception {
TenantInfo tenantInfo = TenantInfo
.builder()
.adminRoles(Sets.newHashSet("admin"))
.allowedClusters(Sets.newHashSet("test"))
.build();
admin.tenants().createTenant("pulsar", tenantInfo);
admin.namespaces().createNamespace("pulsar/system", 2);
@Cleanup
Producer<byte[]> producer = pulsarClient.newProducer().topic("pulsar/system/__topic-1").create();
producer.send("test".getBytes(StandardCharsets.UTF_8));
@Cleanup
Consumer<byte[]> consumer = pulsarClient
.newConsumer()
.topic("pulsar/system/__topic-1")
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.subscriptionName("sub1")
.subscriptionType(SubscriptionType.Shared)
.subscribe();
Message<byte[]> receive = consumer.receive(5, TimeUnit.SECONDS);
Assert.assertNotNull(receive);
}

}

0 comments on commit bfeee50

Please sign in to comment.