Copilot commented on code in PR #8020:
URL: https://github.com/apache/incubator-seata/pull/8020#discussion_r2963759179


##########
core/src/main/java/org/apache/seata/core/protocol/MessageType.java:
##########
@@ -138,6 +138,14 @@ public interface MessageType {
      * The constant TYPE_REG_RM_RESULT.
      */
     short TYPE_REG_RM_RESULT = 104;
+    /**
+     * The constant TYPE_UNREG_RM.
+     */
+    short TYPE_UNREG_RM = 105;
+    /**
+     * The constant TYPE_UNREG_RM_RESULT.
+     */
+    short TYPE_UNREG_RM_RESULT = 106;

Review Comment:
   New message types `TYPE_UNREG_RM`/`TYPE_UNREG_RM_RESULT` need to be 
supported by all configured serializers. The Protobuf serializer uses an 
explicit class->convertor registry 
(`ProtobufConvertManager.fetchConvertor(...)`), and there are currently no 
protobuf convertors/proto definitions registered for 
`UnregisterRMRequest`/`UnregisterRMResponse`, which will cause a runtime NPE if 
users configure `serializer.type=PROTOBUF` and the client attempts to send 
these messages. Add the corresponding protobuf messages/enum entries and 
register convertors in `serializer/seata-serializer-protobuf`, or ensure these 
messages are never sent when protobuf serialization is selected.



##########
core/src/test/java/org/apache/seata/core/rpc/netty/RmNettyClientTest.java:
##########
@@ -362,6 +364,138 @@ public void testGetPoolKeyFunction() throws Exception {
         assertNotNull(function);
     }
 
+    @Test
+    public void unregisterResourceWithBlankParamsTest() {
+        RmNettyRemotingClient client = 
RmNettyRemotingClient.getInstance("app", "test_group");
+
+        NettyClientChannelManager channelManager = 
mock(NettyClientChannelManager.class);
+
+        client.setTransactionServiceGroup(null);
+        client.unregisterResource("group1", 
"jdbc:mysql://localhost:3306/test");
+        verify(channelManager, never()).getChannels();
+
+        client.setTransactionServiceGroup("test_group");
+        client.unregisterResource("group1", "");
+        verify(channelManager, never()).getChannels();
+
+        client.unregisterResource("group1", null);
+        verify(channelManager, never()).getChannels();
+    }

Review Comment:
   `unregisterResourceWithBlankParamsTest` creates a `channelManager` mock but 
never injects it into `RmNettyRemotingClient`, so the `verify(channelManager, 
never()).getChannels()` assertions don't validate the behavior (they will 
always pass regardless of implementation). Inject the mock via the existing 
`setChannelManager(...)` helper (or spy 
`getClientChannelManager()`/`sendAsyncRequest`) before calling 
`unregisterResource`, so the test actually fails if `getChannels()` is invoked.



##########
serializer/seata-serializer-seata/src/test/java/org/apache/seata/serializer/seata/protocol/UnregisterRMResponseSerializerTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.seata.serializer.seata.protocol;
+
+import org.apache.seata.core.protocol.ProtocolConstants;
+import org.apache.seata.core.protocol.ResultCode;
+import org.apache.seata.core.protocol.UnregisterRMResponse;
+import org.apache.seata.serializer.seata.SeataSerializer;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The type Unregister rm response codec test.
+ */
+public class UnregisterRMResponseSerializerTest {
+
+    SeataSerializer seataSerializer = new 
SeataSerializer(ProtocolConstants.VERSION);
+
+    @Test
+    public void codecTest() {
+        UnregisterRMResponse unregisterRMResponse = new UnregisterRMResponse();
+        unregisterRMResponse.setExtraData("abc123");
+        unregisterRMResponse.setIdentified(true);
+        unregisterRMResponse.setMsg("123456");
+        unregisterRMResponse.setVersion("12");
+        unregisterRMResponse.setResultCode(ResultCode.Failed);
+
+        byte[] body = seataSerializer.serialize(unregisterRMResponse);
+
+        UnregisterRMResponse deserialized = seataSerializer.deserialize(body);
+
+        
assertThat(deserialized.isIdentified()).isEqualTo(unregisterRMResponse.isIdentified());
+        
assertThat(deserialized.getVersion()).isEqualTo(unregisterRMResponse.getVersion());

Review Comment:
   The serializer round-trip test sets `extraData`, `msg`, and `resultCode` on 
`UnregisterRMResponse` but only asserts `identified` and `version`. This can 
miss codec regressions for the other fields you explicitly set. Assert the 
remaining fields (at least `extraData`, `msg`, and `resultCode`) to ensure the 
new protocol response is fully covered.
   ```suggestion
           
assertThat(deserialized.getVersion()).isEqualTo(unregisterRMResponse.getVersion());
           
assertThat(deserialized.getExtraData()).isEqualTo(unregisterRMResponse.getExtraData());
           
assertThat(deserialized.getMsg()).isEqualTo(unregisterRMResponse.getMsg());
           
assertThat(deserialized.getResultCode()).isEqualTo(unregisterRMResponse.getResultCode());
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to