Freddy.Adapter.Sandbox (freddy v0.17.2)
Special no-op Freddy adapter designed to be used in automated tests instead of real AMQP connection.
Example
iex> alias Freddy.{Connection, Core.Exchange, Adapter.Sandbox}
iex> {:ok, conn} = Connection.start_link(adapter: :sandbox)
iex> {:ok, channel} = Connection.open_channel(conn)
iex> :ok = Exchange.declare(%Exchange{name: "test"}, channel)
iex> {:ok, pid} = Connection.get_connection(conn)
iex> Sandbox.history(pid)
[
link_connection: [#PID<0.226.0>],
open_channel: [#PID<0.226.0>],
monitor_channel: [#PID<0.228.0>],
declare_exchange: [#PID<0.228.0>, "test", :direct, []]
]
Link to this section Summary
Functions
Sends a message to the process specified by dest
whenever an
event occurs.
Get history of events from connection. Events can be filtered by type,
for example, if one wants to get only history of messages, published
over given connection, he should call history(connection, :publish)
.
Filter by multiple event types is supported.
Sets a response for open_channel/1
function. If set to :ok
, the function
will return a tuple {:ok, channel_pid}
(default behaviour).
Removes a listener previously registered with add_listener/2
.
Link to this section Functions
add_listener(connection, dest)
Sends a message to the process specified by dest
whenever an
event occurs.
The messages will be tuples {event, args}
where event
is an atom
that corresponds to a callback in the Freddy.Adapter
module. args
is
a list of arguments passed to the callback.
dest
may be either a PID or a locally registered name (atom).
Example
iex> alias Freddy.{Connection, Core.Exchange, Adapter.Sandbox}
iex> {:ok, conn} = Connection.start_link(adapter: :sandbox)
iex> {:ok, pid} = Connection.get_connection(conn)
iex> :ok = Sandbox.add_listener(pid, self())
iex> {:ok, channel} = Connection.open_channel(conn)
iex> :ok = Exchange.declare(%Exchange{name: "test"}, channel)
iex> flush()
{:open_channel, [#PID<0.226.0>]}
{:monitor_channel, [#PID<0.228.0>]}
{:declare_exchange, [#PID<0.228.0>, "test", :direct, []]}
history(connection, events \\ :all, flush? \\ false)
Get history of events from connection. Events can be filtered by type,
for example, if one wants to get only history of messages, published
over given connection, he should call history(connection, :publish)
.
Filter by multiple event types is supported.
Passing true
as a third argument will erase entire history after
returning it.
on_open_channel(connection, response)
Sets a response for open_channel/1
function. If set to :ok
, the function
will return a tuple {:ok, channel_pid}
(default behaviour).
remove_listener(connection, dest)
Removes a listener previously registered with add_listener/2
.