Copilot commented on code in PR #10794:
URL: https://github.com/apache/rocketmq/pull/10794#discussion_r3704530950
##########
proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java:
##########
@@ -84,6 +84,11 @@ protected RemotingCommand
getConsumerListByGroup(ChannelHandlerContext ctx, Remo
RemotingCommand response =
RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class);
GetConsumerListByGroupRequestHeader header =
(GetConsumerListByGroupRequestHeader)
request.decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class);
ConsumerGroupInfo consumerGroupInfo =
messagingProcessor.getConsumerGroupInfo(context, header.getConsumerGroup());
+ if (consumerGroupInfo == null) {
+ response.setCode(ResponseCode.CONSUMER_NOT_ONLINE);
+ response.setRemark("the consumer group[" +
header.getConsumerGroup() + "] not online");
+ return response;
+ }
Review Comment:
The not-online remark string is constructed inline via concatenation. If
this message is also used in `GET_CONSUMER_CONNECTION_LIST` (per the PR
description), consider extracting a shared helper/constant (or reusing an
existing one) to keep message wording consistent across request codes and avoid
future drift.
##########
proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.rocketmq.proxy.common.ProxyContext;
+import org.apache.rocketmq.proxy.config.InitConfigTest;
+import org.apache.rocketmq.proxy.processor.MessagingProcessor;
+import org.apache.rocketmq.remoting.protocol.RemotingCommand;
+import org.apache.rocketmq.remoting.protocol.RequestCode;
+import org.apache.rocketmq.remoting.protocol.ResponseCode;
+import
org.apache.rocketmq.remoting.protocol.header.GetConsumerListByGroupRequestHeader;
+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.eq;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConsumerManagerActivityTest extends InitConfigTest {
+ private static final String CONSUMER_GROUP = "offline-group";
+
+ private ConsumerManagerActivity consumerManagerActivity;
+
+ @Mock
+ private MessagingProcessor messagingProcessor;
+
+ @Before
+ public void setup() {
+ this.consumerManagerActivity = new ConsumerManagerActivity(null,
messagingProcessor);
+ }
+
+ @Test
+ public void
testGetConsumerListByGroupShouldReturnNotOnlineWhenGroupMissing() throws
Exception {
+ GetConsumerListByGroupRequestHeader header = new
GetConsumerListByGroupRequestHeader();
+ header.setConsumerGroup(CONSUMER_GROUP);
+ RemotingCommand request = RemotingCommand.createRequestCommand(
+ RequestCode.GET_CONSUMER_LIST_BY_GROUP, header);
+ request.makeCustomHeaderToNet();
+ when(messagingProcessor.getConsumerGroupInfo(any(),
eq(CONSUMER_GROUP))).thenReturn(null);
+
+ RemotingCommand response =
consumerManagerActivity.getConsumerListByGroup(
+ null, request, ProxyContext.create());
+
+
assertThat(response.getCode()).isEqualTo(ResponseCode.CONSUMER_NOT_ONLINE);
+ assertThat(response.getRemark()).isEqualTo("the consumer
group[offline-group] not online");
Review Comment:
The test asserts the full `remark` string exactly, which can make the test
brittle if the message wording changes while behavior remains correct. Consider
asserting key invariants instead (e.g., remark contains the consumer group and
indicates not-online), or centralizing the remark message construction so
production and test share the same source of truth.
--
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]