Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,32 @@
assertTrue(ex.getCause() instanceof NotAcceptableException);
}
}

@Test
public void testAutoTopicCreationOverrideNonPartitionedDefaultNumPartitionsIgnored() throws Exception {
String tenantName = newUniqueName("prop-xyz2");
String namespaceName = tenantName + "/ns-" + System.currentTimeMillis();
TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test"));
admin.tenants().createTenant(tenantName, tenantInfo);
admin.namespaces().createNamespace(namespaceName, Set.of("test"));

AutoTopicCreationOverride overridePolicy = AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(true)
.topicType(TopicType.NON_PARTITIONED.toString())
.defaultNumPartitions(5)
.build();
admin.namespaces().setAutoTopicCreation(namespaceName, overridePolicy);

Check failure on line 2475 in pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java

View workflow job for this annotation

GitHub Actions / CI - Unit - Brokers - Broker Group 3

AdminApi2Test.testAutoTopicCreationOverrideNonPartitionedDefaultNumPartitionsIgnored

Invalid configuration for autoTopicCreationOverride. the detail is [defaultNumPartitions] must be null, 0 or 1 when the type is non-partitioned.

AutoTopicCreationOverride storedPolicy = admin.namespaces().getAutoTopicCreation(namespaceName);
assertTrue(storedPolicy.isAllowAutoTopicCreation());
assertEquals(storedPolicy.getTopicType(), TopicType.NON_PARTITIONED.toString());
assertEquals(storedPolicy.getDefaultNumPartitions(), Integer.valueOf(5));

String topicName = "persistent://" + namespaceName + "/auto-topic-" + UUID.randomUUID();
pulsarClient.newProducer().topic(topicName).create().close();

assertEquals(admin.topics().getPartitionedTopicMetadata(topicName).partitions, 0);
}
@Test
public void testMaxTopicsPerNamespace() throws Exception {
restartClusterAfterTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static ValidateResult validateOverride(AutoTopicCreationOverride override
if (!TopicType.isValidTopicType(override.getTopicType())) {
return ValidateResult.fail(String.format("Unknown topic type [%s]", override.getTopicType()));
}

if (TopicType.PARTITIONED.toString().equals(override.getTopicType())) {
if (override.getDefaultNumPartitions() == null) {
return ValidateResult.fail("[defaultNumPartitions] cannot be null when the type is partitioned.");
Expand All @@ -52,9 +53,10 @@ public static ValidateResult validateOverride(AutoTopicCreationOverride override
return ValidateResult.fail("[defaultNumPartitions] cannot be less than 1 for partition type.");
}
} else if (TopicType.NON_PARTITIONED.toString().equals(override.getTopicType())) {
if (override.getDefaultNumPartitions() != null) {
return ValidateResult.fail("[defaultNumPartitions] is not allowed to be"
Comment thread
lhotari marked this conversation as resolved.
+ " set when the type is non-partition.");
Integer p = override.getDefaultNumPartitions();
if (p != null && p != 0 && p != 1) {
return ValidateResult.fail(
"[defaultNumPartitions] must be null, 0 or 1 when the type is non-partitioned.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,34 @@ public void testNumPartitionsNotSet() {
}

@Test
public void testNumPartitionsOnNonPartitioned() {
public void testNumPartitionsOnNonPartitionedZeroAllowed() {
AutoTopicCreationOverride override = AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(true)
.topicType(TopicType.NON_PARTITIONED.toString())
.defaultNumPartitions(0)
.build();
assertTrue(AutoTopicCreationOverrideImpl.validateOverride(override).isSuccess());
}

@Test
public void testNumPartitionsOnNonPartitionedOneAllowed() {
AutoTopicCreationOverride override = AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(true)
.topicType(TopicType.NON_PARTITIONED.toString())
.defaultNumPartitions(1)
.build();
assertTrue(AutoTopicCreationOverrideImpl.validateOverride(override).isSuccess());
}


@Test
public void testNumPartitionsOnNonPartitionedTooHighRejected() {
AutoTopicCreationOverride override = AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(true)
.topicType(TopicType.NON_PARTITIONED.toString())
.defaultNumPartitions(2)
.build();
assertFalse(AutoTopicCreationOverrideImpl.validateOverride(override).isSuccess());
}

}
Loading