diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-01-16 19:12:40 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-01-16 19:12:40 +0000 |
commit | f8cd15aca29b1ce85947b6a998cdae4ef5f35a8f (patch) | |
tree | 5d2967c0787633725d8fdaf58248a8ce68c553db | |
parent | 2fe63554b475a54742093f01987e2ad02a7a6405 (diff) | |
download | rabbitmq-server-f8cd15aca29b1ce85947b6a998cdae4ef5f35a8f.tar.gz |
refactor: extract helper for initialising test msg store client
-rw-r--r-- | src/rabbit_tests.erl | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index befcfd99..52f5b3cc 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1459,6 +1459,9 @@ restart_msg_store_empty() -> guid_bin(X) -> erlang:md5(term_to_binary(X)). +msg_store_client_init(MsgStore, Ref) -> + rabbit_msg_store:client_init(MsgStore, Ref, undefined, undefined). + msg_store_contains(Atom, Guids, MSCState) -> Atom = lists:foldl( fun (Guid, Atom1) when Atom1 =:= Atom -> @@ -1502,13 +1505,12 @@ msg_store_remove(MsgStore, Ref, Guids) -> with_msg_store_client(MsgStore, Ref, Fun) -> rabbit_msg_store:client_terminate( - Fun(rabbit_msg_store:client_init(MsgStore, Ref, undefined, undefined))). + Fun(msg_store_client_init(MsgStore, Ref))). foreach_with_msg_store_client(MsgStore, Ref, Fun, L) -> rabbit_msg_store:client_terminate( - lists:foldl( - fun (Guid, MSCState) -> Fun(Guid, MSCState) end, - rabbit_msg_store:client_init(MsgStore, Ref, undefined, undefined), L)). + lists:foldl(fun (Guid, MSCState) -> Fun(Guid, MSCState) end, + msg_store_client_init(MsgStore, Ref), L)). test_msg_store() -> restart_msg_store_empty(), @@ -1516,8 +1518,7 @@ test_msg_store() -> Guids = [guid_bin(M) || M <- lists:seq(1,100)], {Guids1stHalf, Guids2ndHalf} = lists:split(50, Guids), Ref = rabbit_guid:guid(), - MSCState = rabbit_msg_store:client_init(?PERSISTENT_MSG_STORE, Ref, - undefined, undefined), + MSCState = msg_store_client_init(?PERSISTENT_MSG_STORE, Ref), %% check we don't contain any of the msgs we're about to publish false = msg_store_contains(false, Guids, MSCState), %% publish the first half @@ -1583,8 +1584,7 @@ test_msg_store() -> ([Guid|GuidsTail]) -> {Guid, 0, GuidsTail} end, Guids2ndHalf}), - MSCState5 = rabbit_msg_store:client_init(?PERSISTENT_MSG_STORE, Ref, - undefined, undefined), + MSCState5 = msg_store_client_init(?PERSISTENT_MSG_STORE, Ref), %% check we have the right msgs left lists:foldl( fun (Guid, Bool) -> @@ -1593,8 +1593,7 @@ test_msg_store() -> ok = rabbit_msg_store:client_terminate(MSCState5), %% restart empty restart_msg_store_empty(), - MSCState6 = rabbit_msg_store:client_init(?PERSISTENT_MSG_STORE, Ref, - undefined, undefined), + MSCState6 = msg_store_client_init(?PERSISTENT_MSG_STORE, Ref), %% check we don't contain any of the msgs false = msg_store_contains(false, Guids, MSCState6), %% publish the first half again @@ -1602,8 +1601,7 @@ test_msg_store() -> %% this should force some sort of sync internally otherwise misread ok = rabbit_msg_store:client_terminate( msg_store_read(Guids1stHalf, MSCState6)), - MSCState7 = rabbit_msg_store:client_init(?PERSISTENT_MSG_STORE, Ref, - undefined, undefined), + MSCState7 = msg_store_client_init(?PERSISTENT_MSG_STORE, Ref), ok = rabbit_msg_store:remove(Guids1stHalf, MSCState7), ok = rabbit_msg_store:client_terminate(MSCState7), %% restart empty @@ -1661,8 +1659,7 @@ init_test_queue() -> TestQueue = test_queue(), Terms = rabbit_queue_index:shutdown_terms(TestQueue), PRef = proplists:get_value(persistent_ref, Terms, rabbit_guid:guid()), - PersistentClient = rabbit_msg_store:client_init(?PERSISTENT_MSG_STORE, - PRef, undefined, undefined), + PersistentClient = msg_store_client_init(?PERSISTENT_MSG_STORE, PRef), Res = rabbit_queue_index:recover( TestQueue, Terms, false, fun (Guid) -> @@ -1696,8 +1693,7 @@ queue_index_publish(SeqIds, Persistent, Qi) -> true -> ?PERSISTENT_MSG_STORE; false -> ?TRANSIENT_MSG_STORE end, - MSCState = - rabbit_msg_store:client_init(MsgStore, Ref, undefined, undefined), + MSCState = msg_store_client_init(MsgStore, Ref), {A, B = [{_SeqId, LastGuidWritten} | _]} = lists:foldl( fun (SeqId, {QiN, SeqIdsGuidsAcc}) -> |