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 --- .../java/testing/protocols/CommitProtocolTest.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/java/testing/protocols/CommitProtocolTest.java (limited to 'src/test/java/testing/protocols/CommitProtocolTest.java') diff --git a/src/test/java/testing/protocols/CommitProtocolTest.java b/src/test/java/testing/protocols/CommitProtocolTest.java new file mode 100644 index 0000000..abe9a5d --- /dev/null +++ b/src/test/java/testing/protocols/CommitProtocolTest.java @@ -0,0 +1,83 @@ +package testing.protocols; + +import testing.*; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * JUnit tests for commit protocols (one-phase and two-phase). + */ +@DisplayName("Commit Protocol Tests") +public class CommitProtocolTest { + private HeadlessSimulationRunner runner; + + @BeforeEach + public void setup() { + runner = new HeadlessSimulationRunner(); + } + + @AfterEach + public void teardown() { + runner.shutdown(); + } + + @Test + @DisplayName("Test One-Phase Commit protocol") + public void testOnePhaseCommit() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/one-phase-commit.dat", + 3000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("1-Phase Commit.*activated|One.*Phase.*activated") + .expectLog("commit|Commit|COMMIT") + .expectLog("Message") + .expectNoLog("ERROR") + .expectNoLog("abort|ABORT"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + } + + @Test + @DisplayName("Test Two-Phase Commit protocol") + public void testTwoPhaseCommit() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/two-phase-commit.dat", + 4000 + ); + + ProtocolVerifier verifier = new ProtocolVerifier() + .expectLog("2-Phase Commit.*activated|Two.*Phase.*activated") + .expectLog("Message") + .expectNoLog("ERROR"); + + VerificationResult verification = verifier.verify(result.getAllLogs()); + assertTrue(verification.passed(), verification.getFailureMessage()); + + // Two-phase commit should have prepare/vote and commit phases + boolean hasPrepare = result.countLogs("prepare|Prepare|PREPARE|vote|Vote") > 0; + boolean hasCommit = result.countLogs("commit|Commit|COMMIT") > 0; + + assertTrue(hasPrepare || hasCommit, + "Should have prepare/vote or commit messages"); + } + + @Test + @DisplayName("Test commit protocol coordinator behavior") + public void testCoordinatorBehavior() throws Exception { + SimulationResult result = runner.runSimulation( + "saved-simulations/two-phase-commit.dat", + 5000 + ); + + // Look for coordinator-specific messages + boolean hasCoordinator = result.countLogs("coordinator|Coordinator|COORDINATOR") > 0; + boolean hasParticipant = result.countLogs("participant|Participant|PARTICIPANT") > 0; + boolean hasTransaction = result.countLogs("transaction|Transaction") > 0; + + assertTrue(hasCoordinator || hasParticipant || hasTransaction, + "Should have coordinator/participant activity"); + } +} \ No newline at end of file -- cgit v1.2.3