memory
ModuleAn in-process adapter: connections and packets are driven by calls, and what the broker sends and closes is recorded.
Contents
use utopia_mqtt::Memory;Rust
pub struct MemoryAn adapter without a network, for tests: the caller opens connections, delivers packets and disconnects clients, and reads back what the broker sent and which connections it closed. Hooks run on the caller's thread.
open,receiveanddisconnectcall the open, receive and close hooks, and return what they return.sendrecords aSentpacket.closerecords the connection and, when it is open, closes it and calls the close hook, as Swoole does.startcalls the start hook and the worker start hook (worker 0) and returns at once.failmakes an operation fail with anError::Runtime.- The timer's tick closes the connection, as on the network.
Clones share the same adapter.
Rust
use utopia_mqtt::Memory;
use utopia_mqtt::adapter::{Adapter, Outbound};
let adapter = Memory::new();
adapter.open(1)?;
adapter.send(1, b"\xD0\x00")?;
adapter.close(1)?;
assert_eq!(adapter.sent()[0].data, b"\xD0\x00");
assert_eq!(adapter.closed(), [1]);Also implements
Default.use utopia_mqtt::memory::Sent;Rust
pub struct SentA packet the broker sent to one connection.
use utopia_mqtt::memory::Operation;Rust
pub enum OperationAn adapter operation Memory::fail can make fail.