org.apache.rocketmq.store.PutMessageStatus Java Examples

The following examples show how to use org.apache.rocketmq.store.PutMessageStatus. 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: DefaultTransactionalMessageCheckListener.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void resolveDiscardMsg(MessageExt msgExt) {
    log.error("MsgExt:{} has been checked too many times, so discard it by moving it to system topic TRANS_CHECK_MAXTIME_TOPIC", msgExt);

    try {
        MessageExtBrokerInner brokerInner = toMessageExtBrokerInner(msgExt);
        PutMessageResult putMessageResult = this.getBrokerController().getMessageStore().putMessage(brokerInner);
        if (putMessageResult != null && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {
            log.info("Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC OK. Restored in queueOffset={}, " +
                "commitLogOffset={}, real topic={}", msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), msgExt.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC));
        } else {
            log.error("Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC failed, real topic={}, msgId={}", msgExt.getTopic(), msgExt.getMsgId());
        }
    } catch (Exception e) {
        log.warn("Put checked-too-many-time message to TRANS_CHECK_MAXTIME_TOPIC error. {}", e);
    }

}
 
Example #2
Source File: DeFiReplyMessageProcessorTest.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    deFiBrokerController = spy(new DeFiBrokerController(new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig(), deFiBusBrokerConfig));
    channelHandlerContext = mock(ChannelHandlerContext.class);
    messageStore = mock(MessageStore.class);
    DeFiBusBroker2Client broker2Client = mock(DeFiBusBroker2Client.class);
    when(this.deFiBrokerController.getDeFiBusBroker2Client()).thenReturn(broker2Client);
    when(broker2Client.pushRRReplyMessageToClient(any(), any(), any())).thenReturn(true);
    Channel channel = mock(Channel.class);
    when(channel.isActive()).thenReturn(true);
    ClientChannelInfo channelInfo = mock(ClientChannelInfo.class);
    when(channelInfo.getChannel()).thenReturn(channel);
    DeFiProducerManager mockProducer = mock(DeFiProducerManager.class);
    when(mockProducer.getClientChannel(anyString())).thenReturn(channelInfo);
    when(this.deFiBrokerController.getProducerManager()).thenReturn(mockProducer);
    this.deFiBrokerController.setMessageStore(this.messageStore);
    when(this.messageStore.now()).thenReturn(System.currentTimeMillis());
    AppendMessageResult appendMessageResult = new AppendMessageResult(AppendMessageStatus.PUT_OK, 0, 0, "00000000000000000000000000000000", messageStore.now(), 0L, 0);
    when(this.messageStore.putMessage(any())).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, appendMessageResult));
    when(channel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(channelHandlerContext.channel()).thenReturn(channel);
    deFiReplyMessageProcessor = new DeFiReplyMessageProcessor(this.deFiBrokerController);
}
 
Example #3
Source File: TransactionalMessageServiceImplTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheck_withCheck() {
    when(bridge.fetchMessageQueues(TopicValidator.RMQ_SYS_TRANS_HALF_TOPIC)).thenReturn(createMessageQueueSet(TopicValidator.RMQ_SYS_TRANS_HALF_TOPIC));
    when(bridge.getHalfMessage(0, 0, 1)).thenReturn(createPullResult(TopicValidator.RMQ_SYS_TRANS_HALF_TOPIC, 5, "hello", 1));
    when(bridge.getHalfMessage(0, 1, 1)).thenReturn(createPullResult(TopicValidator.RMQ_SYS_TRANS_HALF_TOPIC, 6, "hellp", 0));
    when(bridge.getOpMessage(anyInt(), anyLong(), anyInt())).thenReturn(createPullResult(TopicValidator.RMQ_SYS_TRANS_OP_HALF_TOPIC, 1, "5", 0));
    when(bridge.getBrokerController()).thenReturn(this.brokerController);
    when(bridge.renewHalfMessageInner(any(MessageExtBrokerInner.class))).thenReturn(createMessageBrokerInner());
    when(bridge.putMessageReturnResult(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    long timeOut = this.brokerController.getBrokerConfig().getTransactionTimeOut();
    final int checkMax = this.brokerController.getBrokerConfig().getTransactionCheckMax();
    final AtomicInteger checkMessage = new AtomicInteger(0);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            checkMessage.addAndGet(1);
            return checkMessage;
        }
    }).when(listener).resolveHalfMsg(any(MessageExt.class));
    queueTransactionMsgService.check(timeOut, checkMax, listener);
    assertThat(checkMessage.get()).isEqualTo(1);
}
 
Example #4
Source File: TransactionalMessageServiceImplTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheck_withCheck() {
    when(bridge.fetchMessageQueues(MixAll.RMQ_SYS_TRANS_HALF_TOPIC)).thenReturn(createMessageQueueSet(MixAll.RMQ_SYS_TRANS_HALF_TOPIC));
    when(bridge.getHalfMessage(0, 0, 1)).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_HALF_TOPIC, 5, "hello", 1));
    when(bridge.getHalfMessage(0, 1, 1)).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_HALF_TOPIC, 6, "hellp", 0));
    when(bridge.getOpMessage(anyInt(), anyLong(), anyInt())).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_OP_HALF_TOPIC, 1, "5", 0));
    when(bridge.getBrokerController()).thenReturn(this.brokerController);
    when(bridge.renewHalfMessageInner(any(MessageExtBrokerInner.class))).thenReturn(createMessageBrokerInner());
    when(bridge.putMessageReturnResult(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    long timeOut = this.brokerController.getBrokerConfig().getTransactionTimeOut();
    final int checkMax = this.brokerController.getBrokerConfig().getTransactionCheckMax();
    final AtomicInteger checkMessage = new AtomicInteger(0);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            checkMessage.addAndGet(1);
            return checkMessage;
        }
    }).when(listener).resolveHalfMsg(any(MessageExt.class));
    queueTransactionMsgService.check(timeOut, checkMax, listener);
    assertThat(checkMessage.get()).isEqualTo(1);
}
 
Example #5
Source File: TransactionalMessageServiceImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private boolean putBackHalfMsgQueue(MessageExt msgExt, long offset) {
    PutMessageResult putMessageResult = putBackToHalfQueueReturnResult(msgExt);
    if (putMessageResult != null
        && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {
        msgExt.setQueueOffset(
            putMessageResult.getAppendMessageResult().getLogicsOffset());
        msgExt.setCommitLogOffset(
            putMessageResult.getAppendMessageResult().getWroteOffset());
        msgExt.setMsgId(putMessageResult.getAppendMessageResult().getMsgId());
        log.debug(
            "Send check message, the offset={} restored in queueOffset={} "
                + "commitLogOffset={} "
                + "newMsgId={} realMsgId={} topic={}",
            offset, msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), msgExt.getMsgId(),
            msgExt.getUserProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX),
            msgExt.getTopic());
        return true;
    } else {
        log.error(
            "PutBackToHalfQueueReturnResult write failed, topic: {}, queueId: {}, "
                + "msgId: {}",
            msgExt.getTopic(), msgExt.getQueueId(), msgExt.getMsgId());
        return false;
    }
}
 
Example #6
Source File: HAService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private void doWaitTransfer() {
    synchronized (this.requestsRead) {
        if (!this.requestsRead.isEmpty()) {
            for (CommitLog.GroupCommitRequest req : this.requestsRead) {
                boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset();
                long waitUntilWhen = HAService.this.defaultMessageStore.getSystemClock().now()
                    + HAService.this.defaultMessageStore.getMessageStoreConfig().getSyncFlushTimeout();
                while (!transferOK && HAService.this.defaultMessageStore.getSystemClock().now() < waitUntilWhen) {
                    this.notifyTransferObject.waitForRunning(1000);
                    transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset();
                }

                if (!transferOK) {
                    log.warn("transfer messsage to slave timeout, " + req.getNextOffset());
                }

                req.wakeupCustomer(transferOK ? PutMessageStatus.PUT_OK : PutMessageStatus.FLUSH_SLAVE_TIMEOUT);
            }

            this.requestsRead.clear();
        }
    }
}
 
Example #7
Source File: TransactionalMessageServiceImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheck_withCheck() {
    when(bridge.fetchMessageQueues(MixAll.RMQ_SYS_TRANS_HALF_TOPIC)).thenReturn(createMessageQueueSet(MixAll.RMQ_SYS_TRANS_HALF_TOPIC));
    when(bridge.getHalfMessage(0, 0, 1)).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_HALF_TOPIC, 5, "hello", 1));
    when(bridge.getHalfMessage(0, 1, 1)).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_HALF_TOPIC, 6, "hellp", 0));
    when(bridge.getOpMessage(anyInt(), anyLong(), anyInt())).thenReturn(createPullResult(MixAll.RMQ_SYS_TRANS_OP_HALF_TOPIC, 1, "5", 0));
    when(bridge.getBrokerController()).thenReturn(this.brokerController);
    when(bridge.renewHalfMessageInner(any(MessageExtBrokerInner.class))).thenReturn(createMessageBrokerInner());
    when(bridge.putMessageReturnResult(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    long timeOut = this.brokerController.getBrokerConfig().getTransactionTimeOut();
    final int checkMax = this.brokerController.getBrokerConfig().getTransactionCheckMax();
    final AtomicInteger checkMessage = new AtomicInteger(0);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            checkMessage.addAndGet(1);
            return checkMessage;
        }
    }).when(listener).resolveHalfMsg(any(MessageExt.class));
    queueTransactionMsgService.check(timeOut, checkMax, listener);
    assertThat(checkMessage.get()).isEqualTo(1);
}
 
Example #8
Source File: TransactionalMessageBridgeTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutHalfMessage() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    PutMessageResult result = transactionBridge.putHalfMessage(createMessageBrokerInner());
    assertThat(result.getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
}
 
Example #9
Source File: TransactionalMessageBridge.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public boolean putMessage(MessageExtBrokerInner messageInner) {
//        存储消息=》
        PutMessageResult putMessageResult = store.putMessage(messageInner);
        if (putMessageResult != null
            && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {
            return true;
        } else {
            LOGGER.error("Put message failed, topic: {}, queueId: {}, msgId: {}",
                messageInner.getTopic(), messageInner.getQueueId(), messageInner.getMsgId());
            return false;
        }
    }
 
Example #10
Source File: SendMessageProcessorTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_WithMsgBack() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    final RemotingCommand request = createSendMsgBackCommand(RequestCode.CONSUMER_SEND_MSG_BACK);

    sendMessageProcessor = new SendMessageProcessor(brokerController);
    final RemotingCommand response = sendMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #11
Source File: TransactionalMessageBridgeTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessage() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    Boolean success = transactionBridge.putMessage(createMessageBrokerInner());
    assertThat(success).isEqualTo(true);
}
 
Example #12
Source File: AdminBrokerProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_fail() throws RemotingCommandException, UnknownHostException {
    RemotingCommand request = createResumeCheckHalfMessageCommand();
    when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult());
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
            (PutMessageStatus.UNKNOWN_ERROR, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR)));
    RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
}
 
Example #13
Source File: TransactionalMessageBridgeTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessage() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    Boolean success = transactionBridge.putMessage(createMessageBrokerInner());
    assertThat(success).isEqualTo(true);
}
 
Example #14
Source File: EndTransactionProcessorTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest() throws RemotingCommandException {
    when(transactionMsgService.commitMessage(any(EndTransactionRequestHeader.class))).thenReturn(createResponse(ResponseCode.SUCCESS));
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    RemotingCommand request = createEndTransactionMsgCommand(MessageSysFlag.TRANSACTION_COMMIT_TYPE, false);
    RemotingCommand response = endTransactionProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #15
Source File: TransactionalMessageBridgeTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutHalfMessage() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    PutMessageResult result = transactionBridge.putHalfMessage(createMessageBrokerInner());
    assertThat(result.getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
}
 
Example #16
Source File: EndTransactionProcessorTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_CheckMessage() throws RemotingCommandException {
    when(transactionMsgService.commitMessage(any(EndTransactionRequestHeader.class))).thenReturn(createResponse(ResponseCode.SUCCESS));
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    RemotingCommand request = createEndTransactionMsgCommand(MessageSysFlag.TRANSACTION_COMMIT_TYPE, true);
    RemotingCommand response = endTransactionProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #17
Source File: EndTransactionProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest() throws RemotingCommandException {
    when(transactionMsgService.commitMessage(any(EndTransactionRequestHeader.class))).thenReturn(createResponse(ResponseCode.SUCCESS));
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    RemotingCommand request = createEndTransactionMsgCommand(MessageSysFlag.TRANSACTION_COMMIT_TYPE, false);
    RemotingCommand response = endTransactionProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #18
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private RemotingCommand resumeCheckHalfMessage(ChannelHandlerContext ctx,
    RemotingCommand request)
    throws RemotingCommandException {
    final ResumeCheckHalfMessageRequestHeader requestHeader = (ResumeCheckHalfMessageRequestHeader) request
        .decodeCommandCustomHeader(ResumeCheckHalfMessageRequestHeader.class);
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore()
            .selectOneMessageByOffset(messageId.getOffset());
        MessageExt msg = MessageDecoder.decode(selectMappedBufferResult.getByteBuffer());
        msg.putUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, String.valueOf(0));
        PutMessageResult putMessageResult = this.brokerController.getMessageStore()
            .putMessage(toMessageExtBrokerInner(msg));
        if (putMessageResult != null
            && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {
            log.info(
                "Put message back to RMQ_SYS_TRANS_HALF_TOPIC. real topic={}",
                msg.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC));
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
        } else {
            log.error("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed.");
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed.");
        }
    } catch (Exception e) {
        log.error("Exception was thrown when putting message back to RMQ_SYS_TRANS_HALF_TOPIC.");
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("Exception was thrown when putting message back to RMQ_SYS_TRANS_HALF_TOPIC.");
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }
    return response;
}
 
Example #19
Source File: TransactionalMessageBridgeTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessageReturnResult() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    PutMessageResult result = transactionBridge.putMessageReturnResult(createMessageBrokerInner());
    assertThat(result.getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
}
 
Example #20
Source File: DeFiPluginMessageStoreTest.java    From DeFiBus with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessage(){
    MessageExtBrokerInner inner = new MessageExtBrokerInner();
    when(messageStore.putMessage(inner)).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    PutMessageResult result = deFiPluginMessageStore.putMessage(inner);
    assertThat(result.getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
    assertTrue(result.getAppendMessageResult().isOk());
}
 
Example #21
Source File: TransactionalMessageServiceImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 如果需要发送事务状态回查消息,
 * 则先将消息再次发送到RMQ_SYS_TRANS_HALF_TOPIC主题中,发送成功则返回true,否则返回false,这里还有一个实现关键点:
 * @param msgExt ;
 * @param offset ;
 * @return ;
 */
private boolean putBackHalfMsgQueue(MessageExt msgExt, long offset) {
    PutMessageResult putMessageResult = putBackToHalfQueueReturnResult(msgExt);
    if (putMessageResult != null
        && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {

        msgExt.setQueueOffset(
            putMessageResult.getAppendMessageResult().getLogicsOffset());

        msgExt.setCommitLogOffset(
            putMessageResult.getAppendMessageResult().getWroteOffset());

        msgExt.setMsgId(putMessageResult.getAppendMessageResult().getMsgId());

        log.info(
            "Send check message, the offset={} restored in queueOffset={} "
                + "commitLogOffset={} "
                + "newMsgId={} realMsgId={} topic={}",
            offset, msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), msgExt.getMsgId(),
            msgExt.getUserProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX),
            msgExt.getTopic());
        return true;
    } else {
        log.error(
            "PutBackToHalfQueueReturnResult write failed, topic: {}, queueId: {}, "
                + "msgId: {}",
            msgExt.getTopic(), msgExt.getQueueId(), msgExt.getMsgId());
        return false;
    }
}
 
Example #22
Source File: TransactionalMessageBridgeTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessageReturnResult() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    PutMessageResult result = transactionBridge.putMessageReturnResult(createMessageBrokerInner());
    assertThat(result.getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
}
 
Example #23
Source File: TransactionalMessageBridgeTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutMessage() {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    Boolean success = transactionBridge.putMessage(createMessageBrokerInner());
    assertThat(success).isEqualTo(true);
}
 
Example #24
Source File: EndTransactionProcessorTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest() throws RemotingCommandException {
    when(transactionMsgService.commitMessage(any(EndTransactionRequestHeader.class))).thenReturn(createResponse(ResponseCode.SUCCESS));
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult
        (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    RemotingCommand request = createEndTransactionMsgCommand(MessageSysFlag.TRANSACTION_COMMIT_TYPE, false);
    RemotingCommand response = endTransactionProcessor.processRequest(handlerContext, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #25
Source File: TransactionalMessageBridge.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public boolean putMessage(MessageExtBrokerInner messageInner) {
    PutMessageResult putMessageResult = store.putMessage(messageInner);
    if (putMessageResult != null
        && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) {
        return true;
    } else {
        LOGGER.error("Put message failed, topic: {}, queueId: {}, msgId: {}",
            messageInner.getTopic(), messageInner.getQueueId(), messageInner.getMsgId());
        return false;
    }
}
 
Example #26
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 #27
Source File: DLedgerCommitlogTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommittedPos() throws Exception {
    String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0);

    String topic = UUID.randomUUID().toString();
    MessageExtBrokerInner msgInner =  buildMessage();
    msgInner.setTopic(topic);
    msgInner.setQueueId(0);
    PutMessageResult putMessageResult = leaderStore.putMessage(msgInner);
    Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus());

    Thread.sleep(1000);

    Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset());
    Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0));


    DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0);
    Thread.sleep(2000);

    Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);


    leaderStore.destroy();
    followerStore.destroy();

    leaderStore.shutdown();
    followerStore.shutdown();
}
 
Example #28
Source File: MessageStoreTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
protected void doPutMessages(MessageStore messageStore, String topic, int queueId, int num, long beginLogicsOffset) throws UnknownHostException {
    for (int i = 0; i < num; i++) {
        MessageExtBrokerInner msgInner = buildMessage();
        msgInner.setTopic(topic);
        msgInner.setQueueId(queueId);
        PutMessageResult putMessageResult = messageStore.putMessage(msgInner);
        Assert.assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus());
        Assert.assertEquals(beginLogicsOffset + i, putMessageResult.getAppendMessageResult().getLogicsOffset());
    }
}
 
Example #29
Source File: SendMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessRequest_WithMsgBack() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    final RemotingCommand request = createSendMsgBackCommand(RequestCode.CONSUMER_SEND_MSG_BACK);

    sendMessageProcessor = new SendMessageProcessor(brokerController);
    final RemotingCommand response = sendMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
}
 
Example #30
Source File: TransactionalMessageBridgeTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncPutHalfMessage() throws Exception {
    when(messageStore.asyncPutMessage(any(MessageExtBrokerInner.class)))
            .thenReturn(CompletableFuture.completedFuture(new PutMessageResult(PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))));
    CompletableFuture<PutMessageResult> result = transactionBridge.asyncPutHalfMessage(createMessageBrokerInner());
    assertThat(result.get().getPutMessageStatus()).isEqualTo(PutMessageStatus.PUT_OK);
}