Skip to content

Commit 9e7af1c

Browse files
committed
for #3666 add unit test more
1 parent b40d06e commit 9e7af1c

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.rocketmq.broker;
19+
20+
import org.junit.Test;
21+
22+
import static org.junit.Assert.*;
23+
24+
public class BrokerPathConfigHelperTest {
25+
26+
@Test
27+
public void testGetLmqConsumerOffsetPath() {
28+
String lmqConsumerOffsetPath = BrokerPathConfigHelper.getLmqConsumerOffsetPath("/home/admin/store");
29+
assertEquals("/home/admin/store/config/lmqConsumerOffset.json", lmqConsumerOffsetPath);
30+
31+
32+
String consumerOffsetPath = BrokerPathConfigHelper.getConsumerOffsetPath("/home/admin/store");
33+
assertEquals("/home/admin/store/config/consumerOffset.json", consumerOffsetPath);
34+
35+
String topicConfigPath = BrokerPathConfigHelper.getTopicConfigPath("/home/admin/store");
36+
assertEquals("/home/admin/store/config/topics.json", topicConfigPath);
37+
38+
String subscriptionGroupPath = BrokerPathConfigHelper.getSubscriptionGroupPath("/home/admin/store");
39+
assertEquals("/home/admin/store/config/subscriptionGroup.json", subscriptionGroupPath);
40+
41+
}
42+
}

store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java

+91
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import org.apache.rocketmq.common.BrokerConfig;
2929
import org.apache.rocketmq.common.UtilAll;
30+
import org.apache.rocketmq.common.message.MessageConst;
3031
import org.apache.rocketmq.common.message.MessageDecoder;
3132
import org.apache.rocketmq.store.config.MessageStoreConfig;
3233
import org.apache.rocketmq.store.stats.BrokerStatsManager;
@@ -146,6 +147,34 @@ public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
146147
return master;
147148
}
148149

150+
protected DefaultMessageStore genForMultiQueue() throws Exception {
151+
MessageStoreConfig messageStoreConfig = buildStoreConfig(
152+
commitLogFileSize, cqFileSize, true, cqExtFileSize
153+
);
154+
155+
messageStoreConfig.setEnableLmq(true);
156+
messageStoreConfig.setEnableMultiDispatch(true);
157+
158+
BrokerConfig brokerConfig = new BrokerConfig();
159+
160+
DefaultMessageStore master = new DefaultMessageStore(
161+
messageStoreConfig,
162+
new BrokerStatsManager(brokerConfig.getBrokerClusterName(), brokerConfig.isEnableDetailStat()),
163+
new MessageArrivingListener() {
164+
@Override
165+
public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
166+
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
167+
}
168+
}
169+
, brokerConfig);
170+
171+
assertThat(master.load()).isTrue();
172+
173+
master.start();
174+
175+
return master;
176+
}
177+
149178
protected void putMsg(DefaultMessageStore master) throws Exception {
150179
long totalMsgs = 200;
151180

@@ -158,6 +187,33 @@ protected void putMsg(DefaultMessageStore master) throws Exception {
158187
}
159188
}
160189

190+
protected void putMsgMultiQueue(DefaultMessageStore master) throws Exception {
191+
for (long i = 0; i < 1; i++) {
192+
master.putMessage(buildMessageMultiQueue());
193+
}
194+
}
195+
196+
private MessageExtBrokerInner buildMessageMultiQueue() {
197+
MessageExtBrokerInner msg = new MessageExtBrokerInner();
198+
msg.setTopic(topic);
199+
msg.setTags("TAG1");
200+
msg.setKeys("Hello");
201+
msg.setBody(msgBody);
202+
msg.setKeys(String.valueOf(System.currentTimeMillis()));
203+
msg.setQueueId(queueId);
204+
msg.setSysFlag(0);
205+
msg.setBornTimestamp(System.currentTimeMillis());
206+
msg.setStoreHost(StoreHost);
207+
msg.setBornHost(BornHost);
208+
for (int i = 0; i < 1; i++) {
209+
msg.putUserProperty(MessageConst.PROPERTY_INNER_MULTI_DISPATCH, "%LMQ%123,%LMQ%456");
210+
msg.putUserProperty(String.valueOf(i), "imagoodperson" + i);
211+
}
212+
msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
213+
214+
return msg;
215+
}
216+
161217
protected void deleteDirectory(String rootPath) {
162218
File file = new File(rootPath);
163219
deleteFile(file);
@@ -217,6 +273,41 @@ public void testPutMessagePositionInfo_buildCQRepeatedly() throws Exception {
217273

218274
}
219275

276+
@Test
277+
public void testPutMessagePositionInfoMultiQueue() throws Exception {
278+
DefaultMessageStore messageStore = null;
279+
try {
280+
281+
messageStore = genForMultiQueue();
282+
283+
int totalMessages = 10;
284+
285+
for (int i = 0; i < totalMessages; i++) {
286+
putMsgMultiQueue(messageStore);
287+
}
288+
Thread.sleep(5);
289+
290+
ConsumeQueue cq = messageStore.getConsumeQueueTable().get(topic).get(queueId);
291+
292+
ConsumeQueue lmqCq1 = messageStore.getConsumeQueueTable().get("%LMQ%123").get(0);
293+
294+
ConsumeQueue lmqCq2 = messageStore.getConsumeQueueTable().get("%LMQ%456").get(0);
295+
296+
assertThat(cq).isNotNull();
297+
298+
assertThat(lmqCq1).isNotNull();
299+
300+
assertThat(lmqCq2).isNotNull();
301+
302+
} finally {
303+
if (messageStore != null) {
304+
messageStore.shutdown();
305+
messageStore.destroy();
306+
}
307+
deleteDirectory(storePath);
308+
}
309+
}
310+
220311
@Test
221312
public void testConsumeQueueWithExtendData() {
222313
DefaultMessageStore master = null;

0 commit comments

Comments
 (0)