From d3b697218773eaa5a3dd368705184726dbc0fa38 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 21 Jun 2025 15:54:07 +0300 Subject: Implement headless testing framework for DS-Sim protocol simulations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../protocols/ReliableMulticastProtocolTest.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/test/java/testing/protocols/ReliableMulticastProtocolTest.java (limited to 'src/test/java/testing/protocols/ReliableMulticastProtocolTest.java') diff --git a/src/test/java/testing/protocols/ReliableMulticastProtocolTest.java b/src/test/java/testing/protocols/ReliableMulticastProtocolTest.java new file mode 100644 index 0000000..ae9b4d7 --- /dev/null +++ b/src/test/java/testing/protocols/ReliableMulticastProtocolTest.java @@ -0,0 +1,86 @@ +package testing.protocols; + +import testing.*; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * JUnit test for Reliable Multicast protocol. + */ +@DisplayName("Reliable Multicast Protocol Tests") +public class ReliableMulticastProtocolTest { + private HeadlessSimulationRunner runner; + + @BeforeEach + public void setup() { + runner = new HeadlessSimulationRunner(); + } + + @AfterEach + public void teardown() { + runner.shutdown(); + } + + @Test + @DisplayName("Test Reliable Multicast protocol activation") + public void testProtocolActivation() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/reliable-multicast.dat", + 1000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("Reliable Multicast.*activated") + .expectNoLog("ERROR"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + } + + @Test + @DisplayName("Test reliable delivery guarantees") + public void testReliableDelivery() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/reliable-multicast.dat", + 5000 + ); + + // Reliable multicast should ensure delivery + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("Message sent") + .expectLog("Message received") + .expectLog("Multicast|multicast") + .expectNoLog("lost|Lost|LOST") + .expectNoLog("failed delivery"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + + // Check for acknowledgments or reliability mechanisms + boolean hasAck = result.countLogs("ack|ACK|acknowledge|Acknowledge") > 0; + boolean hasSeq = result.countLogs("sequence|Sequence|seq|SEQ") > 0; + boolean hasReliable = result.countLogs("reliable|Reliable") > 0; + + assertTrue(hasAck || hasSeq || hasReliable, + "Should have reliability mechanisms"); + } + + @Test + @DisplayName("Test message ordering in reliable multicast") + public void testMessageOrdering() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/reliable-multicast.dat", + 3000 + ); + + // Verify messages maintain order + var messages = result.findAll("Message received"); + + long lastTime = -1; + for (LogEntry entry : messages) { + assertTrue(entry.getTimestamp() >= lastTime, + "Messages should be in order"); + lastTime = entry.getTimestamp(); + } + } +} \ No newline at end of file -- cgit v1.2.3