summaryrefslogtreecommitdiff
path: root/src/test/java/testing/protocols/BerkeleyProtocolTest.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-21 15:54:07 +0300
committerPaul Buetow <paul@buetow.org>2025-06-21 15:54:07 +0300
commitd3b697218773eaa5a3dd368705184726dbc0fa38 (patch)
treee466fb78829c957f70e88ab92651896b49120856 /src/test/java/testing/protocols/BerkeleyProtocolTest.java
parentdedec9b18bafa2bcfdb05429f717f95f2236d811 (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/BerkeleyProtocolTest.java')
-rw-r--r--src/test/java/testing/protocols/BerkeleyProtocolTest.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/java/testing/protocols/BerkeleyProtocolTest.java b/src/test/java/testing/protocols/BerkeleyProtocolTest.java
new file mode 100644
index 0000000..9dc144d
--- /dev/null
+++ b/src/test/java/testing/protocols/BerkeleyProtocolTest.java
@@ -0,0 +1,78 @@
+package testing.protocols;
+
+import testing.*;
+import org.junit.jupiter.api.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * JUnit test for Berkeley time synchronization protocol.
+ */
+@DisplayName("Berkeley Time Synchronization Protocol Tests")
+public class BerkeleyProtocolTest {
+ private HeadlessSimulationRunner runner;
+
+ @BeforeEach
+ public void setup() {
+ runner = new HeadlessSimulationRunner();
+ }
+
+ @AfterEach
+ public void teardown() {
+ runner.shutdown();
+ }
+
+ @Test
+ @DisplayName("Test Berkeley protocol activation")
+ public void testProtocolActivation() throws Exception {
+ SimulationResult result = runner.runSimulation(
+ "saved-simulations/berkeley.dat",
+ 1000
+ );
+
+ ProtocolVerifier verifier = new ProtocolVerifier()
+ .expectLog("Berkley.*activated|Berkeley.*activated")
+ .expectNoLog("ERROR");
+
+ VerificationResult verification = verifier.verify(result.getAllLogs());
+
+ assertTrue(verification.passed(), verification.getFailureMessage());
+ assertTrue(result.getMetrics().getTotalLogCount() > 0,
+ "Should have some log activity");
+ }
+
+ @Test
+ @DisplayName("Test time synchronization messages")
+ public void testTimeSynchronization() throws Exception {
+ SimulationResult result = runner.runSimulation(
+ "saved-simulations/berkeley.dat",
+ 5000
+ );
+
+ // Berkeley protocol involves time requests and adjustments
+ ProtocolVerifier verifier = new ProtocolVerifier()
+ .expectLog("time|Time|TIME")
+ .expectLog("sync|Sync|SYNC")
+ .expectLog("Message sent")
+ .expectLog("Message received");
+
+ VerificationResult verification = verifier.verify(result.getAllLogs());
+ assertTrue(verification.passed(), verification.getFailureMessage());
+ }
+
+ @Test
+ @DisplayName("Test master-slave communication")
+ public void testMasterSlaveCommunication() throws Exception {
+ SimulationResult result = runner.runSimulation(
+ "saved-simulations/berkeley.dat",
+ 3000
+ );
+
+ // Berkeley has master and slave nodes
+ boolean hasMasterActivity = result.countLogs("master|Master|MASTER") > 0;
+ boolean hasSlaveActivity = result.countLogs("slave|Slave|SLAVE") > 0;
+ boolean hasTimeExchange = result.countLogs("time|Time") > 0;
+
+ assertTrue(hasMasterActivity || hasSlaveActivity || hasTimeExchange,
+ "Should have master/slave or time-related activity");
+ }
+} \ No newline at end of file