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/implementations/VSRaftProtocol.java | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/main/java/protocols') diff --git a/src/main/java/protocols/implementations/VSRaftProtocol.java b/src/main/java/protocols/implementations/VSRaftProtocol.java index 2029b72..0d8fa20 100644 --- a/src/main/java/protocols/implementations/VSRaftProtocol.java +++ b/src/main/java/protocols/implementations/VSRaftProtocol.java @@ -73,6 +73,10 @@ public class VSRaftProtocol extends VSAbstractProtocol { private Integer currentLeader; private long lastHeartbeat; + // Client state + private boolean clientHasScheduled = false; + private int clientRequestCount = 0; + /** * Log entry structure */ @@ -185,19 +189,22 @@ public class VSRaftProtocol extends VSAbstractProtocol { @Override public void onClientInit() { - // Clients don't need special initialization for Raft - setBoolean("raft.client.enabled", true); + // Initialize client state + clientHasScheduled = false; + clientRequestCount = 0; } @Override public void onClientStart() { - // Schedule periodic client requests for testing - scheduleAt(process.getTime() + 500); + // This method is never called when using HAS_ON_SERVER_START + // Clients will send requests in response to server heartbeats instead } @Override public void onClientReset() { removeSchedules(); + clientHasScheduled = false; + clientRequestCount = 0; } @Override @@ -208,6 +215,13 @@ public class VSRaftProtocol extends VSAbstractProtocol { boolean success = message.getBoolean("success"); String result = message.getString("result"); raftLog("Client received response: success=" + success + ", result=" + result); + } else if (MSG_APPEND_ENTRIES.equals(msgType)) { + // Client receives heartbeat from leader - good time to send a request + if (!clientHasScheduled) { + clientHasScheduled = true; + // Schedule first client request after a short delay + scheduleAt(process.getTime() + 100); + } } } @@ -221,10 +235,15 @@ public class VSRaftProtocol extends VSAbstractProtocol { request.setLong("requestId", System.currentTimeMillis()); sendMessage(request); - raftLog("Client sent request: " + request.getString("command")); + raftLog("Client sent request #" + clientRequestCount + ": " + request.getString("command")); - // Schedule next request - scheduleAt(process.getTime() + 1000 + process.getRandomPercentage() * 10); + // Update request count + clientRequestCount++; + + // Schedule next request after a delay + if (clientRequestCount < 10) { // Limit number of requests for testing + scheduleAt(process.getTime() + 1000 + process.getRandomPercentage() * 10); + } } // --- Raft Algorithm Implementation --- -- cgit v1.2.3