Fixed updating partitioned topic without subscriptions
@@ -23,6 +23,8 @@ import static org.testng.Assert.assertEquals;
import org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.ClusterData;
import org.apache.pulsar.common.policies.data.TenantInfo;
@@ -33,6 +35,8 @@ import org.testng.annotations.Test;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import lombok.Cleanup;
+
public class IncrementPartitionsTest extends MockedPulsarServiceBaseTest {
private MockedPulsarService mockPulsarSetup;
@@ -97,4 +101,26 @@ public class IncrementPartitionsTest extends MockedPulsarServiceBaseTest {
consumer.close();
}
+
+ @Test
+ public void testIncrementPartitionsWithNoSubscriptions() throws Exception {
+ final String partitionedTopicName = "persistent://prop-xyz/use/ns1/test-topic-" + System.nanoTime();
+
+ admin.topics().createPartitionedTopic(partitionedTopicName, 1);
+ assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 1);
+
+ @Cleanup
+ Producer<String> consumer = pulsarClient.newProducer(Schema.STRING)
+ .topic(partitionedTopicName)
+ .create();
+
+ admin.topics().updatePartitionedTopic(partitionedTopicName, 2);
+ assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 2);
+
+ admin.topics().updatePartitionedTopic(partitionedTopicName, 10);
+ assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 10);
+
+ admin.topics().updatePartitionedTopic(partitionedTopicName, 20);
+ assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 20);
+ }
}
