Skip to content

Commit

Permalink
[ROCKETMQ-56] Polish unit tests for rocketmq-store
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouxinyu committed Jan 22, 2017
1 parent e9a87ea commit 881aef5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,28 @@
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.store.config.FlushDiskType;
import org.apache.rocketmq.store.config.MessageStoreConfig;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;

public class DefaultMessageStoreTest {
private static final Logger logger = LoggerFactory.getLogger(DefaultMessageStoreTest.class);

private static final String StoreMessage = "Once, there was a chance for me!";

private static int QUEUE_TOTAL = 100;

private static AtomicInteger QueueId = new AtomicInteger(0);

private static SocketAddress BornHost;

private static SocketAddress StoreHost;

private static byte[] MessageBody;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
private final String StoreMessage = "Once, there was a chance for me!";
private int QUEUE_TOTAL = 100;
private AtomicInteger QueueId = new AtomicInteger(0);
private SocketAddress BornHost;
private SocketAddress StoreHost;
private byte[] MessageBody;

@Before
public void init() throws Exception {
StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0);
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Test
public void test_write_read() throws Exception {
logger.debug("================================================================");
public void testWriteAndRead() throws Exception {
long totalMsgs = 100;
QUEUE_TOTAL = 1;
MessageBody = StoreMessage.getBytes();
Expand All @@ -77,29 +63,23 @@ public void test_write_read() throws Exception {
master.start();
try {
for (long i = 0; i < totalMsgs; i++) {
PutMessageResult result = master.putMessage(buildMessage());
logger.debug(i + "\t" + result.getAppendMessageResult().getMsgId());
master.putMessage(buildMessage());
}

for (long i = 0; i < totalMsgs; i++) {
GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null);
if (result == null) {
logger.debug("result == null " + i);
}
assertTrue(result != null);
assertThat(result).isNotNull();
result.release();
logger.debug("read " + i + " OK");
}
} finally {
master.shutdown();
master.destroy();
}
logger.debug("================================================================");
}

public MessageExtBrokerInner buildMessage() {
MessageExtBrokerInner msg = new MessageExtBrokerInner();
msg.setTopic("AAA");
msg.setTopic("FooBar");
msg.setTags("TAG1");
msg.setKeys("Hello");
msg.setBody(MessageBody);
Expand All @@ -113,8 +93,7 @@ public MessageExtBrokerInner buildMessage() {
}

@Test
public void test_group_commit() throws Exception {
logger.debug("================================================================");
public void testGroupCommit() throws Exception {
long totalMsgs = 100;
QUEUE_TOTAL = 1;
MessageBody = StoreMessage.getBytes();
Expand All @@ -128,32 +107,24 @@ public void test_group_commit() throws Exception {
master.start();
try {
for (long i = 0; i < totalMsgs; i++) {
PutMessageResult result = master.putMessage(buildMessage());
logger.debug(i + "\t" + result.getAppendMessageResult().getMsgId());
master.putMessage(buildMessage());
}

for (long i = 0; i < totalMsgs; i++) {
GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null);
if (result == null) {
logger.debug("result == null " + i);
}
assertTrue(result != null);
assertThat(result).isNotNull();
result.release();
logger.debug("read " + i + " OK");

}
} finally {
master.shutdown();
master.destroy();
}
logger.debug("================================================================");
}

private class MyMessageArrivingListener implements MessageArrivingListener {

@Override
public void arriving(String topic, int queueId, long logicOffset, long tagsCode) {
// Do nothing here
}
}
}
Loading

0 comments on commit 881aef5

Please sign in to comment.