diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-21 15:54:07 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-21 15:54:07 +0300 |
| commit | d3b697218773eaa5a3dd368705184726dbc0fa38 (patch) | |
| tree | e466fb78829c957f70e88ab92651896b49120856 /src/test/java/testing/protocols/BroadcastProtocolTest.java | |
| parent | dedec9b18bafa2bcfdb05429f717f95f2236d811 (diff) | |
Implement headless testing framework for DS-Sim protocol simulations
- Created HeadlessSimulationRunner that loads and runs simulations without GUI
- Implemented LogCapture to intercept and store all simulation logs
- Added ProtocolVerifier for flexible pattern-based log verification
- Created test runners: standard, with logs, and clean (filters GUI errors)
- Implemented tests for all non-Raft protocols
- Added DummySimulatorFrame to satisfy GUI dependencies during loading
- Created CleanHeadlessRunner that filters GUI-related errors from output
- Updated run-tests.sh script with quiet mode option
- Documented the framework architecture and usage
The framework successfully runs protocol tests and verifies behavior through
log analysis. GUI errors occur internally due to tight coupling in DS-Sim
but are filtered in quiet mode for clean output.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/testing/protocols/BroadcastProtocolTest.java')
| -rw-r--r-- | src/test/java/testing/protocols/BroadcastProtocolTest.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/test/java/testing/protocols/BroadcastProtocolTest.java b/src/test/java/testing/protocols/BroadcastProtocolTest.java new file mode 100644 index 0000000..d0ed6f3 --- /dev/null +++ b/src/test/java/testing/protocols/BroadcastProtocolTest.java @@ -0,0 +1,93 @@ +package testing.protocols; + +import testing.*; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * JUnit test for Broadcast protocol. + */ +@DisplayName("Broadcast Protocol Tests") +public class BroadcastProtocolTest { + private HeadlessSimulationRunner runner; + + @BeforeEach + public void setup() { + runner = new HeadlessSimulationRunner(); + } + + @AfterEach + public void teardown() { + runner.shutdown(); + } + + @Test + @DisplayName("Test Broadcast protocol activation") + public void testProtocolActivation() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/broadcast.dat", + 1000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("Broadcast.*activated") + .expectNoLog("ERROR") + .expectNoLog("Exception"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + + assertTrue(verification.passed(), verification.getFailureMessage()); + } + + @Test + @DisplayName("Test broadcast message delivery to all nodes") + public void testBroadcastDelivery() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/broadcast.dat", + 3000 + ); + + // In broadcast, one message should be received by multiple nodes + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("Message sent") + .expectLog("Message received") + .expectLog("Broadcast|broadcast|BROADCAST"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + + // Verify broadcast property: more receives than sends + int sent = result.countLogs("Message sent"); + int received = result.countLogs("Message received"); + + if (sent > 0 && result.getMetrics().getNumProcesses() > 2) { + assertTrue(received > sent, + "Broadcast should deliver to multiple receivers"); + } + } + + @Test + @DisplayName("Test all processes receive broadcast") + public void testAllProcessesReceive() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/broadcast.dat", + 4000 + ); + + // Count how many different processes received messages + var processLogs = result.getProcessLogs(); + int processesWithReceivedMessages = 0; + + for (var entry : processLogs.entrySet()) { + boolean hasReceived = entry.getValue().stream() + .anyMatch(log -> log.getMessage().contains("received")); + if (hasReceived) { + processesWithReceivedMessages++; + } + } + + // In broadcast, multiple processes should receive messages + assertTrue(processesWithReceivedMessages >= 1, + "At least one process should receive messages"); + } +}
\ No newline at end of file |
