diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-22 16:45:17 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-22 16:45:17 +0300 |
| commit | 4c16cc3c4da7bbf8375d7951185db1761eb396bf (patch) | |
| tree | 19199b664ce802ed3e967e318e6d4ffeb8c9bf39 /src/main | |
| parent | 464df52901e2dcb84eb81a22f2db19cbf17e5a9f (diff) | |
Remove all Raft protocol code
Removed all Raft-related code as it was not working properly:
- Removed VSRaftProtocol.java implementation
- Removed all Raft test files
- Removed Raft example/demo files
- Removed Raft documentation
- Removed Raft simulation files (.dat)
- Removed Raft scripts
- Updated VSRegisteredEvents to remove Raft registration
- Updated SimulationBuilder to remove RAFT constant
- Updated SimulationFactory to remove Raft methods
- Updated SimulationBuilderTest to remove Raft tests
- Updated pom.xml to remove Raft test configurations
The protocol had issues with leader election not completing in GUI mode.
š¤ Generated with Claude Code
https://claude.ai/code
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/events/VSRegisteredEvents.java | 1 | ||||
| -rw-r--r-- | src/main/java/examples/CreateAndVerifyRaftSimulation.java | 142 | ||||
| -rw-r--r-- | src/main/java/examples/CreateMinimalRaftSimulation.java | 86 | ||||
| -rw-r--r-- | src/main/java/examples/CreateSimpleRaftSimulation.java | 123 | ||||
| -rw-r--r-- | src/main/java/examples/CreateWorkingRaftSimulation.java | 152 | ||||
| -rw-r--r-- | src/main/java/examples/RaftSimulationBuilder.java | 76 | ||||
| -rw-r--r-- | src/main/java/examples/TestRaftLoading.java | 57 | ||||
| -rw-r--r-- | src/main/java/protocols/implementations/VSRaftProtocol.java | 603 | ||||
| -rw-r--r-- | src/main/java/simulator/builder/SimulationBuilder.java | 1 | ||||
| -rw-r--r-- | src/main/java/simulator/builder/SimulationFactory.java | 32 |
10 files changed, 0 insertions, 1273 deletions
diff --git a/src/main/java/events/VSRegisteredEvents.java b/src/main/java/events/VSRegisteredEvents.java index 91000bc..92deeb0 100644 --- a/src/main/java/events/VSRegisteredEvents.java +++ b/src/main/java/events/VSRegisteredEvents.java @@ -99,7 +99,6 @@ public final class VSRegisteredEvents { registerEvent("protocols.implementations.VSReliableMulticastProtocol"); registerEvent("protocols.implementations.VSTwoPhaseCommitProtocol"); registerEvent("protocols.implementations.VSTimestampDemoProtocol"); - registerEvent("protocols.implementations.VSRaftProtocol"); /* Make dummy objects of each protocol, to see if they contain VSPrefs values to edit */ diff --git a/src/main/java/examples/CreateAndVerifyRaftSimulation.java b/src/main/java/examples/CreateAndVerifyRaftSimulation.java deleted file mode 100644 index 126c37c..0000000 --- a/src/main/java/examples/CreateAndVerifyRaftSimulation.java +++ /dev/null @@ -1,142 +0,0 @@ -package examples; - -import simulator.*; -import core.*; -import prefs.*; -import events.*; -import events.internal.*; -import events.implementations.*; -import serialize.VSSerialize; -import java.io.*; - -/** - * Creates a Raft simulation and verifies it can be loaded properly. - */ -public class CreateAndVerifyRaftSimulation { - - private static final String RAFT_PROTOCOL = "protocols.implementations.VSRaftProtocol"; - - public static void main(String[] args) throws Exception { - System.out.println("=== Creating and Verifying Raft Simulation ===\n"); - - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // Step 1: Create the simulation - System.out.println("Step 1: Creating Raft simulation..."); - - VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); - VSSimulator simulator = new VSSimulator(prefs, frame); - frame.addSimulator(simulator); - - // Access visualization - java.lang.reflect.Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); - - // Add processes (5 total: 3 servers + 2 clients) - while (viz.getNumProcesses() < 5) { - java.lang.reflect.Method addProcessMethod = VSSimulatorVisualization.class.getDeclaredMethod("addProcess"); - addProcessMethod.setAccessible(true); - addProcessMethod.invoke(viz); - } - - VSTaskManager taskManager = viz.getTaskManager(); - - // Add Raft server activations - System.out.println(" - Adding 3 Raft servers"); - for (int i = 0; i < 3; i++) { - VSProtocolEvent serverEvent = new VSProtocolEvent(); - serverEvent.setProtocolClassname(RAFT_PROTOCOL); - serverEvent.isClientProtocol(false); - serverEvent.isProtocolActivation(true); - - VSTask task = new VSTask(0, viz.getProcess(i), serverEvent, false); - taskManager.addTask(task); - } - - // Add Raft client activations - System.out.println(" - Adding 2 Raft clients"); - for (int i = 3; i < 5; i++) { - VSProtocolEvent clientEvent = new VSProtocolEvent(); - clientEvent.setProtocolClassname(RAFT_PROTOCOL); - clientEvent.isClientProtocol(true); - clientEvent.isProtocolActivation(true); - - // Stagger client starts - VSTask task = new VSTask(200 + (i-3)*100, viz.getProcess(i), clientEvent, false); - taskManager.addTask(task); - } - - // Add some events - System.out.println(" - Adding crash/recovery events"); - - // Server 0 crashes at 1000, recovers at 1500 - VSProcessCrashEvent crash = new VSProcessCrashEvent(); - taskManager.addTask(new VSTask(1000, viz.getProcess(0), crash, false)); - - VSProcessRecoverEvent recover = new VSProcessRecoverEvent(); - taskManager.addTask(new VSTask(1500, viz.getProcess(0), recover, false)); - - // Save simulation - File outputFile = new File("saved-simulations/raft-verified.dat"); - outputFile.getParentFile().mkdirs(); - - VSSerialize serialize = new VSSerialize(); - serialize.saveSimulator(outputFile.getAbsolutePath(), simulator); - - frame.dispose(); - - System.out.println(" ā Simulation saved to: " + outputFile.getName()); - - // Step 2: Verify the simulation can be loaded - System.out.println("\nStep 2: Loading and verifying simulation..."); - - VSSimulatorFrame frame2 = new VSSimulatorFrame(prefs, null); - VSSimulator loadedSim = serialize.openSimulator(outputFile.getAbsolutePath(), frame2); - - if (loadedSim == null) { - System.err.println(" ā Failed to load simulation!"); - System.exit(1); - } - - // Verify contents - vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization loadedViz = (VSSimulatorVisualization) vizField.get(loadedSim); - - System.out.println(" ā Simulation loaded successfully"); - System.out.println(" - Processes: " + loadedViz.getNumProcesses()); - - // Check tasks - VSTaskManager loadedTaskManager = loadedViz.getTaskManager(); - java.lang.reflect.Field tasksField = VSTaskManager.class.getDeclaredField("tasks"); - tasksField.setAccessible(true); - Object taskQueue = tasksField.get(loadedTaskManager); - java.lang.reflect.Method sizeMethod = taskQueue.getClass().getMethod("size"); - int taskCount = (Integer) sizeMethod.invoke(taskQueue); - - System.out.println(" - Scheduled tasks: " + taskCount); - - frame2.dispose(); - - // Step 3: Provide instructions - System.out.println("\n=== Success! ==="); - System.out.println("\nTo run the Raft simulation:"); - System.out.println("1. Start the simulator:"); - System.out.println(" java -jar target/ds-sim-1.0.1-SNAPSHOT.jar"); - System.out.println("\n2. Load the simulation:"); - System.out.println(" File ā Open ā saved-simulations/raft-verified.dat"); - System.out.println("\n3. Run the simulation:"); - System.out.println(" Click the 'Run' button (ā¶)"); - System.out.println("\n4. What to look for:"); - System.out.println(" - Leader election messages (REQUEST_VOTE, VOTE_RESPONSE)"); - System.out.println(" - Heartbeats from leader (APPEND_ENTRIES)"); - System.out.println(" - Client requests and responses"); - System.out.println(" - Re-election when server 0 crashes at time 1000"); - - System.exit(0); - } -}
\ No newline at end of file diff --git a/src/main/java/examples/CreateMinimalRaftSimulation.java b/src/main/java/examples/CreateMinimalRaftSimulation.java deleted file mode 100644 index 62db468..0000000 --- a/src/main/java/examples/CreateMinimalRaftSimulation.java +++ /dev/null @@ -1,86 +0,0 @@ -package examples; - -import simulator.*; -import core.*; -import prefs.*; -import events.*; -import events.internal.*; -import serialize.VSSerialize; -import java.io.*; -import java.lang.reflect.*; - -/** - * Creates a minimal Raft simulation with just protocol activations. - * This tests if the basic simulation saving/loading works. - */ -public class CreateMinimalRaftSimulation { - - public static void main(String[] args) throws Exception { - System.out.println("=== Creating Minimal Raft Simulation ===\n"); - - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // Create simulator without GUI - VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); - VSSimulator simulator = new VSSimulator(prefs, frame); - frame.addSimulator(simulator); - - // Access visualization via reflection - Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); - - // Add 3 processes - Method addProcessMethod = VSSimulatorVisualization.class.getDeclaredMethod("addProcess"); - addProcessMethod.setAccessible(true); - for (int i = 0; i < 3; i++) { - addProcessMethod.invoke(viz); - } - - VSTaskManager taskManager = viz.getTaskManager(); - - // Create only one Raft server activation at time 0 - System.out.println("Adding single Raft server activation on process 0..."); - VSProtocolEvent serverEvent = new VSProtocolEvent(); - serverEvent.setProtocolClassname("protocols.implementations.VSRaftProtocol"); - serverEvent.isClientProtocol(false); - serverEvent.isProtocolActivation(true); - - VSTask task = new VSTask(0, viz.getProcess(0), serverEvent, false); - taskManager.addTask(task); - - // Save simulation - File outputFile = new File("saved-simulations/raft-minimal.dat"); - outputFile.getParentFile().mkdirs(); - - VSSerialize serialize = new VSSerialize(); - serialize.saveSimulator(outputFile.getAbsolutePath(), simulator); - - frame.dispose(); - - System.out.println("\nSimulation saved to: " + outputFile.getAbsolutePath()); - System.out.println("\nTo test:"); - System.out.println("1. Run: java -jar target/ds-sim-1.0.1-SNAPSHOT.jar"); - System.out.println("2. File ā Open ā saved-simulations/raft-minimal.dat"); - System.out.println("3. Click Run button and check the logs"); - - // Try to immediately load it back to verify - System.out.println("\nVerifying saved file can be loaded..."); - try { - VSSimulatorFrame frame2 = new VSSimulatorFrame(prefs, null); - VSSimulator loaded = serialize.openSimulator(outputFile.getAbsolutePath(), frame2); - if (loaded != null) { - System.out.println("ā File loaded successfully!"); - frame2.dispose(); - } else { - System.out.println("ā Failed to load file!"); - } - } catch (Exception e) { - System.out.println("ā Error loading file: " + e.getMessage()); - e.printStackTrace(); - } - } -}
\ No newline at end of file diff --git a/src/main/java/examples/CreateSimpleRaftSimulation.java b/src/main/java/examples/CreateSimpleRaftSimulation.java deleted file mode 100644 index ebff53e..0000000 --- a/src/main/java/examples/CreateSimpleRaftSimulation.java +++ /dev/null @@ -1,123 +0,0 @@ -package examples; - -import simulator.*; -import core.*; -import prefs.*; -import events.*; -import events.internal.*; -import events.implementations.*; -import serialize.VSSerialize; -import java.io.*; - -/** - * Creates a simple working Raft simulation. - * The key insight: Raft protocol uses HAS_ON_SERVER_START, so when servers - * are activated via VSProtocolEvent, the protocol's onServerStart() method - * will be called automatically. - */ -public class CreateSimpleRaftSimulation { - - private static final String RAFT_PROTOCOL = "protocols.implementations.VSRaftProtocol"; - - public static void main(String[] args) throws Exception { - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // Create frame and simulator - VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); - VSSimulator simulator = new VSSimulator(prefs, frame); - frame.addSimulator(simulator); - - // Access visualization via reflection - java.lang.reflect.Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); - - // Add more processes - we want 5 total (3 servers, 2 clients) - while (viz.getNumProcesses() < 5) { - java.lang.reflect.Method addProcessMethod = VSSimulatorVisualization.class.getDeclaredMethod("addProcess"); - addProcessMethod.setAccessible(true); - addProcessMethod.invoke(viz); - } - - VSTaskManager taskManager = viz.getTaskManager(); - - // Activate Raft SERVERS on processes 0, 1, 2 - // Since Raft uses HAS_ON_SERVER_START, onServerStart() will be called automatically! - System.out.println("Creating Raft server activations..."); - for (int i = 0; i < 3; i++) { - VSProtocolEvent serverEvent = new VSProtocolEvent(); - serverEvent.setProtocolClassname(RAFT_PROTOCOL); - serverEvent.isClientProtocol(false); // Server mode - serverEvent.isProtocolActivation(true); // Activation - - // Activate at time 0 - VSTask task = new VSTask(0, viz.getProcess(i), serverEvent, false); - taskManager.addTask(task); - System.out.println(" - Server " + i + " will activate at time 0"); - } - - // Activate Raft CLIENTS on processes 3, 4 - // Clients will react to server heartbeats and start sending requests - System.out.println("\nCreating Raft client activations..."); - for (int i = 3; i < 5; i++) { - VSProtocolEvent clientEvent = new VSProtocolEvent(); - clientEvent.setProtocolClassname(RAFT_PROTOCOL); - clientEvent.isClientProtocol(true); // Client mode - clientEvent.isProtocolActivation(true); // Activation - - // Activate clients a bit later so servers have time to elect leader - VSTask task = new VSTask(300 + (i-3)*100, viz.getProcess(i), clientEvent, false); - taskManager.addTask(task); - System.out.println(" - Client " + (i-3) + " will activate at time " + (300 + (i-3)*100)); - } - - // Add crash/recovery to demonstrate leader re-election - System.out.println("\nAdding failure scenarios..."); - - // Crash server 0 at time 1000 - VSProcessCrashEvent crash = new VSProcessCrashEvent(); - VSTask crashTask = new VSTask(1000, viz.getProcess(0), crash, false); - taskManager.addTask(crashTask); - System.out.println(" - Server 0 will crash at time 1000"); - - // Recover server 0 at time 1500 - VSProcessRecoverEvent recover = new VSProcessRecoverEvent(); - VSTask recoverTask = new VSTask(1500, viz.getProcess(0), recover, false); - taskManager.addTask(recoverTask); - System.out.println(" - Server 0 will recover at time 1500"); - - // Save simulation - File outputFile = new File("saved-simulations/raft-simple.dat"); - outputFile.getParentFile().mkdirs(); - - VSSerialize serialize = new VSSerialize(); - serialize.saveSimulator(outputFile.getAbsolutePath(), simulator); - - frame.dispose(); - - System.out.println("\n==========================================="); - System.out.println("Simple Raft simulation saved successfully!"); - System.out.println("==========================================="); - System.out.println("\nFile: " + outputFile.getAbsolutePath()); - System.out.println("\nWhat happens in this simulation:"); - System.out.println("1. Time 0: Three Raft servers start and begin leader election"); - System.out.println("2. Time ~150-300: One server becomes leader (watch for election messages)"); - System.out.println("3. Time 300: First client activates and starts sending requests"); - System.out.println("4. Time 400: Second client activates and starts sending requests"); - System.out.println("5. Time 1000: Server 0 crashes, triggering new leader election"); - System.out.println("6. Time 1500: Server 0 recovers and rejoins as follower"); - System.out.println("\nTo run the simulation:"); - System.out.println("1. java -jar target/ds-sim-1.0.1-SNAPSHOT.jar"); - System.out.println("2. File -> Open -> saved-simulations/raft-simple.dat"); - System.out.println("3. Click 'Run' and watch the Raft consensus in action!"); - System.out.println("\nLook for:"); - System.out.println("- REQUEST_VOTE and VOTE_RESPONSE messages during elections"); - System.out.println("- APPEND_ENTRIES messages (heartbeats) from leader"); - System.out.println("- CLIENT_REQUEST messages and their processing"); - - System.exit(0); - } -}
\ No newline at end of file diff --git a/src/main/java/examples/CreateWorkingRaftSimulation.java b/src/main/java/examples/CreateWorkingRaftSimulation.java deleted file mode 100644 index 0bc5df4..0000000 --- a/src/main/java/examples/CreateWorkingRaftSimulation.java +++ /dev/null @@ -1,152 +0,0 @@ -package examples; - -import simulator.*; -import core.*; -import prefs.*; -import events.*; -import events.internal.*; -import events.implementations.*; -import serialize.VSSerialize; -import java.io.*; -import java.lang.reflect.*; - -/** - * Creates a working Raft simulation by properly setting up the event queue - * and ensuring protocols are activated through the normal event system. - */ -public class CreateWorkingRaftSimulation { - - private static final String RAFT_PROTOCOL = "protocols.implementations.VSRaftProtocol"; - - public static void main(String[] args) throws Exception { - System.out.println("=== Creating Working Raft Simulation ===\n"); - - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // Create simulator with frame - VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); - VSSimulator simulator = new VSSimulator(prefs, frame); - frame.addSimulator(simulator); - - // Access visualization - Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); - - // Add 5 processes (3 servers + 2 clients) - Method addProcessMethod = VSSimulatorVisualization.class.getDeclaredMethod("addProcess"); - addProcessMethod.setAccessible(true); - System.out.println("Adding 5 processes..."); - for (int i = 0; i < 5; i++) { - addProcessMethod.invoke(viz); - } - - VSTaskManager taskManager = viz.getTaskManager(); - - // Schedule Raft server activations at time 0 - System.out.println("\nScheduling Raft server activations:"); - for (int i = 0; i < 3; i++) { - VSProtocolEvent serverEvent = new VSProtocolEvent(); - serverEvent.setProtocolClassname(RAFT_PROTOCOL); - serverEvent.isClientProtocol(false); // Server mode - serverEvent.isProtocolActivation(true); // This is an activation - - VSTask task = new VSTask(0, viz.getProcess(i), serverEvent, false); - taskManager.addTask(task); - System.out.println(" - Server " + i + " activation scheduled at time 0"); - } - - // Schedule Raft client activations with slight delay - System.out.println("\nScheduling Raft client activations:"); - for (int i = 3; i < 5; i++) { - VSProtocolEvent clientEvent = new VSProtocolEvent(); - clientEvent.setProtocolClassname(RAFT_PROTOCOL); - clientEvent.isClientProtocol(true); // Client mode - clientEvent.isProtocolActivation(true); // This is an activation - - // Start clients after servers have initialized - long startTime = 500 + (i - 3) * 200; - VSTask task = new VSTask(startTime, viz.getProcess(i), clientEvent, false); - taskManager.addTask(task); - System.out.println(" - Client " + (i-3) + " activation scheduled at time " + startTime); - } - - // Add some interesting events - System.out.println("\nAdding crash/recovery events:"); - - // Process 0 crashes at time 2000 and recovers at 3000 - VSProcessCrashEvent crash1 = new VSProcessCrashEvent(); - taskManager.addTask(new VSTask(2000, viz.getProcess(0), crash1, false)); - System.out.println(" - Server 0 crash scheduled at time 2000"); - - VSProcessRecoverEvent recover1 = new VSProcessRecoverEvent(); - taskManager.addTask(new VSTask(3000, viz.getProcess(0), recover1, false)); - System.out.println(" - Server 0 recovery scheduled at time 3000"); - - // Process 1 crashes at time 4000 and recovers at 5000 - VSProcessCrashEvent crash2 = new VSProcessCrashEvent(); - taskManager.addTask(new VSTask(4000, viz.getProcess(1), crash2, false)); - System.out.println(" - Server 1 crash scheduled at time 4000"); - - VSProcessRecoverEvent recover2 = new VSProcessRecoverEvent(); - taskManager.addTask(new VSTask(5000, viz.getProcess(1), recover2, false)); - System.out.println(" - Server 1 recovery scheduled at time 5000"); - - // Save simulation - File outputFile = new File("saved-simulations/raft-working.dat"); - outputFile.getParentFile().mkdirs(); - - System.out.println("\nSaving simulation..."); - VSSerialize serialize = new VSSerialize(); - serialize.saveSimulator(outputFile.getAbsolutePath(), simulator); - - frame.dispose(); - - System.out.println("\nā Simulation saved to: " + outputFile.getAbsolutePath()); - - // Create instruction file - File instructionFile = new File("saved-simulations/README-raft.txt"); - try (PrintWriter writer = new PrintWriter(instructionFile)) { - writer.println("RAFT CONSENSUS SIMULATION"); - writer.println("========================"); - writer.println(); - writer.println("This directory contains Raft consensus protocol simulations:"); - writer.println(); - writer.println("1. raft-working.dat - Full working simulation with:"); - writer.println(" - 3 Raft servers (processes 0-2)"); - writer.println(" - 2 Raft clients (processes 3-4)"); - writer.println(" - Server crash/recovery events"); - writer.println(); - writer.println("To run the simulation:"); - writer.println("1. java -jar target/ds-sim-1.0.1-SNAPSHOT.jar"); - writer.println("2. File ā Open ā saved-simulations/raft-working.dat"); - writer.println("3. Click Run (ā¶) button"); - writer.println(); - writer.println("What to look for:"); - writer.println("- Leader election (REQUEST_VOTE messages)"); - writer.println("- Heartbeats from leader (APPEND_ENTRIES)"); - writer.println("- Client requests and responses"); - writer.println("- Re-election when servers crash"); - writer.println(); - writer.println("Timeline:"); - writer.println("- Time 0: Servers start, begin leader election"); - writer.println("- Time 500-700: Clients start"); - writer.println("- Time 2000: Server 0 crashes"); - writer.println("- Time 3000: Server 0 recovers"); - writer.println("- Time 4000: Server 1 crashes"); - writer.println("- Time 5000: Server 1 recovers"); - } - - System.out.println("ā Instructions saved to: " + instructionFile.getAbsolutePath()); - - System.out.println("\n=== Success! ==="); - System.out.println("\nThe Raft simulation has been created with the following setup:"); - System.out.println("- 3 servers implementing Raft consensus"); - System.out.println("- 2 clients that will send requests"); - System.out.println("- Crash/recovery events to test fault tolerance"); - System.out.println("\nRun the simulator and load the file to see it in action!"); - } -}
\ No newline at end of file diff --git a/src/main/java/examples/RaftSimulationBuilder.java b/src/main/java/examples/RaftSimulationBuilder.java deleted file mode 100644 index c802448..0000000 --- a/src/main/java/examples/RaftSimulationBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -package examples; - -import simulator.*; -import core.*; -import prefs.*; -import events.*; -import events.internal.*; -import serialize.VSSerialize; -import java.io.*; - -/** - * Builder for creating Raft simulations programmatically. - * Uses reflection to access private simulator fields when necessary. - */ -public class RaftSimulationBuilder { - - private static final String RAFT_PROTOCOL = "protocols.implementations.VSRaftProtocol"; - - public static void main(String[] args) throws Exception { - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // Create frame and simulator - VSSimulatorFrame frame = new VSSimulatorFrame(prefs, null); - VSSimulator simulator = new VSSimulator(prefs, frame); - frame.addSimulator(simulator); - - // Access private field via reflection - java.lang.reflect.Field vizField = VSSimulator.class.getDeclaredField("simulatorVisualization"); - vizField.setAccessible(true); - VSSimulatorVisualization viz = (VSSimulatorVisualization) vizField.get(simulator); - - // Build Raft simulation - VSTaskManager taskManager = viz.getTaskManager(); - - // Add server activations (processes 0,1) - for (int i = 0; i < 2; i++) { - VSProtocolEvent serverEvent = new VSProtocolEvent(); - serverEvent.setProtocolClassname(RAFT_PROTOCOL); - serverEvent.isClientProtocol(false); - serverEvent.isProtocolActivation(true); - - VSTask task = new VSTask(0, viz.getProcess(i), serverEvent, false); - taskManager.addTask(task); - } - - // Add client activation (process 2) - VSProtocolEvent clientEvent = new VSProtocolEvent(); - clientEvent.setProtocolClassname(RAFT_PROTOCOL); - clientEvent.isClientProtocol(true); - clientEvent.isProtocolActivation(true); - - VSTask clientTask = new VSTask(100, viz.getProcess(2), clientEvent, false); - taskManager.addTask(clientTask); - - // Save - File outputFile = new File("saved-simulations/raft-consensus.dat"); - outputFile.getParentFile().mkdirs(); - - VSSerialize serialize = new VSSerialize(); - serialize.saveSimulator(outputFile.getAbsolutePath(), simulator); - - frame.dispose(); - - System.out.println("Raft simulation created: " + outputFile.getAbsolutePath()); - System.out.println("\nContains:"); - System.out.println("- 2 Raft servers (processes 0-1)"); - System.out.println("- 1 Raft client (process 2)"); - System.out.println("\nRun with: java -jar target/ds-sim-1.0.1-SNAPSHOT.jar"); - System.out.println("Then open: " + outputFile.getName()); - - System.exit(0); - } -}
\ No newline at end of file diff --git a/src/main/java/examples/TestRaftLoading.java b/src/main/java/examples/TestRaftLoading.java deleted file mode 100644 index ebad379..0000000 --- a/src/main/java/examples/TestRaftLoading.java +++ /dev/null @@ -1,57 +0,0 @@ -package examples; - -import events.VSRegisteredEvents; -import prefs.VSDefaultPrefs; -import java.util.Vector; - -/** - * Test if Raft protocol is properly registered and loadable - */ -public class TestRaftLoading { - public static void main(String[] args) { - // Initialize - VSDefaultPrefs prefs = new VSDefaultPrefs(); - prefs.fillWithDefaults(); - VSRegisteredEvents.init(prefs); - - // List all registered protocols - System.out.println("=== Registered Protocols ==="); - Vector<String> protocolNames = VSRegisteredEvents.getProtocolNames(); - for (String name : protocolNames) { - String className = VSRegisteredEvents.getClassnameByEventname(name); - System.out.println(name + " -> " + className); - } - - System.out.println("\n=== Protocol Classnames ==="); - Vector<String> protocolClassnames = VSRegisteredEvents.getProtocolClassnames(); - for (String className : protocolClassnames) { - String shortName = VSRegisteredEvents.getShortnameByClassname(className); - System.out.println(className + " (short: " + shortName + ")"); - } - - // Check Raft specifically - System.out.println("\n=== Raft Protocol Check ==="); - String raftClass = "protocols.implementations.VSRaftProtocol"; - String raftShortName = VSRegisteredEvents.getShortnameByClassname(raftClass); - String raftEventName = VSRegisteredEvents.getNameByClassname(raftClass); - - System.out.println("Class: " + raftClass); - System.out.println("Short name: " + raftShortName); - System.out.println("Event name: " + raftEventName); - - // Try to load the class - try { - Class<?> clazz = Class.forName(raftClass); - System.out.println("Class loaded successfully: " + clazz.getName()); - - // Check if it's a protocol - if (protocols.VSAbstractProtocol.class.isAssignableFrom(clazz)) { - System.out.println("ā Is a valid protocol class"); - } else { - System.out.println("ā NOT a protocol class!"); - } - } catch (ClassNotFoundException e) { - System.out.println("ā Class not found: " + e.getMessage()); - } - } -}
\ No newline at end of file diff --git a/src/main/java/protocols/implementations/VSRaftProtocol.java b/src/main/java/protocols/implementations/VSRaftProtocol.java deleted file mode 100644 index af12064..0000000 --- a/src/main/java/protocols/implementations/VSRaftProtocol.java +++ /dev/null @@ -1,603 +0,0 @@ -package protocols.implementations; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import core.VSMessage; -import core.VSInternalProcess; -import protocols.VSAbstractProtocol; - -/** - * Implementation of the Raft consensus algorithm. - * - * Raft is a consensus algorithm designed to be understandable. It ensures that - * a distributed system agrees on values even in the presence of failures. - * - * <p>The protocol has three states:</p> - * <ul> - * <li>Follower - Passive state, responds to leaders</li> - * <li>Candidate - Actively requesting votes to become leader</li> - * <li>Leader - Manages the cluster and log replication</li> - * </ul> - * - * <p>Key features implemented:</p> - * <ul> - * <li>Leader election with randomized timeouts</li> - * <li>Log replication for state machine commands</li> - * <li>Safety through term numbers and log matching</li> - * <li>Membership changes (simplified)</li> - * </ul> - * - * @author Paul C. Buetow - */ -public class VSRaftProtocol extends VSAbstractProtocol { - - // Raft states - private enum State { - FOLLOWER, - CANDIDATE, - LEADER - } - - // Message types - private static final String MSG_REQUEST_VOTE = "REQUEST_VOTE"; - private static final String MSG_VOTE_RESPONSE = "VOTE_RESPONSE"; - private static final String MSG_APPEND_ENTRIES = "APPEND_ENTRIES"; - private static final String MSG_APPEND_RESPONSE = "APPEND_RESPONSE"; - private static final String MSG_CLIENT_REQUEST = "CLIENT_REQUEST"; - - // Timing constants (in simulation time units) - private static final long HEARTBEAT_INTERVAL = 50; - private static final long ELECTION_TIMEOUT_MIN = 150; - private static final long ELECTION_TIMEOUT_MAX = 300; - - // Server state (persistent - should be saved to stable storage) - private State currentState; - private int currentTerm; - private Integer votedFor; - private List<LogEntry> log; - - // Server state (volatile) - private int commitIndex; - private int lastApplied; - - // Leader state (reinitialized after election) - private Map<Integer, Integer> nextIndex; - private Map<Integer, Integer> matchIndex; - - // Candidate state - private Set<Integer> votesReceived; - private long electionTimeout; - - // General state - private Integer currentLeader; - private long lastHeartbeat; - - // Client state - private boolean clientHasScheduled = false; - private int clientRequestCount = 0; - - /** - * Log entry structure - */ - private static class LogEntry { - final int term; - final String command; - final long timestamp; - - LogEntry(int term, String command, long timestamp) { - this.term = term; - this.command = command; - this.timestamp = timestamp; - } - - @Override - public String toString() { - return String.format("LogEntry{term=%d, cmd='%s', time=%d}", - term, command, timestamp); - } - } - - public VSRaftProtocol() { - super(VSAbstractProtocol.HAS_ON_SERVER_START); - setClassname(getClass().toString()); - } - - @Override - public void onServerInit() { - currentState = State.FOLLOWER; - currentTerm = 0; - votedFor = null; - log = new ArrayList<>(); - commitIndex = 0; - lastApplied = 0; - nextIndex = new ConcurrentHashMap<>(); - matchIndex = new ConcurrentHashMap<>(); - votesReceived = new HashSet<>(); - currentLeader = null; - - // Add a dummy entry at index 0 for easier indexing - log.add(new LogEntry(0, "INIT", 0)); - } - - @Override - public void onServerStart() { - // Initialize election timeout and start - resetElectionTimeout(); - raftLog("Raft node initialized as FOLLOWER, election timeout=" + electionTimeout); - scheduleElectionTimeout(); - raftLog("Scheduled election timeout check"); - } - - @Override - public void onServerReset() { - onServerInit(); - removeSchedules(); - } - - @Override - public void onServerRecv(VSMessage message) { - String msgType = message.getString("type"); - int term = message.getInteger("term"); - int senderId = message.getSendingProcess().getProcessNum(); - - // Check if this message is intended for us (for unicast messages) - if (message.objectExists("receiverNum")) { - int receiverNum = message.getInteger("receiverNum"); - if (receiverNum != process.getProcessNum()) { - // Message not for us, ignore it - return; - } - } - - // If we receive a message with a higher term, become follower - if (term > currentTerm) { - currentTerm = term; - votedFor = null; - if (currentState != State.FOLLOWER) { - becomeFollower(); - } - } - - switch (msgType) { - case MSG_REQUEST_VOTE: - handleRequestVote(message, senderId); - break; - case MSG_VOTE_RESPONSE: - handleVoteResponse(message, senderId); - break; - case MSG_APPEND_ENTRIES: - handleAppendEntries(message, senderId); - break; - case MSG_APPEND_RESPONSE: - handleAppendResponse(message, senderId); - break; - case MSG_CLIENT_REQUEST: - handleClientRequest(message, senderId); - break; - } - } - - @Override - public void onServerSchedule() { - long currentTime = process.getTime(); - - raftLog("onServerSchedule called at time " + currentTime + ", state=" + currentState + ", electionTimeout=" + electionTimeout); - - switch (currentState) { - case FOLLOWER: - case CANDIDATE: - // Check election timeout - if (currentTime >= electionTimeout) { - startElection(); - } else { - // Reschedule to check again - scheduleAt(electionTimeout); - } - break; - case LEADER: - // Send heartbeats - sendHeartbeats(); - scheduleAt(currentTime + HEARTBEAT_INTERVAL); - break; - } - } - - @Override - public void onClientInit() { - // Initialize client state - clientHasScheduled = false; - clientRequestCount = 0; - } - - @Override - public void onClientStart() { - // 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 - public void onClientRecv(VSMessage message) { - // Clients can receive responses to their requests - String msgType = message.getString("type"); - if ("CLIENT_RESPONSE".equals(msgType)) { - 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); - } - } - } - - @Override - public void onClientSchedule() { - // Send a test client request - VSMessage request = new VSMessage(); - request.setString("type", MSG_CLIENT_REQUEST); - request.setString("command", "SET x=" + process.getRandomPercentage()); - request.setLong("clientId", process.getProcessNum()); - request.setLong("requestId", System.currentTimeMillis()); - - sendMessage(request); - raftLog("Client sent request #" + clientRequestCount + ": " + request.getString("command")); - - // 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 --- - - private void startElection() { - currentState = State.CANDIDATE; - currentTerm++; - votedFor = process.getProcessNum(); - votesReceived.clear(); - votesReceived.add(process.getProcessNum()); // Vote for self - - raftLog("Starting election for term " + currentTerm + " (need " + ((getNumProcesses() / 2) + 1) + " votes)"); - - // Send RequestVote to all other servers - VSMessage voteRequest = new VSMessage(); - voteRequest.setString("type", MSG_REQUEST_VOTE); - voteRequest.setInteger("term", currentTerm); - voteRequest.setInteger("candidateId", process.getProcessNum()); - voteRequest.setInteger("lastLogIndex", log.size() - 1); - voteRequest.setInteger("lastLogTerm", log.get(log.size() - 1).term); - - raftLog("Sending vote request to all processes"); - sendMessage(voteRequest); - - // Reset election timeout - resetElectionTimeout(); - scheduleElectionTimeout(); - } - - private void handleRequestVote(VSMessage message, int candidateId) { - int term = message.getInteger("term"); - int lastLogIndex = message.getInteger("lastLogIndex"); - int lastLogTerm = message.getInteger("lastLogTerm"); - - raftLog("Received vote request from " + candidateId + " for term " + term); - - boolean voteGranted = false; - - // Grant vote if: - // 1. We haven't voted in this term or voted for this candidate - // 2. Candidate's log is at least as up-to-date as ours - if (term >= currentTerm && - (votedFor == null || votedFor == candidateId) && - isLogUpToDate(lastLogIndex, lastLogTerm)) { - - votedFor = candidateId; - voteGranted = true; - resetElectionTimeout(); - - raftLog("Voted for candidate " + candidateId + " in term " + term); - } else { - raftLog("Did not vote for candidate " + candidateId + " (already voted for " + votedFor + ")"); - } - - // Send vote response - VSMessage response = new VSMessage(); - response.setString("type", MSG_VOTE_RESPONSE); - response.setInteger("term", currentTerm); - response.setBoolean("voteGranted", voteGranted); - response.setInteger("senderId", process.getProcessNum()); - - // Send directly to candidate - response.setInteger("receiverNum", candidateId); - raftLog("Sending vote response to " + candidateId + " (granted=" + voteGranted + ")"); - sendMessage(response); - } - - private void handleVoteResponse(VSMessage message, int senderId) { - if (currentState != State.CANDIDATE) { - return; - } - - boolean voteGranted = message.getBoolean("voteGranted"); - if (voteGranted) { - votesReceived.add(senderId); - - raftLog("Received vote from " + senderId + " (total: " + votesReceived.size() + ")"); - - // Check if we have majority - int majority = (getNumProcesses() / 2) + 1; - if (votesReceived.size() >= majority) { - becomeLeader(); - } - } - } - - private void becomeLeader() { - currentState = State.LEADER; - currentLeader = process.getProcessNum(); - - raftLog("Became LEADER for term " + currentTerm); - - // Initialize leader state - nextIndex.clear(); - matchIndex.clear(); - - for (int i = 0; i < getNumProcesses(); i++) { - if (i != process.getProcessNum()) { - nextIndex.put(i, log.size()); - matchIndex.put(i, 0); - } - } - - // Send initial heartbeats immediately - sendHeartbeats(); - - // Schedule regular heartbeats - removeSchedules(); - scheduleAt(process.getTime() + HEARTBEAT_INTERVAL); - - // Highlight the leader visually - if (process instanceof VSInternalProcess) { - ((VSInternalProcess) process).highlightOn(); - } - } - - private void becomeFollower() { - currentState = State.FOLLOWER; - - raftLog("Became FOLLOWER for term " + currentTerm); - - // Remove leader highlighting - if (process instanceof VSInternalProcess) { - ((VSInternalProcess) process).highlightOff(); - } - - // Reset election timeout - resetElectionTimeout(); - scheduleElectionTimeout(); - } - - private void sendHeartbeats() { - for (int i = 0; i < getNumProcesses(); i++) { - if (i != process.getProcessNum()) { - sendAppendEntries(i); - } - } - } - - private void sendAppendEntries(int followerId) { - int nextIdx = nextIndex.getOrDefault(followerId, 1); - int prevLogIndex = nextIdx - 1; - int prevLogTerm = prevLogIndex >= 0 && prevLogIndex < log.size() ? log.get(prevLogIndex).term : 0; - - VSMessage appendEntries = new VSMessage(); - appendEntries.setString("type", MSG_APPEND_ENTRIES); - appendEntries.setInteger("term", currentTerm); - appendEntries.setInteger("leaderId", process.getProcessNum()); - appendEntries.setInteger("prevLogIndex", prevLogIndex); - appendEntries.setInteger("prevLogTerm", prevLogTerm); - appendEntries.setInteger("leaderCommit", commitIndex); - - // Include log entries if needed - List<LogEntry> entries = new ArrayList<>(); - for (int i = nextIdx; i < log.size(); i++) { - entries.add(log.get(i)); - } - - // For simplicity, we'll send entry count and details separately - appendEntries.setInteger("entryCount", entries.size()); - for (int i = 0; i < entries.size(); i++) { - LogEntry entry = entries.get(i); - appendEntries.setInteger("entry_" + i + "_term", entry.term); - appendEntries.setString("entry_" + i + "_cmd", entry.command); - appendEntries.setLong("entry_" + i + "_time", entry.timestamp); - } - - appendEntries.setInteger("receiverNum", followerId); - sendMessage(appendEntries); - } - - private void handleAppendEntries(VSMessage message, int leaderId) { - int term = message.getInteger("term"); - int prevLogIndex = message.getInteger("prevLogIndex"); - int prevLogTerm = message.getInteger("prevLogTerm"); - int leaderCommit = message.getInteger("leaderCommit"); - - // Reset election timeout when we hear from leader - resetElectionTimeout(); - lastHeartbeat = process.getTime(); - currentLeader = leaderId; - - boolean success = false; - - // Check if log matches at prevLogIndex - if (prevLogIndex == 0 || - (prevLogIndex < log.size() && log.get(prevLogIndex).term == prevLogTerm)) { - - success = true; - - // Remove conflicting entries - if (prevLogIndex + 1 < log.size()) { - log.subList(prevLogIndex + 1, log.size()).clear(); - } - - // Append new entries - int entryCount = message.getInteger("entryCount"); - for (int i = 0; i < entryCount; i++) { - int entryTerm = message.getInteger("entry_" + i + "_term"); - String entryCmd = message.getString("entry_" + i + "_cmd"); - long entryTime = message.getLong("entry_" + i + "_time"); - - log.add(new LogEntry(entryTerm, entryCmd, entryTime)); - raftLog("Appended log entry: " + entryCmd); - } - - // Update commit index - if (leaderCommit > commitIndex) { - commitIndex = Math.min(leaderCommit, log.size() - 1); - applyStateMachine(); - } - } - - // Send response - VSMessage response = new VSMessage(); - response.setString("type", MSG_APPEND_RESPONSE); - response.setInteger("term", currentTerm); - response.setBoolean("success", success); - response.setInteger("senderId", process.getProcessNum()); - response.setInteger("matchIndex", log.size() - 1); - response.setInteger("receiverNum", leaderId); - - sendMessage(response); - } - - private void handleAppendResponse(VSMessage message, int followerId) { - if (currentState != State.LEADER) { - return; - } - - boolean success = message.getBoolean("success"); - int matchIdx = message.getInteger("matchIndex"); - - if (success) { - matchIndex.put(followerId, matchIdx); - nextIndex.put(followerId, matchIdx + 1); - - // Check if we can advance commit index - updateCommitIndex(); - } else { - // Decrement nextIndex and retry - int next = nextIndex.getOrDefault(followerId, 1); - if (next > 1) { - nextIndex.put(followerId, next - 1); - } - } - } - - private void handleClientRequest(VSMessage message, int clientId) { - if (currentState != State.LEADER) { - // Redirect to leader or reject - VSMessage response = new VSMessage(); - response.setString("type", "CLIENT_RESPONSE"); - response.setBoolean("success", false); - response.setString("result", "Not leader. Leader is: " + currentLeader); - response.setInteger("receiverNum", clientId); - sendMessage(response); - return; - } - - // Append to log - String command = message.getString("command"); - LogEntry entry = new LogEntry(currentTerm, command, process.getTime()); - log.add(entry); - - raftLog("Leader received client request: " + command); - - // Will be committed when replicated to majority - // For now, send optimistic response - VSMessage response = new VSMessage(); - response.setString("type", "CLIENT_RESPONSE"); - response.setBoolean("success", true); - response.setString("result", "Command logged: " + command); - response.setInteger("receiverNum", clientId); - sendMessage(response); - } - - // --- Helper Methods --- - - private boolean isLogUpToDate(int lastLogIndex, int lastLogTerm) { - int ourLastIndex = log.size() - 1; - int ourLastTerm = log.get(ourLastIndex).term; - - return lastLogTerm > ourLastTerm || - (lastLogTerm == ourLastTerm && lastLogIndex >= ourLastIndex); - } - - private void resetElectionTimeout() { - if (process != null) { - long timeout = ELECTION_TIMEOUT_MIN + - (long)(Math.random() * (ELECTION_TIMEOUT_MAX - ELECTION_TIMEOUT_MIN)); - electionTimeout = process.getTime() + timeout; - } - } - - private void scheduleElectionTimeout() { - removeSchedules(); - scheduleAt(electionTimeout); - } - - private void updateCommitIndex() { - // Find the highest index that has been replicated to majority - for (int n = log.size() - 1; n > commitIndex; n--) { - if (log.get(n).term == currentTerm) { - int replicatedCount = 1; // Leader has it - - for (int matchIdx : matchIndex.values()) { - if (matchIdx >= n) { - replicatedCount++; - } - } - - if (replicatedCount > getNumProcesses() / 2) { - commitIndex = n; - applyStateMachine(); - break; - } - } - } - } - - private void applyStateMachine() { - while (lastApplied < commitIndex) { - lastApplied++; - LogEntry entry = log.get(lastApplied); - raftLog("Applied to state machine: " + entry.command); - } - } - - private void raftLog(String message) { - String stateStr = currentState != null ? currentState.toString() : "CLIENT"; - String prefix = String.format("[%s T:%d N:%d] ", - stateStr, currentTerm, process.getProcessNum()); - process.log(prefix + message); - } - - @Override - public String toString() { - return super.toString() + " - Raft Consensus"; - } -}
\ No newline at end of file diff --git a/src/main/java/simulator/builder/SimulationBuilder.java b/src/main/java/simulator/builder/SimulationBuilder.java index 8ac5d04..c35f0ea 100644 --- a/src/main/java/simulator/builder/SimulationBuilder.java +++ b/src/main/java/simulator/builder/SimulationBuilder.java @@ -351,7 +351,6 @@ public class SimulationBuilder { * Fluent API for common protocol setups */ public static class Protocols { - public static final String RAFT = "protocols.implementations.VSRaftProtocol"; public static final String PING_PONG = "protocols.implementations.VSPingPongProtocol"; public static final String BERKLEY_TIME = "protocols.implementations.VSBerkelyTimeProtocol"; public static final String BROADCAST = "protocols.implementations.VSBroadcastProtocol"; diff --git a/src/main/java/simulator/builder/SimulationFactory.java b/src/main/java/simulator/builder/SimulationFactory.java index c06be00..2bd73b9 100644 --- a/src/main/java/simulator/builder/SimulationFactory.java +++ b/src/main/java/simulator/builder/SimulationFactory.java @@ -8,38 +8,6 @@ import java.util.stream.IntStream; */ public class SimulationFactory { - /** - * Create a standard Raft consensus simulation - * @param numServers Number of Raft servers (minimum 3 for consensus) - * @param numClients Number of client processes - * @return Configured SimulationBuilder - */ - public static SimulationBuilder createRaftSimulation(int numServers, int numClients) throws Exception { - if (numServers < 3) { - throw new IllegalArgumentException("Raft requires at least 3 servers for consensus"); - } - - return new SimulationBuilder() - .withProcesses(numServers + numClients) - .withProtocol(SimulationBuilder.Protocols.RAFT) - .withDuration(15000) // 15 seconds to see leader election - .activateServers(IntStream.range(0, numServers).toArray()) - .activateClients(500, IntStream.range(numServers, numServers + numClients).toArray()); - } - - /** - * Create a Raft simulation with fault tolerance testing - * @param numServers Number of Raft servers - * @return Configured SimulationBuilder with crash/recovery events - */ - public static SimulationBuilder createRaftFaultToleranceSimulation(int numServers) throws Exception { - return createRaftSimulation(numServers, 0) - .withDuration(30000) // 30 seconds for fault testing - .addCrashEvent(0, 5000) // Crash leader after 5s - .addRecoveryEvent(0, 10000) // Recover after 10s - .addCrashEvent(1, 15000) // Crash another server - .addRecoveryEvent(1, 20000); // Recover after 20s - } /** * Create a simple ping-pong simulation |
