Skip to content

Commit

Permalink
test: MatchPosFinder test
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Nov 21, 2024
1 parent 9d2b1b5 commit 65c08ee
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.github.dtprj.dongting.raft.test.MockExecutors;
import com.github.dtprj.dongting.raft.test.TestUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -293,7 +292,7 @@ public FrameCallResult execute(Void input) {
}

private FrameCallResult afterNext(List<LogItem> logItems) {
Assertions.fail();
fail();
return Fiber.frameReturn();
}

Expand All @@ -313,7 +312,7 @@ public FrameCallResult execute(Void input) {
}

private FrameCallResult afterNext(List<LogItem> logItems) {
Assertions.fail();
fail();
return Fiber.frameReturn();
}

Expand Down Expand Up @@ -431,8 +430,8 @@ void testTryFindMatchPos() throws Exception {
append(list);
raftStatus.setLastLogIndex(list.get(list.size() - 1).getIndex());

TailCache tailCache = raftStatus.getTailCache();
for (int i = 0; i <= list.size(); i++) {
TailCache tailCache = raftStatus.getTailCache();
tailCache.cleanAll();
for (int j = list.size() - i; j < list.size(); j++) {
RaftInput ri = new RaftInput(0, null, null, null, false);
Expand All @@ -443,6 +442,31 @@ void testTryFindMatchPos() throws Exception {
}
testMatch();
}

tailCache.cleanAll();
doInFiber(new FiberFrame<>() {
@Override
public FrameCallResult execute(Void input) {
FiberFrame<Pair<Integer, Long>> f = raftLog.tryFindMatchPos(1, 1, () -> true);
return Fiber.call(f, this::afterFind);
}

private FrameCallResult afterFind(Pair<Integer, Long> r) {
fail();
return Fiber.frameReturn();
}

@Override
protected FrameCallResult handle(Throwable ex) {
assertInstanceOf(RaftCancelException.class, ex);
return Fiber.frameReturn();
}
});

// mark delete
raftLog.logFiles.getLogFile(0).deleteTimestamp = 100;
testMatch(2, 5, 2, 5);
testMatch(1, 4, -1, -1);
}

private void testMatch() throws Exception {
Expand Down

0 comments on commit 65c08ee

Please sign in to comment.