Java Code Examples for org.apache.rocketmq.store.DefaultMessageStore#destroy()

The following examples show how to use org.apache.rocketmq.store.DefaultMessageStore#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DLedgerCommitlogTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutAndGetMessage() throws Exception {
    String base =  createBaseDir();
    String peers = String.format("n0-localhost:%d", nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore messageStore = createDledgerMessageStore(base, group, "n0", peers, null, false, 0);
    Thread.sleep(1000);
    String topic = UUID.randomUUID().toString();

    List<PutMessageResult> results = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        MessageExtBrokerInner msgInner =
            i < 5 ? buildMessage() : buildIPv6HostMessage();
        msgInner.setTopic(topic);
        msgInner.setQueueId(0);
        PutMessageResult putMessageResult = messageStore.putMessage(msgInner);
        results.add(putMessageResult);
        Assert.assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus());
        Assert.assertEquals(i, putMessageResult.getAppendMessageResult().getLogicsOffset());
    }
    Thread.sleep(100);
    Assert.assertEquals(0, messageStore.getMinOffsetInQueue(topic, 0));
    Assert.assertEquals(10, messageStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(0, messageStore.dispatchBehindBytes());
    GetMessageResult getMessageResult =  messageStore.getMessage("group", topic, 0, 0, 32, null);
    Assert.assertEquals(GetMessageStatus.FOUND, getMessageResult.getStatus());

    Assert.assertEquals(10, getMessageResult.getMessageBufferList().size());
    Assert.assertEquals(10, getMessageResult.getMessageMapedList().size());

    for (int i = 0; i < results.size(); i++) {
        ByteBuffer buffer = getMessageResult.getMessageBufferList().get(i);
        MessageExt messageExt = MessageDecoder.decode(buffer);
        Assert.assertEquals(i, messageExt.getQueueOffset());
        Assert.assertEquals(results.get(i).getAppendMessageResult().getMsgId(), messageExt.getMsgId());
        Assert.assertEquals(results.get(i).getAppendMessageResult().getWroteOffset(), messageExt.getCommitLogOffset());
    }
    messageStore.destroy();
    messageStore.shutdown();
}
 
Example 2
Source File: DLedgerCommitlogTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommittedPos() throws Exception {
    String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0);

    String topic = UUID.randomUUID().toString();
    MessageExtBrokerInner msgInner =  buildMessage();
    msgInner.setTopic(topic);
    msgInner.setQueueId(0);
    PutMessageResult putMessageResult = leaderStore.putMessage(msgInner);
    Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus());

    Thread.sleep(1000);

    Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset());
    Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0));


    DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0);
    Thread.sleep(2000);

    Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);


    leaderStore.destroy();
    followerStore.destroy();

    leaderStore.shutdown();
    followerStore.shutdown();
}
 
Example 3
Source File: DLedgerCommitlogTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testIPv6HostMsgCommittedPos() throws Exception {
    String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort());
    String group = UUID.randomUUID().toString();
    DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0);

    String topic = UUID.randomUUID().toString();
    MessageExtBrokerInner msgInner =  buildIPv6HostMessage();
    msgInner.setTopic(topic);
    msgInner.setQueueId(0);
    PutMessageResult putMessageResult = leaderStore.putMessage(msgInner);
    Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus());

    Thread.sleep(1000);

    Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset());
    Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0));


    DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0);
    Thread.sleep(2000);

    Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0));
    Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0);


    leaderStore.destroy();
    followerStore.destroy();

    leaderStore.shutdown();
    followerStore.shutdown();
}