You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2023/01/20 05:09:43 UTC

[GitHub] [rocketmq] RongtongJin commented on a diff in pull request #5909: [ISSUE #5684] request code should be short, to support serializeTypeCurrentRPC=ROCKETMQ

RongtongJin commented on code in PR #5909:
URL: https://github.com/apache/rocketmq/pull/5909#discussion_r1082113808


##########
remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RequestCodeTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.protocol;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RequestCodeTest {
+
+    @Test
+    public void testRequestCodeShouldBeShort() throws IllegalAccessException {
+        Set<String> ignored = new HashSet<>();
+        ignored.add("POP_MESSAGE");
+        ignored.add("ACK_MESSAGE");
+        ignored.add("PEEK_MESSAGE");
+        ignored.add("CHANGE_MESSAGE_INVISIBLETIME");
+        ignored.add("NOTIFICATION");
+        ignored.add("POLLING_INFO");
+        Class clazz = RequestCode.class;
+        Field[] fields = clazz.getFields();
+        for (Field field : fields) {
+            if (ignored.contains(field.getName())) {
+                continue;
+            }
+            if (field.getInt(clazz) > Short.MAX_VALUE) {
+                Assert.fail(field.getName() + "=" + field.getInt(clazz) + " should be short, to support serializeTypeCurrentRPC=ROCKETMQ");
+            }
+        }
+    }
+}

Review Comment:
   It would be better to add a UT to prohibit the use of code which be converted to short in ignored hashset.  For example, developers should be prohibited from using code of 3442((short)RequestCode.POP_MESSAGE).



##########
remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RequestCodeTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.protocol;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RequestCodeTest {
+
+    @Test
+    public void testRequestCodeShouldBeShort() throws IllegalAccessException {
+        Set<String> ignored = new HashSet<>();
+        ignored.add("POP_MESSAGE");
+        ignored.add("ACK_MESSAGE");
+        ignored.add("PEEK_MESSAGE");
+        ignored.add("CHANGE_MESSAGE_INVISIBLETIME");
+        ignored.add("NOTIFICATION");
+        ignored.add("POLLING_INFO");
+        Class clazz = RequestCode.class;
+        Field[] fields = clazz.getFields();
+        for (Field field : fields) {
+            if (ignored.contains(field.getName())) {
+                continue;
+            }
+            if (field.getInt(clazz) > Short.MAX_VALUE) {
+                Assert.fail(field.getName() + "=" + field.getInt(clazz) + " should be short, to support serializeTypeCurrentRPC=ROCKETMQ");
+            }
+        }
+    }
+}

Review Comment:
   It would be better to add a UT to prohibit the use of code which be converted to short in ignored hashset.  For example, developers should be prohibited from using code of 3442((short)RequestCode.POP_MESSAGE).



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