FakeSeam

class FakeSeam(val selfId: PeerId = PeerId("self"), initialPeers: Set<PeerId> = setOf(selfId), initialState: SeamState = SeamState.Woven, policy: DeliveryPolicy = DeliveryPolicy.Reliable) : Seam

A test double for Seam with test-driver helpers for state mutation, frame delivery, and outgoing-frame inspection.

Defaults make FakeSeam() a ready-to-use, single-peer, SeamState.Woven seam in one line:

val seam = FakeSeam()
seam.deliver(PeerId("alice"), byteArrayOf(1, 2, 3))
val frame = seam.incoming.first()

For wired two-peer scenarios, prefer fakeSeamPair which cross-wires broadcast delivery between two seams.

Send semantics (matching the Seam contract):

The inbound buffer is bounded via policy (default DeliveryPolicy.Reliable). Unbounded delivery is structurally unrepresentable — pass a custom policy to change capacity or overflow behaviour.

Constructors

Link copied to clipboard
constructor(selfId: PeerId = PeerId("self"), initialPeers: Set<PeerId> = setOf(selfId), initialState: SeamState = SeamState.Woven, policy: DeliveryPolicy = DeliveryPolicy.Reliable)

Properties

Link copied to clipboard

All payloads passed to broadcast, in call order. Each read returns a fresh defensive snapshot; two reads may observe different snapshots if a broadcast lands between them.

Link copied to clipboard
open val capability: StateFlow<TransportCapability>
Link copied to clipboard

All (peer, payload) pairs passed to sendTo, in call order. Each read returns a fresh defensive snapshot; two reads may observe different snapshots if a sendTo lands between them.

Link copied to clipboard
open override val incoming: Flow<Swatch>
Link copied to clipboard
open val maxPayloadBytes: Int?
Link copied to clipboard
open override val peers: StateFlow<Set<PeerId>>
Link copied to clipboard
open val plies: StateFlow<Map<PlyId, SeamState>>
Link copied to clipboard
open override val selfId: PeerId
Link copied to clipboard
open override val state: StateFlow<SeamState>

Functions

Link copied to clipboard
fun addPeer(peer: PeerId)

Add peer to the live peers set.

Link copied to clipboard
open suspend override fun broadcast(payload: ByteArray)
Link copied to clipboard
open suspend override fun close(reason: CloseReason)
Link copied to clipboard
suspend fun deliver(swatch: Swatch)

Push swatch directly into incoming, applying the configured DeliveryPolicy.

suspend fun deliver(from: PeerId, payload: ByteArray)

Push a frame from from into incoming, stamping sender and a monotonically increasing sequence (receiver-local, starting at 1).

Link copied to clipboard
fun removePeer(peer: PeerId)

Remove peer from the live peers set.

Link copied to clipboard
open suspend override fun sendTo(peer: PeerId, payload: ByteArray)
Link copied to clipboard
fun tear(reason: CloseReason = CloseReason.Normal)

Transition state to SeamState.Torn with reason, completing incoming — matching every real seam (NwSeam.latchTorn, MeshSeam.tearDown, InMemorySeam.close), all of which close the spool on tear so a consumer that relies on incoming completing (or wrongly processes frames after Torn) can't pass against this fake but fail in production. Idempotent.

Link copied to clipboard
fun weave()

Transition state from SeamState.Weaving to SeamState.Woven.