You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/06/22 08:32:15 UTC

[GitHub] [pulsar] mattisonchao opened a new pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

mattisonchao opened a new pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015


   
   ### Modifications
   
   add test for TopicCountEquallyDivideBundleSplitAlgorithm.
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat merged pull request #11015: [Tests] Add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
merlimat merged pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] lhotari commented on a change in pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
lhotari commented on a change in pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#discussion_r656074466



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/common/naming/TopicCountEquallyDivideBundleSplitAlgorithmTest.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.common.naming;
+
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.hash.Hashing;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.junit.Test;

Review comment:
       I noticed some previous PRs have been merged with org.junit.Test annotations. That's fixed in #11020 so you don't have to worry about the imports in previous PRs.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao commented on pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#issuecomment-865781178


   I've been fixing it, could you review it? @lhotari 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao commented on pull request #11015: [Tests] Add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#issuecomment-865892003


   Thank you for your rigorous review 👍🏼 , I've been fixing some problem. 
   Could you review it again?
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao removed a comment on pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao removed a comment on pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#issuecomment-865780291


   i've been fix it,could you review it ? @lhotari 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] lhotari commented on a change in pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
lhotari commented on a change in pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#discussion_r656010644



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/common/naming/TopicCountEquallyDivideBundleSplitAlgorithmTest.java
##########
@@ -0,0 +1,93 @@
+/**
+ * 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.common.naming;
+
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.hash.Hashing;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.testng.Assert;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+
+public class TopicCountEquallyDivideBundleSplitAlgorithmTest {
+
+    @Test
+    public void testWrongArg() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        Assert.assertThrows(NullPointerException.class, () -> algorithm.getSplitBoundary(null, null));
+    }
+
+    @Test
+    public void testTopicsSizeLessThan1() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        NamespaceService mockNamespaceService = Mockito.mock(NamespaceService.class);
+        NamespaceBundle mockNamespaceBundle = Mockito.mock(NamespaceBundle.class);
+        Mockito.doReturn(CompletableFuture.completedFuture(Lists.newArrayList("a")))
+                .when(mockNamespaceService).getOwnedTopicListForNamespaceBundle(mockNamespaceBundle);
+        Assert.assertNull(algorithm.getSplitBoundary(mockNamespaceService, mockNamespaceBundle).join());
+    }
+    @Test
+    public void testAlgorithmReturnCorrectResult() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        List<String> mockTopics = Lists.newArrayList("a", "b", "c");
+        long correctResult = getCorrectResult(mockTopics);
+        NamespaceService mockNamespaceService1 = Mockito.mock(NamespaceService.class);
+        NamespaceBundle mockNamespaceBundle1 = Mockito.mock(NamespaceBundle.class);
+        Mockito.doReturn(CompletableFuture.completedFuture(mockTopics))
+                .when(mockNamespaceService1).getOwnedTopicListForNamespaceBundle(mockNamespaceBundle1);
+        NamespaceBundleFactory mockNamespaceBundleFactory = Mockito.mock(NamespaceBundleFactory.class);
+        mockTopics.forEach((topic)->{
+            Mockito.doReturn(mockNamespaceBundleFactory)
+                    .when(mockNamespaceBundle1).getNamespaceBundleFactory();
+            long hashValue = Hashing.crc32().hashString(topic, Charsets.UTF_8).padToLong();
+            Mockito.doReturn(hashValue)
+                    .when(mockNamespaceBundleFactory).getLongHashCode(topic);
+        });
+        Assert.assertEquals((long)algorithm.getSplitBoundary(mockNamespaceService1, mockNamespaceBundle1).join(),correctResult);
+    }
+
+    private long getCorrectResult(List<String> mockTopics){

Review comment:
       "getCorrectResult" is a very vague name for a method.
   It seems that a better approach would be to inline this method.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao commented on a change in pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on a change in pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#discussion_r656019367



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/common/naming/TopicCountEquallyDivideBundleSplitAlgorithmTest.java
##########
@@ -0,0 +1,93 @@
+/**
+ * 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.common.naming;
+
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.hash.Hashing;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.testng.Assert;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+
+public class TopicCountEquallyDivideBundleSplitAlgorithmTest {
+
+    @Test
+    public void testWrongArg() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        Assert.assertThrows(NullPointerException.class, () -> algorithm.getSplitBoundary(null, null));
+    }
+
+    @Test
+    public void testTopicsSizeLessThan1() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        NamespaceService mockNamespaceService = Mockito.mock(NamespaceService.class);
+        NamespaceBundle mockNamespaceBundle = Mockito.mock(NamespaceBundle.class);
+        Mockito.doReturn(CompletableFuture.completedFuture(Lists.newArrayList("a")))
+                .when(mockNamespaceService).getOwnedTopicListForNamespaceBundle(mockNamespaceBundle);
+        Assert.assertNull(algorithm.getSplitBoundary(mockNamespaceService, mockNamespaceBundle).join());
+    }
+    @Test
+    public void testAlgorithmReturnCorrectResult() {
+        TopicCountEquallyDivideBundleSplitAlgorithm algorithm = new TopicCountEquallyDivideBundleSplitAlgorithm();
+        List<String> mockTopics = Lists.newArrayList("a", "b", "c");
+        long correctResult = getCorrectResult(mockTopics);
+        NamespaceService mockNamespaceService1 = Mockito.mock(NamespaceService.class);
+        NamespaceBundle mockNamespaceBundle1 = Mockito.mock(NamespaceBundle.class);
+        Mockito.doReturn(CompletableFuture.completedFuture(mockTopics))
+                .when(mockNamespaceService1).getOwnedTopicListForNamespaceBundle(mockNamespaceBundle1);
+        NamespaceBundleFactory mockNamespaceBundleFactory = Mockito.mock(NamespaceBundleFactory.class);
+        mockTopics.forEach((topic)->{
+            Mockito.doReturn(mockNamespaceBundleFactory)
+                    .when(mockNamespaceBundle1).getNamespaceBundleFactory();
+            long hashValue = Hashing.crc32().hashString(topic, Charsets.UTF_8).padToLong();
+            Mockito.doReturn(hashValue)
+                    .when(mockNamespaceBundleFactory).getLongHashCode(topic);
+        });
+        Assert.assertEquals((long)algorithm.getSplitBoundary(mockNamespaceService1, mockNamespaceBundle1).join(),correctResult);
+    }
+
+    private long getCorrectResult(List<String> mockTopics){

Review comment:
       OK, thank you, I will fix it.  : )




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao commented on a change in pull request #11015: [Tests] Add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on a change in pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#discussion_r656116749



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/common/naming/TopicCountEquallyDivideBundleSplitAlgorithmTest.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.common.naming;
+
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.hash.Hashing;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.junit.Test;

Review comment:
       fixed :)




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] lhotari commented on a change in pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
lhotari commented on a change in pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#discussion_r656067306



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/common/naming/TopicCountEquallyDivideBundleSplitAlgorithmTest.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.common.naming;
+
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.hash.Hashing;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.junit.Test;

Review comment:
       Invalid import in TestNG tests. Please use the TestNG Test annotation.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] mattisonchao commented on pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#issuecomment-865780291


   i've been fix it,could you review it ? @lhotari 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] lhotari commented on pull request #11015: Feat # add test for TopicCountEquallyDivideBundleSplitAlgorithm.

Posted by GitBox <gi...@apache.org>.
lhotari commented on pull request #11015:
URL: https://github.com/apache/pulsar/pull/11015#issuecomment-865834956


   Btw. The prefix "Feat #" you have for the PR title doesn't follow the conventions used in Apache Pulsar. Please take a look at titles of other PRs.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org