A message source (Alternera.Plugin.Provisional.Source) over a queue
held in memory, for tests of the code that consumes a source, with no
broker around.
A queue is an Agent the test starts and names (start_queue/1); the
source's one setting, "queue", names it. The agent is registered
globally, so a receive from any process (a runner's task) finds it, and
it is linked to the test process, so it goes when the test does.
{:ok, _pid} = MemorySource.start_queue("orders")
MemorySource.push("orders", ~s({"id": 1}))
# ... a consumer opens the source with %{"queue" => "orders"}
MemorySource.settled("orders") #=> [{"m-1", :ack}]It behaves as a queue with a timed lock does: a received message is
hidden for the hold the receive asked for, its receive_count goes up
each time it is delivered, and each delivery has a handle of its own, so a
settle with the handle of an earlier delivery fails stale. :ack
removes a message, {:retry, ms} makes it visible again after ms,
:reject moves it to the queue's rejected list. With the setting
"extend_hold" true it can lengthen a hold (extend/2). calls/1 lists
the settles and extends it was asked for, with how many messages each
took. The queue's clock is the
node's monotonic clock plus what advance/2 added, so a test can let a
hold lapse without waiting for it. fail_next/4 makes the next call of a
callback fail.
Summary
Functions
Moves the queue's clock on by ms.
The settles and extends asked of the queue, oldest first, as
{:settle | :extend, how many messages}.
Takes the message id out of the queue as a broker's redrive policy
moves one to its dead-letter queue: it is never delivered again.
Makes the next call of callback (:open, :receive, :settle or
:extend) on the queue answer {:error, type, message}.
The ids of the messages still in the queue, hidden or not.
Puts a message with body and attributes at the back of the queue; answers its id.
The ids of the messages rejected, oldest first.
The verdicts settled on the queue, oldest first, as {message_id, verdict}.
Starts the queue named name, linked to the calling process.
When the message id becomes visible again, on the queue's clock
(monotonic ms plus what advance/2 added), or nil when it is not in the
queue.
Functions
@spec advance(String.t(), non_neg_integer()) :: :ok
Moves the queue's clock on by ms.
@spec calls(String.t()) :: [{:settle | :extend, pos_integer()}]
The settles and extends asked of the queue, oldest first, as
{:settle | :extend, how many messages}.
Takes the message id out of the queue as a broker's redrive policy
moves one to its dead-letter queue: it is never delivered again.
Makes the next call of callback (:open, :receive, :settle or
:extend) on the queue answer {:error, type, message}.
The ids of the messages still in the queue, hidden or not.
Puts a message with body and attributes at the back of the queue; answers its id.
The ids of the messages rejected, oldest first.
The verdicts settled on the queue, oldest first, as {message_id, verdict}.
Starts the queue named name, linked to the calling process.
When the message id becomes visible again, on the queue's clock
(monotonic ms plus what advance/2 added), or nil when it is not in the
queue.