Rust

memory

Module

An 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 Memory

An 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, receive and disconnect call the open, receive and close hooks, and return what they return.
  • send records a Sent packet.
  • close records the connection and, when it is open, closes it and calls the close hook, as Swoole does.
  • start calls the start hook and the worker start hook (worker 0) and returns at once.
  • fail makes an operation fail with an Error::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 Sent

A packet the broker sent to one connection.

use utopia_mqtt::memory::Operation;
Rust
pub enum Operation

An adapter operation Memory::fail can make fail.