You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "yx9o (via GitHub)" <gi...@apache.org> on 2024/10/22 12:20:35 UTC

[PR] [ISSUE #8852] Add more test coverage for ClientMetadata [rocketmq]

yx9o opened a new pull request, #8853:
URL: https://github.com/apache/rocketmq/pull/8853

   
   Fixes #8852 .
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

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


Re: [PR] [ISSUE #8852] Add more test coverage for ClientMetadata [rocketmq]

Posted by "RongtongJin (via GitHub)" <gi...@apache.org>.
RongtongJin commented on code in PR #8853:
URL: https://github.com/apache/rocketmq/pull/8853#discussion_r1811601083


##########
remoting/src/test/java/org/apache/rocketmq/remoting/rpc/ClientMetadataTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.rocketmq.remoting.rpc;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.remoting.protocol.route.TopicRouteData;
+import org.apache.rocketmq.remoting.protocol.statictopic.TopicQueueMappingInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClientMetadataTest {
+
+    private ClientMetadata clientMetadata;
+
+    private final ConcurrentMap<String, TopicRouteData> topicRouteTable = new ConcurrentHashMap<>();
+
+    private final ConcurrentMap<String, ConcurrentMap<MessageQueue, String>> topicEndPointsTable = new ConcurrentHashMap<>();
+
+    private final ConcurrentMap<String, HashMap<Long, String>> brokerAddrTable = new ConcurrentHashMap<>();
+
+    private final String defaultTopic = "defaultTopic";
+
+    private final String defaultBroker = "defaultBroker";
+
+    @Before
+    public void init() throws IllegalAccessException {
+        clientMetadata = new ClientMetadata();
+
+        FieldUtils.writeDeclaredField(clientMetadata, "topicRouteTable", topicRouteTable, true);
+        FieldUtils.writeDeclaredField(clientMetadata, "topicEndPointsTable", topicEndPointsTable, true);
+        FieldUtils.writeDeclaredField(clientMetadata, "brokerAddrTable", brokerAddrTable, true);
+    }
+
+    @Test
+    public void testGetBrokerNameFromMessageQueue() {
+        MessageQueue mq = new MessageQueue(defaultTopic, defaultBroker, 0);
+        topicEndPointsTable.put(defaultTopic, new ConcurrentHashMap<>());
+        topicEndPointsTable.get(defaultTopic).put(mq, defaultBroker);

Review Comment:
   It would be better not to use defaultBroker, so it can be distinguished from testGetBrokerNameFrommessageQueueNotFound test 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.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

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


Re: [PR] [ISSUE #8852] Add more test coverage for ClientMetadata [rocketmq]

Posted by "RongtongJin (via GitHub)" <gi...@apache.org>.
RongtongJin merged PR #8853:
URL: https://github.com/apache/rocketmq/pull/8853


-- 
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: commits-unsubscribe@rocketmq.apache.org

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


Re: [PR] [ISSUE #8852] Add more test coverage for ClientMetadata [rocketmq]

Posted by "yx9o (via GitHub)" <gi...@apache.org>.
yx9o commented on code in PR #8853:
URL: https://github.com/apache/rocketmq/pull/8853#discussion_r1811860350


##########
remoting/src/test/java/org/apache/rocketmq/remoting/rpc/ClientMetadataTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.rocketmq.remoting.rpc;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.remoting.protocol.route.TopicRouteData;
+import org.apache.rocketmq.remoting.protocol.statictopic.TopicQueueMappingInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClientMetadataTest {
+
+    private ClientMetadata clientMetadata;
+
+    private final ConcurrentMap<String, TopicRouteData> topicRouteTable = new ConcurrentHashMap<>();
+
+    private final ConcurrentMap<String, ConcurrentMap<MessageQueue, String>> topicEndPointsTable = new ConcurrentHashMap<>();
+
+    private final ConcurrentMap<String, HashMap<Long, String>> brokerAddrTable = new ConcurrentHashMap<>();
+
+    private final String defaultTopic = "defaultTopic";
+
+    private final String defaultBroker = "defaultBroker";
+
+    @Before
+    public void init() throws IllegalAccessException {
+        clientMetadata = new ClientMetadata();
+
+        FieldUtils.writeDeclaredField(clientMetadata, "topicRouteTable", topicRouteTable, true);
+        FieldUtils.writeDeclaredField(clientMetadata, "topicEndPointsTable", topicEndPointsTable, true);
+        FieldUtils.writeDeclaredField(clientMetadata, "brokerAddrTable", brokerAddrTable, true);
+    }
+
+    @Test
+    public void testGetBrokerNameFromMessageQueue() {
+        MessageQueue mq = new MessageQueue(defaultTopic, defaultBroker, 0);
+        topicEndPointsTable.put(defaultTopic, new ConcurrentHashMap<>());
+        topicEndPointsTable.get(defaultTopic).put(mq, defaultBroker);

Review Comment:
   Hi @RongtongJin , changes are complete, please review, thank you.



-- 
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: commits-unsubscribe@rocketmq.apache.org

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


Re: [PR] [ISSUE #8852] Add more test coverage for ClientMetadata [rocketmq]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #8853:
URL: https://github.com/apache/rocketmq/pull/8853#issuecomment-2429205356

   ## [Codecov](https://app.codecov.io/gh/apache/rocketmq/pull/8853?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 47.44%. Comparing base [(`a024dc8`)](https://app.codecov.io/gh/apache/rocketmq/commit/a024dc81dafad21182a8485c1216b97e79b64661?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`e28e0b5`)](https://app.codecov.io/gh/apache/rocketmq/commit/e28e0b5c36571bd55a3ed1cca3e8aaf1eee57b31?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@              Coverage Diff              @@
   ##             develop    #8853      +/-   ##
   =============================================
   + Coverage      47.41%   47.44%   +0.02%     
   - Complexity     11611    11615       +4     
   =============================================
     Files           1284     1284              
     Lines          90023    90023              
     Branches       11586    11586              
   =============================================
   + Hits           42686    42710      +24     
   + Misses         42097    42056      -41     
   - Partials        5240     5257      +17     
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/rocketmq/pull/8853?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

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