diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-09-30 12:23:07 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-09-30 12:23:07 +0100 |
commit | 2f4ab5c8aa0d4c32834962be5b1f0d50496dc576 (patch) | |
tree | 183ba02d4d328662020f11890fc61c83b4da2e91 /src/rabbit_backing_queue_qc.erl | |
parent | 80e2c5091671543e556eb357a8440f40a3090e70 (diff) | |
parent | ff2ed02403c733caf895061d1fb8ab9182cdf1e6 (diff) | |
download | rabbitmq-server-2f4ab5c8aa0d4c32834962be5b1f0d50496dc576.tar.gz |
merge default into bug23764
Diffstat (limited to 'src/rabbit_backing_queue_qc.erl')
-rw-r--r-- | src/rabbit_backing_queue_qc.erl | 93 |
1 files changed, 41 insertions, 52 deletions
diff --git a/src/rabbit_backing_queue_qc.erl b/src/rabbit_backing_queue_qc.erl index a8cfe6ba..095202dd 100644 --- a/src/rabbit_backing_queue_qc.erl +++ b/src/rabbit_backing_queue_qc.erl @@ -27,8 +27,9 @@ -define(TIMEOUT_LIMIT, 100). -define(RECORD_INDEX(Key, Record), - proplists:get_value(Key, lists:zip( - record_info(fields, Record), lists:seq(2, record_info(size, Record))))). + proplists:get_value( + Key, lists:zip(record_info(fields, Record), + lists:seq(2, record_info(size, Record))))). -export([initial_state/0, command/1, precondition/2, postcondition/3, next_state/3]). @@ -56,7 +57,7 @@ initial_state() -> prop_backing_queue_test() -> ?FORALL(Cmds, commands(?MODULE, initial_state()), - backing_queue_test(Cmds)). + backing_queue_test(Cmds)). backing_queue_test(Cmds) -> {ok, FileSizeLimit} = @@ -77,8 +78,8 @@ backing_queue_test(Cmds) -> ?BQMOD:delete_and_terminate(shutdown, BQ), ?WHENFAIL( - io:format("Result: ~p~n", [Res]), - aggregate(command_names(Cmds), Res =:= ok)). + io:format("Result: ~p~n", [Res]), + aggregate(command_names(Cmds), Res =:= ok)). %% Commands @@ -105,20 +106,20 @@ command(S) -> qc_publish(#state{bqstate = BQ}) -> {call, ?BQMOD, publish, - [qc_message(), - #message_properties{needs_confirming = frequency([{1, true}, - {20, false}]), - expiry = oneof([undefined | lists:seq(1, 10)])}, - self(), BQ]}. + [qc_message(), + #message_properties{needs_confirming = frequency([{1, true}, + {20, false}]), + expiry = oneof([undefined | lists:seq(1, 10)])}, + self(), BQ]}. qc_publish_multiple(#state{bqstate = BQ}) -> {call, ?MODULE, publish_multiple, - [qc_message(), #message_properties{}, BQ, - resize(?QUEUE_MAXLEN, pos_integer())]}. + [qc_message(), #message_properties{}, BQ, + resize(?QUEUE_MAXLEN, pos_integer())]}. qc_publish_delivered(#state{bqstate = BQ}) -> {call, ?BQMOD, publish_delivered, - [boolean(), qc_message(), #message_properties{}, self(), BQ]}. + [boolean(), qc_message(), #message_properties{}, self(), BQ]}. qc_fetch(#state{bqstate = BQ}) -> {call, ?BQMOD, fetch, [boolean(), BQ]}. @@ -132,7 +133,7 @@ qc_requeue(#state{bqstate = BQ, acks = Acks}) -> qc_set_ram_duration_target(#state{bqstate = BQ}) -> {call, ?BQMOD, set_ram_duration_target, - [oneof([0, 1, 2, resize(1000, pos_integer()), infinity]), BQ]}. + [oneof([0, 1, 2, resize(1000, pos_integer()), infinity]), BQ]}. qc_ram_duration(#state{bqstate = BQ}) -> {call, ?BQMOD, ram_duration, [BQ]}. @@ -155,7 +156,7 @@ qc_purge(#state{bqstate = BQ}) -> %% Preconditions precondition(#state{acks = Acks}, {call, ?BQMOD, Fun, _Arg}) - when Fun =:= ack; Fun =:= requeue -> + when Fun =:= ack; Fun =:= requeue -> length(Acks) > 0; precondition(#state{messages = Messages}, {call, ?BQMOD, publish_delivered, _Arg}) -> @@ -177,7 +178,7 @@ next_state(S, BQ, {call, ?BQMOD, publish, [Msg, MsgProps, _Pid, _BQ]}) -> MsgId = {call, erlang, element, [?RECORD_INDEX(id, basic_message), Msg]}, NeedsConfirm = {call, erlang, element, - [?RECORD_INDEX(needs_confirming, message_properties), MsgProps]}, + [?RECORD_INDEX(needs_confirming, message_properties), MsgProps]}, S#state{bqstate = BQ, len = Len + 1, next_seq_id = NextSeq + 1, @@ -200,14 +201,14 @@ next_state(S, BQ, {call, _, publish_multiple, [Msg, MsgProps, _BQ, Count]}) -> next_state(S, Res, {call, ?BQMOD, publish_delivered, - [AckReq, Msg, MsgProps, _Pid, _BQ]}) -> + [AckReq, Msg, MsgProps, _Pid, _BQ]}) -> #state{confirms = Confirms, acks = Acks, next_seq_id = NextSeq} = S, AckTag = {call, erlang, element, [1, Res]}, BQ1 = {call, erlang, element, [2, Res]}, MsgId = {call, erlang, element, [?RECORD_INDEX(id, basic_message), Msg]}, NeedsConfirm = {call, erlang, element, - [?RECORD_INDEX(needs_confirming, message_properties), MsgProps]}, + [?RECORD_INDEX(needs_confirming, message_properties), MsgProps]}, S#state{bqstate = BQ1, next_seq_id = NextSeq + 1, confirms = case eval(NeedsConfirm) of @@ -292,8 +293,8 @@ postcondition(S, {call, ?BQMOD, fetch, _Args}, Res) -> {_SeqId, {_MsgProps, Msg}} = gb_trees:smallest(Messages), MsgFetched =:= Msg andalso not proplists:is_defined(AckTag, Acks) andalso - not gb_sets:is_element(AckTag, Confrms) andalso - RemainingLen =:= Len - 1; + not gb_sets:is_element(AckTag, Confrms) andalso + RemainingLen =:= Len - 1; {empty, _BQ} -> Len =:= 0 end; @@ -301,37 +302,32 @@ postcondition(S, {call, ?BQMOD, fetch, _Args}, Res) -> postcondition(S, {call, ?BQMOD, publish_delivered, _Args}, {AckTag, _BQ}) -> #state{acks = Acks, confirms = Confrms} = S, not proplists:is_defined(AckTag, Acks) andalso - not gb_sets:is_element(AckTag, Confrms); + not gb_sets:is_element(AckTag, Confrms); postcondition(#state{len = Len}, {call, ?BQMOD, purge, _Args}, Res) -> {PurgeCount, _BQ} = Res, Len =:= PurgeCount; -postcondition(#state{len = Len}, - {call, ?BQMOD, is_empty, _Args}, Res) -> +postcondition(#state{len = Len}, {call, ?BQMOD, is_empty, _Args}, Res) -> (Len =:= 0) =:= Res; postcondition(S, {call, ?BQMOD, drain_confirmed, _Args}, Res) -> #state{confirms = Confirms} = S, {ReportedConfirmed, _BQ} = Res, - lists:all(fun (M) -> - gb_sets:is_element(M, Confirms) - end, ReportedConfirmed); + lists:all(fun (M) -> gb_sets:is_element(M, Confirms) end, + ReportedConfirmed); postcondition(#state{bqstate = BQ, len = Len}, {call, _M, _F, _A}, _Res) -> ?BQMOD:len(BQ) =:= Len. %% Helpers -repeat(Result, _Fun, 0) -> - Result; -repeat(Result, Fun, Times) -> - repeat(Fun(Result), Fun, Times - 1). +repeat(Result, _Fun, 0) -> Result; +repeat(Result, Fun, Times) -> repeat(Fun(Result), Fun, Times - 1). publish_multiple(Msg, MsgProps, BQ, Count) -> - repeat(BQ, fun(BQ1) -> - ?BQMOD:publish(Msg, MsgProps, self(), BQ1) - end, Count). + repeat(BQ, fun(BQ1) -> ?BQMOD:publish(Msg, MsgProps, self(), BQ1) end, + Count). timeout(BQ, 0) -> BQ; @@ -341,37 +337,30 @@ timeout(BQ, AtMost) -> _ -> timeout(?BQMOD:timeout(BQ), AtMost - 1) end. -qc_message_payload() -> - ?SIZED(Size, resize(Size * Size, binary())). +qc_message_payload() -> ?SIZED(Size, resize(Size * Size, binary())). -qc_routing_key() -> - noshrink(binary(10)). +qc_routing_key() -> noshrink(binary(10)). -qc_delivery_mode() -> - oneof([1, 2]). +qc_delivery_mode() -> oneof([1, 2]). -qc_message() -> - qc_message(qc_delivery_mode()). +qc_message() -> qc_message(qc_delivery_mode()). qc_message(DeliveryMode) -> - {call, rabbit_basic, message, [ - qc_default_exchange(), - qc_routing_key(), - #'P_basic'{delivery_mode = DeliveryMode}, - qc_message_payload()]}. + {call, rabbit_basic, message, [qc_default_exchange(), + qc_routing_key(), + #'P_basic'{delivery_mode = DeliveryMode}, + qc_message_payload()]}. qc_default_exchange() -> {call, rabbit_misc, r, [<<>>, exchange, <<>>]}. qc_variable_queue_init(Q) -> {call, ?BQMOD, init, - [Q, false, function(2, ok)]}. + [Q, false, function(2, ok)]}. -qc_test_q() -> - {call, rabbit_misc, r, [<<"/">>, queue, noshrink(binary(16))]}. +qc_test_q() -> {call, rabbit_misc, r, [<<"/">>, queue, noshrink(binary(16))]}. -qc_test_queue() -> - qc_test_queue(boolean()). +qc_test_queue() -> qc_test_queue(boolean()). qc_test_queue(Durable) -> #amqqueue{name = qc_test_q(), @@ -392,7 +381,7 @@ rand_choice(List, Selection, N) -> dropfun(Props) -> Expiry = eval({call, erlang, element, - [?RECORD_INDEX(expiry, message_properties), Props]}), + [?RECORD_INDEX(expiry, message_properties), Props]}), Expiry =/= 1. drop_messages(Messages) -> |