Search in sources :

Example 6 with GetMinOffsetRequestHeader

use of org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader in project rocketmq by apache.

the class AdminBrokerProcessorTest method testGetMinOffset.

@Test
public void testGetMinOffset() throws Exception {
    messageStore = mock(MessageStore.class);
    when(messageStore.getMinOffsetInQueue(anyString(), anyInt())).thenReturn(Long.MIN_VALUE);
    when(brokerController.getMessageStore()).thenReturn(messageStore);
    GetMinOffsetRequestHeader getMinOffsetRequestHeader = new GetMinOffsetRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_MIN_OFFSET, getMinOffsetRequestHeader);
    request.addExtField("topic", "topic");
    request.addExtField("queueId", "0");
    RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
Also used : DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) MessageStore(org.apache.rocketmq.store.MessageStore) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetMinOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader) Test(org.junit.Test)

Example 7 with GetMinOffsetRequestHeader

use of org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader in project rocketmq by apache.

the class AdminBrokerProcessor method getMinOffset.

private RemotingCommand getMinOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class);
    final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader();
    final GetMinOffsetRequestHeader requestHeader = (GetMinOffsetRequestHeader) request.decodeCommandCustomHeader(GetMinOffsetRequestHeader.class);
    long offset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId());
    responseHeader.setOffset(offset);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetMinOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader) GetMinOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.GetMinOffsetResponseHeader)

Example 8 with GetMinOffsetRequestHeader

use of org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader in project rocketmq-comments by HScarb.

the class AdminBrokerProcessorTest method testGetMinOffset.

@Test
public void testGetMinOffset() throws Exception {
    messageStore = mock(MessageStore.class);
    when(messageStore.getMinOffsetInQueue(anyString(), anyInt())).thenReturn(Long.MIN_VALUE);
    when(brokerController.getMessageStore()).thenReturn(messageStore);
    GetMinOffsetRequestHeader getMinOffsetRequestHeader = new GetMinOffsetRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_MIN_OFFSET, getMinOffsetRequestHeader);
    request.addExtField("topic", "topic");
    request.addExtField("queueId", "0");
    RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
Also used : DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) MessageStore(org.apache.rocketmq.store.MessageStore) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetMinOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader) Test(org.junit.Test)

Aggregations

GetMinOffsetRequestHeader (org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader)8 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)8 GetMinOffsetResponseHeader (org.apache.rocketmq.common.protocol.header.GetMinOffsetResponseHeader)6 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)3 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2 MessageStore (org.apache.rocketmq.store.MessageStore)2 Test (org.junit.Test)2