Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.UtilAll;

Expand Down Expand Up @@ -75,9 +74,6 @@ public String getBackFilePath() {
* Write entries to file
*/
public void write(final List<T> entries) throws IOException {
if (entries.isEmpty()) {
return;
}
synchronized (this) {
StringBuilder entryContent = new StringBuilder();
for (T entry : entries) {
Expand Down Expand Up @@ -143,11 +139,10 @@ private List<T> read(String filePath) throws IOException {
*/
public List<T> read() throws IOException {
try {
List<T> result = this.read(this.filePath);
if (CollectionUtils.isEmpty(result)) {
result = this.read(this.getBackFilePath());
if (!new File(this.filePath).exists()) {
return this.read(this.getBackFilePath());
}
return result;
return this.read(this.filePath);
} catch (IOException e) {
return this.read(this.getBackFilePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public void testNormalWriteAndRead() throws IOException {
Assert.assertEquals(entryList, listFromFile);
}

@Test
public void testEmptyCheckpointOverridesOldState() throws IOException {
this.checkpoint.write(entryList);
this.checkpoint.write(new ArrayList<>());

Assert.assertTrue(checkpoint.read().isEmpty());
}

@Test
public void testAbNormalWriteAndRead() throws IOException {
this.checkpoint.write(entryList);
Expand Down