You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "Aias00 (via GitHub)" <gi...@apache.org> on 2026/08/03 07:37:15 UTC

[PR] [ISSUE #10782] Set error code for empty lock batch MQ [rocketmq]

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

   ### What is changed
   - Set an explicit failure response code when Proxy receives LOCK_BATCH_MQ or UNLOCK_BATCH_MQ with an empty MessageQueue set.
   - Keep the existing response body and remark so clients still get the diagnostic message.
   - Add remoting activity coverage for both empty lock and unlock paths and verify Proxy does not forward invalid requests to the broker.
   
   Fixes #10782
   
   ### Verification
   - mvn -pl proxy -Dtest=ConsumerManagerActivityTest test
   


-- 
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 #10782] Set error code for empty lock batch MQ [rocketmq]

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

   Clarification: #10790 contains the same lock/unlock validation, uses ResponseCode.INVALID_PARAMETER for the invalid request, and verifies the retained response body.


-- 
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 #10782] Set error code for empty lock batch MQ [rocketmq]

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


##########
proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 io.netty.channel.ChannelHandlerContext;
+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.service.channel.SimpleChannel;
+import org.apache.rocketmq.proxy.service.channel.SimpleChannelHandlerContext;
+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.body.LockBatchRequestBody;
+import org.apache.rocketmq.remoting.protocol.body.UnlockBatchRequestBody;
+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.anyLong;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConsumerManagerActivityTest extends InitConfigTest {
+
+    private ConsumerManagerActivity consumerManagerActivity;
+    private ChannelHandlerContext ctx;
+
+    @Mock
+    private MessagingProcessor messagingProcessor;
+
+    @Before
+    public void setup() {
+        consumerManagerActivity = new ConsumerManagerActivity(null, messagingProcessor);
+        ctx = new SimpleChannelHandlerContext(new SimpleChannel(null, "0.0.0.0:0", "1.1.1.1:1"));
+    }
+
+    @Test
+    public void testLockBatchMQShouldRejectEmptyMessageQueueSet() throws Exception {
+        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);
+        request.setBody(new LockBatchRequestBody().encode());
+
+        RemotingCommand response = consumerManagerActivity.processRequest0(ctx, request, ProxyContext.create());
+
+        assertThat(response).isNotNull();
+        assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
+        assertThat(response.getRemark()).isEqualTo("MessageQueue set is empty");
+        verify(messagingProcessor, never()).request(any(), any(), any(), anyLong());

Review Comment:
   The PR description says the existing response body is preserved for diagnostics, but the tests don’t assert anything about `response.getBody()`. Add an assertion that the response body is present and matches the encoded request body (or otherwise verifies the expected diagnostic payload) so the stated behavior is covered.



##########
proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 io.netty.channel.ChannelHandlerContext;
+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.service.channel.SimpleChannel;
+import org.apache.rocketmq.proxy.service.channel.SimpleChannelHandlerContext;
+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.body.LockBatchRequestBody;
+import org.apache.rocketmq.remoting.protocol.body.UnlockBatchRequestBody;
+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.anyLong;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConsumerManagerActivityTest extends InitConfigTest {
+
+    private ConsumerManagerActivity consumerManagerActivity;
+    private ChannelHandlerContext ctx;
+
+    @Mock
+    private MessagingProcessor messagingProcessor;
+
+    @Before
+    public void setup() {
+        consumerManagerActivity = new ConsumerManagerActivity(null, messagingProcessor);
+        ctx = new SimpleChannelHandlerContext(new SimpleChannel(null, "0.0.0.0:0", "1.1.1.1:1"));
+    }
+
+    @Test
+    public void testLockBatchMQShouldRejectEmptyMessageQueueSet() throws Exception {
+        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);
+        request.setBody(new LockBatchRequestBody().encode());
+
+        RemotingCommand response = consumerManagerActivity.processRequest0(ctx, request, ProxyContext.create());
+
+        assertThat(response).isNotNull();
+        assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
+        assertThat(response.getRemark()).isEqualTo("MessageQueue set is empty");

Review Comment:
   The error remark string is duplicated across tests. Consider extracting it into a local constant (e.g., `private static final String EMPTY_MQ_SET_REMARK = ...`) to avoid brittle failures if the message is updated in the implementation.



##########
proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 io.netty.channel.ChannelHandlerContext;
+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.service.channel.SimpleChannel;
+import org.apache.rocketmq.proxy.service.channel.SimpleChannelHandlerContext;
+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.body.LockBatchRequestBody;
+import org.apache.rocketmq.remoting.protocol.body.UnlockBatchRequestBody;
+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.anyLong;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConsumerManagerActivityTest extends InitConfigTest {
+
+    private ConsumerManagerActivity consumerManagerActivity;
+    private ChannelHandlerContext ctx;
+
+    @Mock
+    private MessagingProcessor messagingProcessor;
+
+    @Before
+    public void setup() {
+        consumerManagerActivity = new ConsumerManagerActivity(null, messagingProcessor);
+        ctx = new SimpleChannelHandlerContext(new SimpleChannel(null, "0.0.0.0:0", "1.1.1.1:1"));
+    }
+
+    @Test
+    public void testLockBatchMQShouldRejectEmptyMessageQueueSet() throws Exception {
+        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);
+        request.setBody(new LockBatchRequestBody().encode());
+
+        RemotingCommand response = consumerManagerActivity.processRequest0(ctx, request, ProxyContext.create());
+
+        assertThat(response).isNotNull();
+        assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
+        assertThat(response.getRemark()).isEqualTo("MessageQueue set is empty");
+        verify(messagingProcessor, never()).request(any(), any(), any(), anyLong());
+    }
+
+    @Test
+    public void testUnlockBatchMQShouldRejectEmptyMessageQueueSet() throws Exception {
+        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null);
+        request.setBody(new UnlockBatchRequestBody().encode());
+
+        RemotingCommand response = consumerManagerActivity.processRequest0(ctx, request, ProxyContext.create());
+
+        assertThat(response).isNotNull();
+        assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
+        assertThat(response.getRemark()).isEqualTo("MessageQueue set is empty");

Review Comment:
   The error remark string is duplicated across tests. Consider extracting it into a local constant (e.g., `private static final String EMPTY_MQ_SET_REMARK = ...`) to avoid brittle failures if the message is updated in the implementation.



-- 
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 #10782] Set error code for empty lock batch MQ [rocketmq]

Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 closed pull request #10783: [ISSUE #10782] Set error code for empty lock batch MQ
URL: https://github.com/apache/rocketmq/pull/10783


-- 
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 #10782] Set error code for empty lock batch MQ [rocketmq]

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

   Closing as duplicate of #10790. #10790 now contains the same lock/unlock validation, uses  for the invalid request, and verifies the retained response body.


-- 
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 #10782] Set error code for empty lock batch MQ [rocketmq]

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

   ## [Codecov](https://app.codecov.io/gh/apache/rocketmq/pull/10783?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 48.25%. Comparing base ([`eddb235`](https://app.codecov.io/gh/apache/rocketmq/commit/eddb235c1bd8adc5c3a1125a294405526e7bb0e3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`9989011`](https://app.codecov.io/gh/apache/rocketmq/commit/99890114f563d37cdc94047438fd2b2cb41f1d4c?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   #10783      +/-   ##
   =============================================
   + Coverage      48.24%   48.25%   +0.01%     
   + Complexity     13496    13494       -2     
   =============================================
     Files           1380     1380              
     Lines         101104   101106       +2     
     Branches       13107    13107              
   =============================================
   + Hits           48773    48785      +12     
   + Misses         46350    46333      -17     
   - Partials        5981     5988       +7     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/rocketmq/pull/10783?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).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


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