diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-26 23:21:21 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-26 23:21:21 +0200 |
| commit | 0881fac983503a5320f5b093c738ebc44cc06a70 (patch) | |
| tree | 126a48b6ac156eb652a3170170113a2ea69d0f9d /src/test/java | |
| parent | e76b434619e1ec034e161e0c644e5fad5ab14c79 (diff) | |
Add Raft election guard negative test (0bac83d3-1322-4940-a9ee-58eb1e0d6245)
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/protocols/implementations/VSRaftProtocolTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/java/protocols/implementations/VSRaftProtocolTest.java b/src/test/java/protocols/implementations/VSRaftProtocolTest.java index 7f4f867..0ae52ba 100644 --- a/src/test/java/protocols/implementations/VSRaftProtocolTest.java +++ b/src/test/java/protocols/implementations/VSRaftProtocolTest.java @@ -167,6 +167,25 @@ class VSRaftProtocolTest { } @Test + void testOnClientScheduleDoesNotStartElectionBeforeTimeout() throws Exception { + protocol.currentContextIsServer(false); + protocol.onClientInit(); + clearInvocations(mockProcess, mockTaskManager); + when(mockProcess.getTime()).thenReturn(2000L); + + protocol.onClientSchedule(); + + verify(mockProcess, never()).sendMessage(any()); + verify(mockTaskManager, never()).removeAllTasks(any()); + verify(mockTaskManager, never()).addTask(any()); + assertFalse(getBooleanField("isCandidate")); + assertFalse(getBooleanField("isLeader")); + assertEquals(0, getIntField("currentTerm")); + assertEquals(0, getIntField("votesReceived")); + assertEquals(-1, getIntField("votedFor")); + } + + @Test void testCandidateTimeoutStartsNewElectionAndReschedules() throws Exception { protocol.currentContextIsServer(false); protocol.onClientInit(); |
