Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.apache.rocketmq.remoting.protocol.RemotingCommand;

public class ConsumerManagerActivity extends AbstractRemotingActivity {
static final String EMPTY_QUEUE_REMARK = "MessageQueue set is empty";

public ConsumerManagerActivity(RequestPipeline requestPipeline, MessagingProcessor messagingProcessor) {
super(requestPipeline, messagingProcessor);
}
Expand Down Expand Up @@ -136,7 +138,8 @@ protected RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand
Set<MessageQueue> mqSet = requestBody.getMqSet();
if (mqSet.isEmpty()) {
response.setBody(requestBody.encode());
response.setRemark("MessageQueue set is empty");
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(EMPTY_QUEUE_REMARK);
return response;
}
Comment on lines 138 to 144

Expand All @@ -157,7 +160,8 @@ protected RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, RemotingComma
Set<MessageQueue> mqSet = requestBody.getMqSet();
if (mqSet.isEmpty()) {
response.setBody(requestBody.encode());
response.setRemark("MessageQueue set is empty");
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(EMPTY_QUEUE_REMARK);
return response;
}
Comment on lines 160 to 166

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.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.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 {
ConsumerManagerActivity consumerManagerActivity;

@Mock
MessagingProcessor messagingProcessorMock;

@Before
public void setup() {
consumerManagerActivity = new ConsumerManagerActivity(null, messagingProcessorMock);
}

@Test
public void testLockBatchMQWithEmptyQueueSetReturnsErrorCode() throws Exception {
LockBatchRequestBody requestBody = new LockBatchRequestBody();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);
request.setBody(requestBody.encode());

RemotingCommand response = consumerManagerActivity.lockBatchMQ(null, request, null);

assertThat(response.getCode()).isEqualTo(ResponseCode.INVALID_PARAMETER);
assertThat(response.getRemark()).isEqualTo(ConsumerManagerActivity.EMPTY_QUEUE_REMARK);
assertThat(response.getBody()).isEqualTo(requestBody.encode());
verify(messagingProcessorMock, never()).request(any(), any(), any(), anyLong());
}

@Test
public void testUnlockBatchMQWithEmptyQueueSetReturnsErrorCode() throws Exception {
UnlockBatchRequestBody requestBody = new UnlockBatchRequestBody();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null);
request.setBody(requestBody.encode());

RemotingCommand response = consumerManagerActivity.unlockBatchMQ(null, request, null);

assertThat(response.getCode()).isEqualTo(ResponseCode.INVALID_PARAMETER);
assertThat(response.getRemark()).isEqualTo(ConsumerManagerActivity.EMPTY_QUEUE_REMARK);
assertThat(response.getBody()).isEqualTo(requestBody.encode());
verify(messagingProcessorMock, never()).request(any(), any(), any(), anyLong());
}
}
Loading