summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Joubert <emile@rabbitmq.com>2012-11-22 17:30:21 +0000
committerEmile Joubert <emile@rabbitmq.com>2012-11-22 17:30:21 +0000
commitacd1ab8fafab77b4a93222cd8f6dce354fe1b7d8 (patch)
treedcba291e9f5f620a2ebd0e55e5e125849d32ea23
parent1c86935bb0d27011e20e68169cc9fd5064f11921 (diff)
downloadrabbitmq-server-acd1ab8fafab77b4a93222cd8f6dce354fe1b7d8.tar.gz
QC test for backing queue fold
-rw-r--r--src/rabbit_backing_queue_qc.erl21
-rw-r--r--src/rabbit_variable_queue.erl6
2 files changed, 22 insertions, 5 deletions
diff --git a/src/rabbit_backing_queue_qc.erl b/src/rabbit_backing_queue_qc.erl
index 3168ca5c..00e17d02 100644
--- a/src/rabbit_backing_queue_qc.erl
+++ b/src/rabbit_backing_queue_qc.erl
@@ -106,7 +106,8 @@ command(S) ->
{1, qc_dropwhile(S)},
{1, qc_is_empty(S)},
{1, qc_timeout(S)},
- {1, qc_purge(S)}]).
+ {1, qc_purge(S)},
+ {1, qc_fold(S)}]).
qc_publish(#state{bqstate = BQ}) ->
{call, ?BQMOD, publish,
@@ -157,6 +158,9 @@ qc_timeout(#state{bqstate = BQ}) ->
qc_purge(#state{bqstate = BQ}) ->
{call, ?BQMOD, purge, [BQ]}.
+qc_fold(#state{bqstate = BQ}) ->
+ {call, ?BQMOD, fold, [fun foldfun/2, foldacc(), BQ]}.
+
%% Preconditions
%% Create long queues by only allowing publishing
@@ -271,7 +275,11 @@ next_state(S, BQ, {call, ?MODULE, timeout, _Args}) ->
next_state(S, Res, {call, ?BQMOD, purge, _Args}) ->
BQ1 = {call, erlang, element, [2, Res]},
- S#state{bqstate = BQ1, len = 0, messages = gb_trees:empty()}.
+ S#state{bqstate = BQ1, len = 0, messages = gb_trees:empty()};
+
+next_state(S, Res, {call, ?BQMOD, fold, _Args}) ->
+ BQ1 = {call, erlang, element, [2, Res]},
+ S#state{bqstate = BQ1}.
%% Postconditions
@@ -321,6 +329,12 @@ postcondition(S, {call, ?BQMOD, drain_confirmed, _Args}, Res) ->
lists:all(fun (M) -> gb_sets:is_element(M, Confirms) end,
ReportedConfirmed);
+postcondition(S, {call, ?BQMOD, fold, _Args}, {Res, _BQ}) ->
+ #state{messages = Messages} = S,
+ lists:foldl(fun ({_SeqId, {_MsgProps, Msg}}, Acc) ->
+ foldfun(Msg, Acc)
+ end, foldacc(), gb_trees:to_list(Messages)) =:= Res;
+
postcondition(#state{bqstate = BQ, len = Len}, {call, _M, _F, _A}, _Res) ->
?BQMOD:len(BQ) =:= Len.
@@ -379,6 +393,9 @@ rand_choice(List, Selection, N) ->
rand_choice(List -- [Picked], [Picked | Selection],
N - 1).
+foldfun(Msg, Acc) -> [Msg | Acc].
+foldacc() -> [].
+
dropfun(Props) ->
Expiry = eval({call, erlang, element,
[?RECORD_INDEX(expiry, message_properties), Props]}),
diff --git a/src/rabbit_variable_queue.erl b/src/rabbit_variable_queue.erl
index 7636d5ea..f49aa085 100644
--- a/src/rabbit_variable_queue.erl
+++ b/src/rabbit_variable_queue.erl
@@ -18,8 +18,8 @@
-export([init/3, terminate/2, delete_and_terminate/2, purge/1,
publish/4, publish_delivered/4, discard/3, drain_confirmed/1,
- dropwhile/3, fetch/2, drop/2, ack/2, requeue/2, len/1, is_empty/1,
- depth/1, set_ram_duration_target/2, ram_duration/1,
+ dropwhile/3, fetch/2, drop/2, ack/2, requeue/2, fold/3, len/1,
+ is_empty/1, depth/1, set_ram_duration_target/2, ram_duration/1,
needs_timeout/1, timeout/1, handle_pre_hibernate/1, status/1, invoke/3,
is_duplicate/2, multiple_routing_keys/0, foreach_ack/3]).
@@ -684,7 +684,7 @@ fold(Fun, Acc, #vqstate { q1 = Q1,
q3 = Q3,
q4 = Q4} = State) ->
QFun = fun(M, {A, S}) ->
- {#msg_status{msg = Msg}, State1} = read_msg(M, S, false),
+ {#msg_status{msg = Msg}, State1} = read_msg(M, false, S),
A1 = Fun(Msg, A),
{A1, State1}
end,