Class ConsensusSimulation
java.lang.Object
org.j7m.middleware.consensus.ConsensusSimulation
- All Implemented Interfaces:
AutoCloseable
Deterministic local consensus simulation harness.
-
Constructor Summary
ConstructorsConstructorDescriptionConsensusSimulation(ConsensusConfig config, long seed) Creates a simulation. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()org.j7m.middleware.api.consensus.ConsensusConfigurationReturns fixed configuration.voidcrash(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Crashes a node.Returns current leader.org.j7m.middleware.api.consensus.ConsensusNodeIdReturns current leader id.voidDelivers all pending messages.voidDrops next sent message.voidDuplicates next sent message.org.j7m.middleware.api.consensus.ConsensusStateelect(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Starts an election.voidheal()Heals network partition.voidRecords stale leader rejection as observed by a scenario.node(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Returns a node.nodes()Returns all nodes.voidpartition(Set<org.j7m.middleware.api.consensus.ConsensusNodeId> majority, Set<org.j7m.middleware.api.consensus.ConsensusNodeId> minority) Partitions the network.voidQueues current leader replication messages without delivering them.voidReorders pending messages.voidrestart(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Restarts a node from durable state.org.j7m.middleware.api.consensus.ConsensusSafetyReportRuns safety checks.org.j7m.middleware.api.consensus.ConsensusSimulationReportReturns deterministic simulation report.org.j7m.middleware.api.consensus.ConsensusStatusstatus()Returns status.org.j7m.middleware.api.consensus.ConsensusCommandResultsubmit(org.j7m.middleware.api.consensus.ConsensusCommand command) Submits a command to the current leader.org.j7m.middleware.api.consensus.ConsensusCommandResultsubmitTo(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId, org.j7m.middleware.api.consensus.ConsensusCommand command) Submits a command to a specific node.static ConsensusSimulationCreates a three-node simulation.
-
Constructor Details
-
ConsensusSimulation
Creates a simulation.- Parameters:
config- configurationseed- deterministic seed
-
-
Method Details
-
threeNode
Creates a three-node simulation.- Parameters:
root- storage rootseed- deterministic seed- Returns:
- simulation
-
elect
public org.j7m.middleware.api.consensus.ConsensusState elect(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Starts an election.- Parameters:
nodeId- candidate- Returns:
- candidate state after delivery
-
submit
public org.j7m.middleware.api.consensus.ConsensusCommandResult submit(org.j7m.middleware.api.consensus.ConsensusCommand command) Submits a command to the current leader.- Parameters:
command- command- Returns:
- result
-
submitTo
public org.j7m.middleware.api.consensus.ConsensusCommandResult submitTo(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId, org.j7m.middleware.api.consensus.ConsensusCommand command) Submits a command to a specific node.- Parameters:
nodeId- node idcommand- command- Returns:
- result
-
dropNextMessage
public void dropNextMessage()Drops next sent message. -
duplicateNextMessage
public void duplicateNextMessage()Duplicates next sent message. -
reorderPendingMessages
public void reorderPendingMessages()Reorders pending messages. -
queueLeaderReplication
public void queueLeaderReplication()Queues current leader replication messages without delivering them. -
partition
-
heal
public void heal()Heals network partition. -
crash
public void crash(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Crashes a node.- Parameters:
nodeId- node id
-
restart
public void restart(org.j7m.middleware.api.consensus.ConsensusNodeId nodeId) Restarts a node from durable state.- Parameters:
nodeId- node id
-
deliverAll
public void deliverAll()Delivers all pending messages. -
currentLeader
-
currentLeaderId
public org.j7m.middleware.api.consensus.ConsensusNodeId currentLeaderId()Returns current leader id.- Returns:
- leader id or null
-
node
Returns a node.- Parameters:
nodeId- node id- Returns:
- node
-
nodes
-
status
public org.j7m.middleware.api.consensus.ConsensusStatus status()Returns status.- Returns:
- status
-
safetyReport
public org.j7m.middleware.api.consensus.ConsensusSafetyReport safetyReport()Runs safety checks.- Returns:
- safety report
-
simulationReport
public org.j7m.middleware.api.consensus.ConsensusSimulationReport simulationReport()Returns deterministic simulation report.- Returns:
- simulation report
-
markStaleLeaderRejectionObserved
public void markStaleLeaderRejectionObserved()Records stale leader rejection as observed by a scenario. -
configuration
public org.j7m.middleware.api.consensus.ConsensusConfiguration configuration()Returns fixed configuration.- Returns:
- configuration
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-