Search in sources :

Example 11 with GetMessageResult

use of org.apache.rocketmq.store.GetMessageResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MessageStoreWithFilterTest method testGetMessage_withFilterBitMapAndConsumerChanged.

@Test
public void testGetMessage_withFilterBitMapAndConsumerChanged() {
    int topicCount = 10, msgPerTopic = 10;
    ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic);
    DefaultMessageStore master = null;
    try {
        master = gen(filterManager);
    } catch (Exception e) {
        e.printStackTrace();
        assertThat(true).isFalse();
    }
    try {
        List<MessageExtBrokerInner> msgs = null;
        try {
            msgs = putMsg(master, topicCount, msgPerTopic);
        } catch (Exception e) {
            e.printStackTrace();
            assertThat(true).isFalse();
        }
        // sleep to wait for consume queue has been constructed.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
            assertThat(true).isFalse();
        }
        // reset consumer;
        String topic = "topic" + 0;
        String resetGroup = "CID_" + 2;
        String normalGroup = "CID_" + 3;
        {
            // reset CID_2@topic0 to get all messages.
            SubscriptionData resetSubData = new SubscriptionData();
            resetSubData.setExpressionType(ExpressionType.SQL92);
            resetSubData.setTopic(topic);
            resetSubData.setClassFilterMode(false);
            resetSubData.setSubString("a is not null OR a is null");
            ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), System.currentTimeMillis());
            GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager));
            try {
                assertThat(resetGetResult).isNotNull();
                List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, resetFilterData);
                assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
            } finally {
                resetGetResult.release();
            }
        }
        {
            ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup);
            assertThat(normalFilterData).isNotNull();
            assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis());
            SubscriptionData normalSubData = new SubscriptionData();
            normalSubData.setExpressionType(normalFilterData.getExpressionType());
            normalSubData.setTopic(topic);
            normalSubData.setClassFilterMode(false);
            normalSubData.setSubString(normalFilterData.getExpression());
            List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, normalFilterData);
            GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager));
            try {
                assertThat(normalGetResult).isNotNull();
                assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
            } finally {
                normalGetResult.release();
            }
        }
    } finally {
        master.shutdown();
        master.destroy();
        deleteDirectory(storePath);
    }
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) UnknownHostException(java.net.UnknownHostException) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 12 with GetMessageResult

use of org.apache.rocketmq.store.GetMessageResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessorTest method testProcessRequest_NoMsgInQueue.

@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);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetMessageResult(org.apache.rocketmq.store.GetMessageResult) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) Test(org.junit.Test)

Example 13 with GetMessageResult

use of org.apache.rocketmq.store.GetMessageResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessorTest method createGetMessageResult.

private GetMessageResult createGetMessageResult() {
    GetMessageResult getMessageResult = new GetMessageResult();
    getMessageResult.setStatus(GetMessageStatus.FOUND);
    getMessageResult.setMinOffset(100);
    getMessageResult.setMaxOffset(1024);
    getMessageResult.setNextBeginOffset(516);
    return getMessageResult;
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult)

Example 14 with GetMessageResult

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

the class MessageStoreWithFilterTest method testGetMessage_withFilterBitMap.

@Test
public void testGetMessage_withFilterBitMap() throws Exception {
    List<MessageExtBrokerInner> msgs = putMsg(master, topicCount, msgPerTopic);
    Thread.sleep(100);
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgPerTopic; j++) {
            String group = "CID_" + j;
            ConsumerFilterData filterData = filterManager.get(realTopic, group);
            assertThat(filterData).isNotNull();
            List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, filterData);
            SubscriptionData subscriptionData = new SubscriptionData();
            subscriptionData.setExpressionType(filterData.getExpressionType());
            subscriptionData.setTopic(filterData.getTopic());
            subscriptionData.setClassFilterMode(false);
            subscriptionData.setSubString(filterData.getExpression());
            GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, new ExpressionMessageFilter(subscriptionData, filterData, filterManager));
            String assertMsg = group + "-" + realTopic;
            try {
                assertThat(getMessageResult).isNotNull();
                assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus());
                assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty();
                assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
                for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) {
                    MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false);
                    assertThat(messageExt).isNotNull();
                    Object evlRet = null;
                    try {
                        evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties()));
                    } catch (Exception e) {
                        e.printStackTrace();
                        assertThat(true).isFalse();
                    }
                    assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE);
                    // check
                    boolean find = false;
                    for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) {
                        if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) {
                            find = true;
                        }
                    }
                    assertThat(find).isTrue();
                }
            } finally {
                getMessageResult.release();
            }
        }
    }
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) ByteBuffer(java.nio.ByteBuffer) UnknownHostException(java.net.UnknownHostException) MessageExt(org.apache.rocketmq.common.message.MessageExt) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Test(org.junit.Test)

Example 15 with GetMessageResult

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

the class MessageStoreWithFilterTest method testGetMessage_withFilter_checkTagsCode.

@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);
    }
}
Also used : ConsumeQueueExt(org.apache.rocketmq.store.ConsumeQueueExt) GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageFilter(org.apache.rocketmq.store.MessageFilter) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

GetMessageResult (org.apache.rocketmq.store.GetMessageResult)17 Test (org.junit.Test)13 ExpressionMessageFilter (org.apache.rocketmq.broker.filter.ExpressionMessageFilter)10 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)10 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)6 ArrayList (java.util.ArrayList)4 ConsumeMessageContext (org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext)4 MessageExtBrokerInner (org.apache.rocketmq.store.MessageExtBrokerInner)4 UnknownHostException (java.net.UnknownHostException)3 ByteBuffer (java.nio.ByteBuffer)3 MessageFilter (org.apache.rocketmq.store.MessageFilter)3 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 FileRegion (io.netty.channel.FileRegion)2 List (java.util.List)2 ConsumerGroupInfo (org.apache.rocketmq.broker.client.ConsumerGroupInfo)2 ConsumerFilterData (org.apache.rocketmq.broker.filter.ConsumerFilterData)2 ExpressionForRetryMessageFilter (org.apache.rocketmq.broker.filter.ExpressionForRetryMessageFilter)2 PullRequest (org.apache.rocketmq.broker.longpolling.PullRequest)2 ConsumeMessageHook (org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook)2