diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-22 11:58:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-22 11:58:00 +0300 |
| commit | 0b5afe8839241dec66ba832cf42860ec69b87df8 (patch) | |
| tree | e100d2d6204f8c04dc33418ae9f193fa6b1a83c2 /src/test/java/testing/protocols/RaftProtocolTest.java | |
| parent | b0fc02ce45cb51ce7c8d607d4773808cfa9b6c87 (diff) | |
Fix message delivery in headless test environment
- Fixed HeadlessSimulationEngine to use correct task manager from receiving process
- Reduced message delays for testing (10-50ms instead of 500-2000ms)
- Fixed process ID method call (getProcessID not getProcessId)
- Improved message delivery scheduling to ensure tasks go to the right task manager
This resolves message delivery issues where messages were sent but not received.
BasicMulticast test now passes, but 12 protocol tests still failing.
🤖 Generated with Claude Code
https://claude.ai/code
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/testing/protocols/RaftProtocolTest.java')
| -rw-r--r-- | src/test/java/testing/protocols/RaftProtocolTest.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/java/testing/protocols/RaftProtocolTest.java b/src/test/java/testing/protocols/RaftProtocolTest.java new file mode 100644 index 0000000..b92606d --- /dev/null +++ b/src/test/java/testing/protocols/RaftProtocolTest.java @@ -0,0 +1,77 @@ +package testing.protocols; + +import testing.*; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Integration test for Raft consensus protocol. + */ +public class RaftProtocolTest extends BaseProtocolTest { + + @Test + @DisplayName("Test Raft protocol activation and message sending") + public void testRaftActivation() { + SimulationResult result = runSimulation( + "saved-simulations/raft.dat", + 2000 // 2 seconds should be enough for elections + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLogExactly("Raft Consensus Server activated", 3) + .expectLog("FOLLOWER.*initialized") + .expectLog("Starting election") + .expectLog("CANDIDATE") + .expectMessages() // Must have messages + .expectAtLeastNMessages(10); // Should have many election messages + + VerificationResult verification = verifier.verify(result.getAllLogs()); + + assertTrue(verification.passed(), verification.getFailureMessage()); + assertEquals(3, result.getMetrics().getNumProcesses(), + "Should have 3 processes"); + } + + @Test + @DisplayName("Test Raft election messages") + public void testRaftElectionMessages() { + SimulationResult result = runSimulation( + "saved-simulations/raft.dat", + 3000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("REQUEST_VOTE") + .expectLog("Message sent.*REQUEST_VOTE") + .expectAtLeastNMessages(15); // Multiple election rounds + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + + // Verify term progression + assertTrue(result.findFirst("term=1").isPresent(), "Should have term 1"); + assertTrue(result.findFirst("term=2").isPresent(), "Should progress to term 2"); + } + + @Test + @DisplayName("Test Raft with clients") + public void testRaftWithClients() { + // Skip if file doesn't exist + if (!new java.io.File("saved-simulations/raft-with-clients.dat").exists()) { + return; + } + + SimulationResult result = runSimulation( + "saved-simulations/raft-with-clients.dat", + 5000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLogExactly("Raft Consensus Server activated", 3) + .expectLogExactly("Raft Consensus Client activated", 2) + .expectMessages(); // Must have messages + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + } +}
\ No newline at end of file |
