RobertIndie commented on code in PR #22797:
URL: https://github.com/apache/pulsar/pull/22797#discussion_r1630652327
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/ShadowTopicTest.java:
##########
@@ -113,6 +116,52 @@ public void testPartitionedShadowTopicSetup() throws
Exception {
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().get().toString(),
sourceTopicPartition);
}
+ @Test
+ public void testPartitionedShadowTopicProduceAndConsume() throws Exception
{
+ String sourceTopic = newShadowSourceTopicName();
+ String shadowTopic = sourceTopic + "-shadow";
+ admin.topics().createPartitionedTopic(sourceTopic, 3);
+ admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+
+ // We should not allow to set with the shadow partition topic which
contains `-partition-n`.
+ Assert.assertThrows(PulsarAdminException.class, ()->
admin.topics().setShadowTopics(sourceTopic,
Lists.newArrayList(shadowTopic+"-partition-0")));
+ admin.topics().setShadowTopics(sourceTopic,
Lists.newArrayList(shadowTopic));
+
+ @Cleanup
+ Producer<String> producer =
pulsarClient.newProducer(Schema.STRING).topic(sourceTopic).create();
+ @Cleanup
+ Consumer<String> consumer =
pulsarClient.newConsumer(Schema.STRING).topic(shadowTopic).subscriptionName("test")
+ .subscribe();
+
+ for (int i = 0; i < 10; i++) {
+ producer.send("msg-" + i);
+ }
+
+ Set<String> set = new HashSet<>();
+ for (int i = 0; i < 10; i++) {
+ Message<String> msg = consumer.receive();
+ set.add(msg.getValue());
+ }
+ for (int i = 0; i < 10; i++) {
+ Assert.assertTrue(set.contains("msg-" + i));
+ }
+ }
+
+ @Test
+ public void testPartitionedShadowTopicExpansion() throws Exception {
+ String sourceTopic = newShadowSourceTopicName();
+ String shadowTopic = sourceTopic + "-shadow";
+ admin.topics().createPartitionedTopic(sourceTopic, 1);
+ admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+ admin.topics().setShadowTopics(sourceTopic,
Lists.newArrayList(shadowTopic));
+
+ Assert.assertThrows(PulsarAdminException.class, () ->
admin.topics().updatePartitionedTopic(sourceTopic, 3));
+
+ admin.topics().updatePartitionedTopic(shadowTopic, 3);
+
+ admin.topics().updatePartitionedTopic(sourceTopic, 3);
Review Comment:
This makes sense to me. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]