class

Raft::Transport::InMemory

Inherits Raft::Transport < Reference < Object

In-memory transport for testing.

Messages are delivered directly between fibers via a class-level channel registry — no sockets involved. Supports partition simulation via partition / heal class methods.

Call reset between test cases to clear all registrations and partitions.

Constructors

new(node_id : String)

Creates an in-memory transport registered under node_id.

Source

Class methods

heal(a : String, b : String) : Nil

Removes the partition between nodes a and b, restoring connectivity.

Source
partition(a : String, b : String) : Nil

Simulates a network partition between nodes a and b (bidirectional).

Source
reset

Clears all registrations and partitions. Call in before_each blocks.

Source

Instance methods

send(peer_id : String, message : RPC::Message) : Nil

Sends an RPC message to the peer identified by peer_id.

Delivery is best-effort. If the peer is unreachable the message is silently dropped — Raft's protocol-level retries handle the loss.

Source
start(inbox : Channel(RPC::Envelope)) : Nil

Starts listening for incoming messages.

Received messages are wrapped in RPC::Envelope (tagged with sender ID) and pushed into the provided inbox channel.

Source
stop

Shuts down the transport, closing all connections and listeners.

Source