-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2281c76
commit f0ec50a
Showing
8 changed files
with
166 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
distmq-broker/src/test/java/com/github/wenweihu86/distmq/broker/log/TestLogManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.wenweihu86.distmq.broker.log; | ||
|
||
import com.github.wenweihu86.distmq.broker.config.GlobalConf; | ||
import com.github.wenweihu86.distmq.client.api.BrokerMessage; | ||
import com.google.protobuf.ByteString; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Created by wenweihu86 on 2017/6/26. | ||
*/ | ||
public class TestLogManager { | ||
|
||
private BrokerMessage.MessageContent.Builder createMessage(String topic, Integer queue) { | ||
BrokerMessage.MessageContent.Builder message = BrokerMessage.MessageContent.newBuilder() | ||
.setContent(ByteString.copyFrom(UUID.randomUUID().toString().getBytes())) | ||
.setTopic(topic) | ||
.setQueue(queue); | ||
return message; | ||
} | ||
|
||
@Test | ||
public void testClearExpiredLog() { | ||
GlobalConf conf = GlobalConf.getInstance(); | ||
conf.setMaxSegmentSize(128); | ||
conf.setExpiredLogDuration(1); | ||
LogManager logManager = new LogManager(conf.getDataDir()); | ||
String topic = "test-topic"; | ||
Integer queue = 0; | ||
SegmentedLog log = logManager.getOrCreateQueueLog(topic, queue); | ||
for (int i = 0; i < 1000; i++) { | ||
log.append(createMessage(topic, queue)); | ||
} | ||
|
||
try { | ||
Thread.sleep(2000); | ||
} catch (InterruptedException ex) { | ||
ex.printStackTrace(); | ||
} | ||
|
||
System.out.println("before clear log count=" + log.getStartOffsetSegmentMap().size()); | ||
logManager.run(); | ||
System.out.println("after clear log count=" + log.getStartOffsetSegmentMap().size()); | ||
Assert.assertTrue(log.getStartOffsetSegmentMap().size() == 1); | ||
File file = new File(conf.getDataDir()); | ||
try { | ||
FileUtils.deleteDirectory(file); | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} |