org.apache.rocketmq.store.GetMessageResult Java Examples

The following examples show how to use org.apache.rocketmq.store.GetMessageResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PullMessageProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #2
Source File: TransactionalMessageBridge.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息列表
 * @param getMessageResult getMessageResult
 * @return ;
 */
private List<MessageExt> decodeMsgList(GetMessageResult getMessageResult) {
    List<MessageExt> foundList = new ArrayList<>();
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            MessageExt msgExt = MessageDecoder.decode(bb);
            foundList.add(msgExt);
        }

    } finally {
        getMessageResult.release();
    }

    return foundList;
}
 
Example #3
Source File: PullMessageProcessor.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #4
Source File: DeFiPluginMessageStore.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Override
public GetMessageResult getMessage(String group, String topic, int queueId, long offset,
    int maxMsgNums, final MessageFilter messageFilter) {
    long startTime = System.nanoTime();
    GetMessageResult getMessageResult
        = next.getMessage(group, topic, queueId, offset, maxMsgNums, messageFilter);

    if (getMessageResult.getStatus().equals(GetMessageStatus.FOUND)) {
        this.deFiQueueManager.recordLastDeliverOffset(group, topic, queueId, getMessageResult.getNextBeginOffset());
    }

    long eclipseNanoTime = System.nanoTime() - startTime;
    pluginStoreStatService.recordGetTime(eclipseNanoTime);

    return getMessageResult;
}
 
Example #5
Source File: TransactionalMessageBridge.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private List<MessageExt> decodeMsgList(GetMessageResult getMessageResult) {
    List<MessageExt> foundList = new ArrayList<>();
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            MessageExt msgExt = MessageDecoder.decode(bb, true, false);
            if (msgExt != null) {
                foundList.add(msgExt);
            }
        }

    } finally {
        getMessageResult.release();
    }

    return foundList;
}
 
Example #6
Source File: PullMessageProcessor.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 从GetMessageResult获取要读取的消息
 * @param getMessageResult ;
 * @param group ;
 * @param topic ;
 * @param queueId 队列id
 * @return ;
 */
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic,
    final int queueId) {

    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        //释放资源
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #7
Source File: PullMessageProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic,
    final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #8
Source File: PullMessageProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * 读取拉取到的消息,将其数据按顺序收集组合成一个字节数组
 *
 * @param getMessageResult
 * @param group
 * @param topic
 * @param queueId
 * @return
 */
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId,
        this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #9
Source File: PullMessageProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic,
    final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #10
Source File: PullMessageProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic,
    final int queueId) {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());

    long storeTimestamp = 0;
    try {
        List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {

            byteBuffer.put(bb);
            storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
        }
    } finally {
        getMessageResult.release();
    }

    this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
    return byteBuffer.array();
}
 
Example #11
Source File: MessageStoreTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
protected void doGetMessages(MessageStore messageStore, String topic, int queueId, int num, long beginLogicsOffset) {
    for (int i = 0; i < num; i++) {
        GetMessageResult getMessageResult =  messageStore.getMessage("group", topic, queueId, beginLogicsOffset + i, 3, null);
        Assert.assertNotNull(getMessageResult);
        Assert.assertTrue(!getMessageResult.getMessageBufferList().isEmpty());
        MessageExt messageExt = MessageDecoder.decode(getMessageResult.getMessageBufferList().get(0));
        Assert.assertEquals(beginLogicsOffset + i, messageExt.getQueueOffset());
        getMessageResult.release();
    }
}
 
Example #12
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_NoMsgInQueue() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.NO_MESSAGE_IN_QUEUE);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_OFFSET_MOVED);
}
 
Example #13
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_MsgWasRemoving() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.MESSAGE_WAS_REMOVING);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_RETRY_IMMEDIATELY);
}
 
Example #14
Source File: MessageStoreWithFilterTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMessage_withFilter_checkTagsCode() throws Exception {
    putMsg(master, topicCount, msgPerTopic);

    Thread.sleep(200);

    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;

        GetMessageResult getMessageResult = master.getMessage("test", realTopic, queueId, 0, 10000,
            new MessageFilter() {
                @Override
                public boolean isMatchedByConsumeQueue(Long tagsCode, ConsumeQueueExt.CqExtUnit cqExtUnit) {
                    if (tagsCode != null && tagsCode <= ConsumeQueueExt.MAX_ADDR) {
                        return false;
                    }
                    return true;
                }

                @Override
                public boolean isMatchedByCommitLog(ByteBuffer msgBuffer, Map<String, String> properties) {
                    return true;
                }
            });
        assertThat(getMessageResult.getMessageCount()).isEqualTo(msgPerTopic);
    }
}
 
Example #15
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_Found() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #16
Source File: DLedgerCommitlogTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutAndGetMessage() throws Exception {
    String base =  createBaseDir();
    String peers = String.format("n0-localhost:%d", nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore messageStore = createDledgerMessageStore(base, group, "n0", peers, null, false, 0);
    Thread.sleep(1000);
    String topic = UUID.randomUUID().toString();

    List<PutMessageResult> results = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        MessageExtBrokerInner msgInner =
            i < 5 ? buildMessage() : buildIPv6HostMessage();
        msgInner.setTopic(topic);
        msgInner.setQueueId(0);
        PutMessageResult putMessageResult = messageStore.putMessage(msgInner);
        results.add(putMessageResult);
        Assert.assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus());
        Assert.assertEquals(i, putMessageResult.getAppendMessageResult().getLogicsOffset());
    }
    Thread.sleep(100);
    Assert.assertEquals(0, messageStore.getMinOffsetInQueue(topic, 0));
    Assert.assertEquals(10, messageStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(0, messageStore.dispatchBehindBytes());
    GetMessageResult getMessageResult =  messageStore.getMessage("group", topic, 0, 0, 32, null);
    Assert.assertEquals(GetMessageStatus.FOUND, getMessageResult.getStatus());

    Assert.assertEquals(10, getMessageResult.getMessageBufferList().size());
    Assert.assertEquals(10, getMessageResult.getMessageMapedList().size());

    for (int i = 0; i < results.size(); i++) {
        ByteBuffer buffer = getMessageResult.getMessageBufferList().get(i);
        MessageExt messageExt = MessageDecoder.decode(buffer);
        Assert.assertEquals(i, messageExt.getQueueOffset());
        Assert.assertEquals(results.get(i).getAppendMessageResult().getMsgId(), messageExt.getMsgId());
        Assert.assertEquals(results.get(i).getAppendMessageResult().getWroteOffset(), messageExt.getCommitLogOffset());
    }
    messageStore.destroy();
    messageStore.shutdown();
}
 
Example #17
Source File: ManyMessageTransferTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void ManyMessageTransferCloseTest(){
    ByteBuffer byteBuffer = ByteBuffer.allocate(20);
    byteBuffer.putInt(20);
    GetMessageResult getMessageResult = new GetMessageResult();
    ManyMessageTransfer manyMessageTransfer = new ManyMessageTransfer(byteBuffer,getMessageResult);
    manyMessageTransfer.close();
    manyMessageTransfer.deallocate();
}
 
Example #18
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private GetMessageResult createGetMessageResult() {
    GetMessageResult getMessageResult = new GetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.FOUND);
    getMessageResult.setMinOffset(100);
    getMessageResult.setMaxOffset(1024);
    getMessageResult.setNextBeginOffset(516);
    return getMessageResult;
}
 
Example #19
Source File: ManyMessageTransferTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void ManyMessageTransferCountTest(){
    ByteBuffer byteBuffer = ByteBuffer.allocate(20);
    byteBuffer.putInt(20);
    GetMessageResult getMessageResult = new GetMessageResult();
    ManyMessageTransfer manyMessageTransfer = new ManyMessageTransfer(byteBuffer,getMessageResult);

    Assert.assertEquals(manyMessageTransfer.count(),20);

}
 
Example #20
Source File: PullMessageProcessorTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_MsgWasRemoving() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.MESSAGE_WAS_REMOVING);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(SubscriptionData.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_RETRY_IMMEDIATELY);
}
 
Example #21
Source File: PullMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
private GetMessageResult createGetMessageResult() {
    GetMessageResult getMessageResult = new GetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.FOUND);
    getMessageResult.setMinOffset(100);
    getMessageResult.setMaxOffset(1024);
    getMessageResult.setNextBeginOffset(516);
    return getMessageResult;
}
 
Example #22
Source File: PullMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_NoMsgInQueue() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.NO_MESSAGE_IN_QUEUE);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_OFFSET_MOVED);
}
 
Example #23
Source File: PullMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_MsgWasRemoving() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.MESSAGE_WAS_REMOVING);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_RETRY_IMMEDIATELY);
}
 
Example #24
Source File: PullMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_Found() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #25
Source File: MessageStoreWithFilterTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMessage_withFilter_checkTagsCode() throws Exception {
    putMsg(master, topicCount, msgPerTopic);

    Thread.sleep(200);

    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;

        GetMessageResult getMessageResult = master.getMessage("test", realTopic, queueId, 0, 10000,
            new MessageFilter() {
                @Override
                public boolean isMatchedByConsumeQueue(Long tagsCode, ConsumeQueueExt.CqExtUnit cqExtUnit) {
                    if (tagsCode != null && tagsCode <= ConsumeQueueExt.MAX_ADDR) {
                        return false;
                    }
                    return true;
                }

                @Override
                public boolean isMatchedByCommitLog(ByteBuffer msgBuffer, Map<String, String> properties) {
                    return true;
                }
            });
        assertThat(getMessageResult.getMessageCount()).isEqualTo(msgPerTopic);
    }
}
 
Example #26
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private GetMessageResult createGetMessageResult() {
    GetMessageResult getMessageResult = new GetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.FOUND);
    getMessageResult.setMinOffset(100);
    getMessageResult.setMaxOffset(1024);
    getMessageResult.setNextBeginOffset(516);
    return getMessageResult;
}
 
Example #27
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_NoMsgInQueue() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.NO_MESSAGE_IN_QUEUE);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_OFFSET_MOVED);
}
 
Example #28
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_MsgWasRemoving() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.MESSAGE_WAS_REMOVING);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_RETRY_IMMEDIATELY);
}
 
Example #29
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_Found() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #30
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_NoMsgInQueue() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.NO_MESSAGE_IN_QUEUE);
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(SubscriptionData.class))).thenReturn(getMessageResult);

    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.PULL_OFFSET_MOVED);
}