Search in sources :

Example 11 with PutMessageResult

use of org.apache.rocketmq.store.PutMessageResult in project rocketmq by apache.

the class SendMessageProcessorTest method testProcessRequest_WithHook.

@Test
public void testProcessRequest_WithHook() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK)));
    List<SendMessageHook> sendMessageHookList = new ArrayList<>();
    final SendMessageContext[] sendMessageContext = new SendMessageContext[1];
    SendMessageHook sendMessageHook = new SendMessageHook() {

        @Override
        public String hookName() {
            return null;
        }

        @Override
        public void sendMessageBefore(SendMessageContext context) {
            sendMessageContext[0] = context;
        }

        @Override
        public void sendMessageAfter(SendMessageContext context) {
        }
    };
    sendMessageHookList.add(sendMessageHook);
    sendMessageProcessor.registerSendMessageHook(sendMessageHookList);
    assertPutResult(ResponseCode.SUCCESS);
    System.out.println(sendMessageContext[0]);
    assertThat(sendMessageContext[0]).isNotNull();
    assertThat(sendMessageContext[0].getTopic()).isEqualTo(topic);
    assertThat(sendMessageContext[0].getProducerGroup()).isEqualTo(group);
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) SendMessageContext(org.apache.rocketmq.broker.mqtrace.SendMessageContext) ArrayList(java.util.ArrayList) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) AppendMessageResult(org.apache.rocketmq.store.AppendMessageResult) SendMessageHook(org.apache.rocketmq.broker.mqtrace.SendMessageHook) Test(org.junit.Test)

Example 12 with PutMessageResult

use of org.apache.rocketmq.store.PutMessageResult in project rocketmq by apache.

the class SendMessageProcessorTest method testProcessRequest_MessageIllegal.

@Test
public void testProcessRequest_MessageIllegal() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.MESSAGE_ILLEGAL, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR)));
    assertPutResult(ResponseCode.MESSAGE_ILLEGAL);
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) AppendMessageResult(org.apache.rocketmq.store.AppendMessageResult) Test(org.junit.Test)

Example 13 with PutMessageResult

use of org.apache.rocketmq.store.PutMessageResult in project rocketmq by apache.

the class SendMessageProcessorTest method testProcessRequest_WithMsgBack.

@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);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) PutMessageResult(org.apache.rocketmq.store.PutMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) AppendMessageResult(org.apache.rocketmq.store.AppendMessageResult) Test(org.junit.Test)

Example 14 with PutMessageResult

use of org.apache.rocketmq.store.PutMessageResult in project rocketmq by apache.

the class SendMessageProcessorTest method testProcessRequest_PropertiesTooLong.

@Test
public void testProcessRequest_PropertiesTooLong() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.PROPERTIES_SIZE_EXCEEDED, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR)));
    assertPutResult(ResponseCode.MESSAGE_ILLEGAL);
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) AppendMessageResult(org.apache.rocketmq.store.AppendMessageResult) Test(org.junit.Test)

Example 15 with PutMessageResult

use of org.apache.rocketmq.store.PutMessageResult in project rocketmq by apache.

the class SendMessageProcessorTest method testProcessRequest_FlushSlaveTimeout.

@Test
public void testProcessRequest_FlushSlaveTimeout() throws RemotingCommandException {
    when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.FLUSH_SLAVE_TIMEOUT, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR)));
    assertPutResult(ResponseCode.FLUSH_SLAVE_TIMEOUT);
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) AppendMessageResult(org.apache.rocketmq.store.AppendMessageResult) Test(org.junit.Test)

Aggregations

PutMessageResult (org.apache.rocketmq.store.PutMessageResult)34 MessageExtBrokerInner (org.apache.rocketmq.store.MessageExtBrokerInner)32 AppendMessageResult (org.apache.rocketmq.store.AppendMessageResult)22 Test (org.junit.Test)22 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)10 TopicConfig (org.apache.rocketmq.common.TopicConfig)6 ArrayList (java.util.ArrayList)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 SendMessageResponseHeader (org.apache.rocketmq.common.protocol.header.SendMessageResponseHeader)4 ConsumeMessageContext (org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext)2 SendMessageContext (org.apache.rocketmq.broker.mqtrace.SendMessageContext)2 SendMessageHook (org.apache.rocketmq.broker.mqtrace.SendMessageHook)2 MessageExtBatch (org.apache.rocketmq.common.message.MessageExtBatch)2 ConsumerSendMsgBackRequestHeader (org.apache.rocketmq.common.protocol.header.ConsumerSendMsgBackRequestHeader)2 EndTransactionRequestHeader (org.apache.rocketmq.common.protocol.header.EndTransactionRequestHeader)2 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 MessageStore (org.apache.rocketmq.store.MessageStore)2