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/simulator | |
| 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/simulator')
| -rw-r--r-- | src/test/java/simulator/SimpleRaftGUITest.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/java/simulator/SimpleRaftGUITest.java b/src/test/java/simulator/SimpleRaftGUITest.java new file mode 100644 index 0000000..3697db2 --- /dev/null +++ b/src/test/java/simulator/SimpleRaftGUITest.java @@ -0,0 +1,66 @@ +package simulator; + +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +import core.*; +import prefs.*; +import events.*; +import serialize.VSSerialize; + +import java.io.File; +import java.lang.reflect.*; + +/** + * Simple GUI test for Raft simulation to verify it loads and runs. + */ +public class SimpleRaftGUITest { + + @Test + @DisplayName("Test loading Raft simulation file") + public void testLoadRaftSimulation() throws Exception { + // Initialize + VSDefaultPrefs prefs = new VSDefaultPrefs(); + prefs.fillWithDefaults(); + VSRegisteredEvents.init(prefs); + + // Check if simulation file exists + File simFile = new File("saved-simulations/raft-working.dat"); + assertTrue(simFile.exists(), "Raft simulation file should exist"); + + // Load simulation + VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); + VSSerialize serialize = new VSSerialize(); + VSSimulator simulator = serialize.openSimulator(simFile.getAbsolutePath(), frame); + + assertNotNull(simulator, "Simulator should be loaded"); + + // Access visualization + Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); + vizField.setAccessible(true); + VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); + + // Verify basic properties + assertTrue(viz.getNumProcesses() >= 5, "Should have at least 5 processes"); + + // Check task manager + VSTaskManager taskManager = viz.getTaskManager(); + assertNotNull(taskManager, "Task manager should exist"); + + // Get task count using reflection + Field tasksField = VSTaskManager.class.getDeclaredField("tasks"); + tasksField.setAccessible(true); + Object taskQueue = tasksField.get(taskManager); + Method sizeMethod = taskQueue.getClass().getMethod("size"); + int taskCount = (Integer) sizeMethod.invoke(taskQueue); + + assertTrue(taskCount > 0, "Should have scheduled tasks"); + + frame.dispose(); + + System.out.println("\n=== Test Results ==="); + System.out.println("✓ Raft simulation loads successfully"); + System.out.println("✓ Processes: " + viz.getNumProcesses()); + System.out.println("✓ Scheduled tasks: " + taskCount); + } +}
\ No newline at end of file |
