use of org.apache.rocketmq.store.MessageExtBrokerInner 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);
}
}
use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class MessageStoreWithFilterTest method putMsg.
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception {
List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
for (int i = 0; i < topicCount; i++) {
String realTopic = topic + i;
for (int j = 0; j < msgCountPerTopic; j++) {
MessageExtBrokerInner msg = buildMessage();
msg.setTopic(realTopic);
msg.putUserProperty("a", String.valueOf(j * 10 + 5));
msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
PutMessageResult result = master.putMessage(msg);
msg.setMsgId(result.getAppendMessageResult().getMsgId());
msgs.add(msg);
}
}
return msgs;
}
use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq by apache.
the class EndTransactionProcessor method endMessageTransaction.
private MessageExtBrokerInner endMessageTransaction(MessageExt msgExt) {
MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
msgInner.setBody(msgExt.getBody());
msgInner.setFlag(msgExt.getFlag());
MessageAccessor.setProperties(msgInner, msgExt.getProperties());
TopicFilterType topicFilterType = (msgInner.getSysFlag() & MessageSysFlag.MULTI_TAGS_FLAG) == MessageSysFlag.MULTI_TAGS_FLAG ? TopicFilterType.MULTI_TAG : TopicFilterType.SINGLE_TAG;
long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags());
msgInner.setTagsCode(tagsCodeValue);
msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties()));
msgInner.setSysFlag(msgExt.getSysFlag());
msgInner.setBornTimestamp(msgExt.getBornTimestamp());
msgInner.setBornHost(msgExt.getBornHost());
msgInner.setStoreHost(msgExt.getStoreHost());
msgInner.setReconsumeTimes(msgExt.getReconsumeTimes());
msgInner.setWaitStoreMsgOK(false);
MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL);
msgInner.setTopic(msgExt.getTopic());
msgInner.setQueueId(msgExt.getQueueId());
return msgInner;
}
use of org.apache.rocketmq.store.MessageExtBrokerInner 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();
}
}
}
}
use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq by apache.
the class MessageStoreWithFilterTest method putMsg.
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception {
List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>();
for (int i = 0; i < topicCount; i++) {
String realTopic = topic + i;
for (int j = 0; j < msgCountPerTopic; j++) {
MessageExtBrokerInner msg = buildMessage();
msg.setTopic(realTopic);
msg.putUserProperty("a", String.valueOf(j * 10 + 5));
msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
PutMessageResult result = master.putMessage(msg);
msg.setMsgId(result.getAppendMessageResult().getMsgId());
msgs.add(msg);
}
}
return msgs;
}
Aggregations