class Raft::Transport::InMemory

Overview

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.

Defined in:

raft/transport/in_memory.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Raft::Transport

send(peer_id : String, message : RPC::Message) : Nil send, start(inbox : Channel(RPC::Envelope)) : Nil start, stop : Nil stop

Constructor Detail

def self.new(node_id : String) #

[View source]

Class Method Detail

def self.heal(a : String, b : String) : Nil #

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


[View source]
def self.partition(a : String, b : String) : Nil #

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


[View source]
def self.reset : Nil #

Clears all registrations and partitions. Call in before_each blocks.


[View source]

Instance Method Detail

def send(peer_id : String, message : RPC::Message) : Nil #
Description copied from class Raft::Transport

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.


[View source]
def start(inbox : Channel(RPC::Envelope)) : Nil #
Description copied from class Raft::Transport

Starts listening for incoming messages.

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


[View source]
def stop : Nil #
Description copied from class Raft::Transport

Shuts down the transport, closing all connections and listeners.


[View source]