AnonHxy commented on code in PR #17711:
URL: https://github.com/apache/pulsar/pull/17711#discussion_r979613744


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/ShadowTopicTest.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.pulsar.broker.service.persistent;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.service.BrokerTestBase;
+import org.apache.pulsar.common.naming.TopicName;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class ShadowTopicTest extends BrokerTestBase {
+
+    @BeforeClass(alwaysRun = true)
+    @Override
+    protected void setup() throws Exception {
+        baseSetup();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    protected void cleanup() throws Exception {
+        internalCleanup();
+    }
+
+    @Test()
+    public void testNonPartitionedShadowTopicSetup() throws Exception {
+        String sourceTopic = "persistent://prop/ns-abc/source";
+        String shadowTopic = "persistent://prop/ns-abc/shadow";
+        //1. test shadow topic setting in topic creation.
+        admin.topics().createNonPartitionedTopic(sourceTopic);
+        admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+        PersistentTopic brokerShadowTopic =
+                (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+
+        //2. test shadow topic could be properly loaded after unload.
+        admin.namespaces().unload("prop/ns-abc");
+        
Assert.assertTrue(pulsar.getBrokerService().getTopicReference(shadowTopic).isEmpty());
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+        brokerShadowTopic = (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+    }
+
+    @Test()
+    public void testPartitionedShadowTopicSetup() throws Exception {
+        String sourceTopic = "persistent://prop/ns-abc/source-p";
+        String shadowTopic = "persistent://prop/ns-abc/shadow-p";
+        String shadowTopicPartition = 
TopicName.get(shadowTopic).getPartition(0).toString();
+
+        //1. test shadow topic setting in topic creation.
+        admin.topics().createPartitionedTopic(sourceTopic, 2);
+        admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+        
pulsarClient.newProducer().topic(shadowTopic).create().close();//trigger 
loading partitions.
+        PersistentTopic brokerShadowTopic = (PersistentTopic) 
pulsar.getBrokerService()
+                .getTopicIfExists(shadowTopicPartition).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+
+        //2. test shadow topic could be properly loaded after unload.
+        admin.namespaces().unload("prop/ns-abc");
+        
Assert.assertTrue(pulsar.getBrokerService().getTopicReference(shadowTopic).isEmpty());
+
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+        brokerShadowTopic =
+                (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopicPartition).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);

Review Comment:
   It's better verify the `ManagedLedger `of `brokerShadowTopic` is a 
`ShadowManagedLedgerImpl`



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/ShadowTopicTest.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.pulsar.broker.service.persistent;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.service.BrokerTestBase;
+import org.apache.pulsar.common.naming.TopicName;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class ShadowTopicTest extends BrokerTestBase {
+
+    @BeforeClass(alwaysRun = true)
+    @Override
+    protected void setup() throws Exception {
+        baseSetup();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    protected void cleanup() throws Exception {
+        internalCleanup();
+    }
+
+    @Test()
+    public void testNonPartitionedShadowTopicSetup() throws Exception {
+        String sourceTopic = "persistent://prop/ns-abc/source";
+        String shadowTopic = "persistent://prop/ns-abc/shadow";
+        //1. test shadow topic setting in topic creation.
+        admin.topics().createNonPartitionedTopic(sourceTopic);
+        admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+        PersistentTopic brokerShadowTopic =
+                (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+
+        //2. test shadow topic could be properly loaded after unload.
+        admin.namespaces().unload("prop/ns-abc");
+        
Assert.assertTrue(pulsar.getBrokerService().getTopicReference(shadowTopic).isEmpty());
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);
+        brokerShadowTopic = (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+    }
+
+    @Test()
+    public void testPartitionedShadowTopicSetup() throws Exception {
+        String sourceTopic = "persistent://prop/ns-abc/source-p";
+        String shadowTopic = "persistent://prop/ns-abc/shadow-p";
+        String shadowTopicPartition = 
TopicName.get(shadowTopic).getPartition(0).toString();
+
+        //1. test shadow topic setting in topic creation.
+        admin.topics().createPartitionedTopic(sourceTopic, 2);
+        admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+        
pulsarClient.newProducer().topic(shadowTopic).create().close();//trigger 
loading partitions.
+        PersistentTopic brokerShadowTopic = (PersistentTopic) 
pulsar.getBrokerService()
+                .getTopicIfExists(shadowTopicPartition).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);
+        Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), 
sourceTopic);

Review Comment:
   It's better verify the `ManagedLedger` of  `brokerShadowTopic` is  a 
`ShadowManagedLedgerImpl`



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/ShadowTopicTest.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.pulsar.broker.service.persistent;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.service.BrokerTestBase;
+import org.apache.pulsar.common.naming.TopicName;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class ShadowTopicTest extends BrokerTestBase {
+
+    @BeforeClass(alwaysRun = true)
+    @Override
+    protected void setup() throws Exception {
+        baseSetup();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    protected void cleanup() throws Exception {
+        internalCleanup();
+    }
+
+    @Test()
+    public void testNonPartitionedShadowTopicSetup() throws Exception {
+        String sourceTopic = "persistent://prop/ns-abc/source";
+        String shadowTopic = "persistent://prop/ns-abc/shadow";
+        //1. test shadow topic setting in topic creation.
+        admin.topics().createNonPartitionedTopic(sourceTopic);
+        admin.topics().createShadowTopic(shadowTopic, sourceTopic);
+        PersistentTopic brokerShadowTopic =
+                (PersistentTopic) 
pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get();
+        
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().toString(), 
sourceTopic);

Review Comment:
   It's better verify the `ManagedLedger` of  `brokerShadowTopic` is  a 
`ShadowManagedLedgerImpl`



-- 
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]

Reply via email to