Copilot commented on code in PR #10792:
URL: https://github.com/apache/rocketmq/pull/10792#discussion_r3704497943
##########
proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ClientManagerActivity.java:
##########
@@ -78,6 +78,13 @@ protected RemotingCommand
processRequest0(ChannelHandlerContext ctx, RemotingCom
protected RemotingCommand heartBeat(ChannelHandlerContext ctx,
RemotingCommand request,
ProxyContext context) {
HeartbeatData heartbeatData = HeartbeatData.decode(request.getBody(),
HeartbeatData.class);
+ if (heartbeatData == null) {
+ return
RemotingCommand.buildErrorResponse(ResponseCode.INVALID_PARAMETER, "heartbeat
data is empty");
+ }
+ if (heartbeatData.getProducerDataSet() == null ||
heartbeatData.getConsumerDataSet() == null) {
+ return
RemotingCommand.buildErrorResponse(ResponseCode.INVALID_PARAMETER,
+ "heartbeat producerDataSet and consumerDataSet are required");
+ }
Review Comment:
The error remark strings are hard-coded here and also asserted verbatim in
tests, which makes future message tweaks unnecessarily brittle. Consider
extracting these remarks into `static final` constants (or a shared constants
holder) and referencing the same constants from the test to keep production and
test expectations aligned.
##########
proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ClientManagerActivityTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.proxy.remoting.activity;
+
+import java.nio.charset.StandardCharsets;
+import org.apache.rocketmq.proxy.common.ProxyContext;
+import org.apache.rocketmq.proxy.config.InitConfigTest;
+import org.apache.rocketmq.proxy.processor.MessagingProcessor;
+import org.apache.rocketmq.proxy.remoting.channel.RemotingChannelManager;
+import org.apache.rocketmq.remoting.protocol.RemotingCommand;
+import org.apache.rocketmq.remoting.protocol.RequestCode;
+import org.apache.rocketmq.remoting.protocol.ResponseCode;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClientManagerActivityTest extends InitConfigTest {
+ private ClientManagerActivity clientManagerActivity;
+
+ @Mock
+ private MessagingProcessor messagingProcessor;
+ @Mock
+ private RemotingChannelManager remotingChannelManager;
+
+ @Before
+ public void setup() {
+ this.clientManagerActivity = new ClientManagerActivity(null,
messagingProcessor, remotingChannelManager);
+ }
+
+ @Test
+ public void testHeartbeatShouldRejectEmptyBody() {
+ RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null);
+
+ RemotingCommand response = clientManagerActivity.heartBeat(null,
request, ProxyContext.create());
+
+
assertThat(response.getCode()).isEqualTo(ResponseCode.INVALID_PARAMETER);
+ assertThat(response.getRemark()).isEqualTo("heartbeat data is empty");
+ verifyNoClientRegistration();
+ }
+
+ @Test
+ public void testHeartbeatShouldRejectNullDataSets() {
+ RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null);
+
request.setBody("{\"clientID\":\"client-a\",\"producerDataSet\":null,\"consumerDataSet\":[]}"
+ .getBytes(StandardCharsets.UTF_8));
+
+ RemotingCommand response = clientManagerActivity.heartBeat(null,
request, ProxyContext.create());
+
+
assertThat(response.getCode()).isEqualTo(ResponseCode.INVALID_PARAMETER);
+ assertThat(response.getRemark()).isEqualTo("heartbeat producerDataSet
and consumerDataSet are required");
+ verifyNoClientRegistration();
+ }
Review Comment:
The new production logic rejects when either dataset is null, but the test
only covers `producerDataSet=null` with a non-null `consumerDataSet`. Add a
companion test where `consumerDataSet=null` (and `producerDataSet` is non-null,
possibly empty) to ensure both branches of the `||` condition are covered and
remain protected from regressions.
--
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]