Skip to content

Commit 43a239d

Browse files
author
Daniil Fedotov
committed
Updated tests to support per-vhost message store
1 parent 99ee963 commit 43a239d

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

test/channel_operation_timeout_test_queue.erl

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,21 @@ stop() ->
234234
ok = rabbit_queue_index:stop().
235235

236236
start_msg_store(Refs, StartFunState) ->
237-
ok = rabbit_sup:start_child(?TRANSIENT_MSG_STORE, rabbit_msg_store,
237+
ok = rabbit_sup:start_child(?TRANSIENT_MSG_STORE, rabbit_msg_store_vhost_sup,
238238
[?TRANSIENT_MSG_STORE, rabbit_mnesia:dir(),
239239
undefined, {fun (ok) -> finished end, ok}]),
240-
ok = rabbit_sup:start_child(?PERSISTENT_MSG_STORE, rabbit_msg_store,
240+
ok = rabbit_sup:start_child(?PERSISTENT_MSG_STORE, rabbit_msg_store_vhost_sup,
241241
[?PERSISTENT_MSG_STORE, rabbit_mnesia:dir(),
242-
Refs, StartFunState]).
242+
Refs, StartFunState]),
243+
%% Start message store for all known vhosts
244+
VHosts = rabbit_vhost:list(),
245+
lists:foreach(
246+
fun(VHost) ->
247+
rabbit_msg_store_vhost_sup:add_vhost(?TRANSIENT_MSG_STORE, VHost),
248+
rabbit_msg_store_vhost_sup:add_vhost(?PERSISTENT_MSG_STORE, VHost)
249+
end,
250+
VHosts),
251+
ok.
243252

244253
stop_msg_store() ->
245254
ok = rabbit_sup:stop_child(?PERSISTENT_MSG_STORE),
@@ -258,22 +267,26 @@ init(#amqqueue { name = QueueName, durable = IsDurable }, new,
258267
AsyncCallback, MsgOnDiskFun, MsgIdxOnDiskFun, MsgAndIdxOnDiskFun) ->
259268
IndexState = rabbit_queue_index:init(QueueName,
260269
MsgIdxOnDiskFun, MsgAndIdxOnDiskFun),
270+
VHost = QueueName#resource.virtual_host,
261271
init(IsDurable, IndexState, 0, 0, [],
262272
case IsDurable of
263273
true -> msg_store_client_init(?PERSISTENT_MSG_STORE,
264-
MsgOnDiskFun, AsyncCallback);
274+
MsgOnDiskFun, AsyncCallback,
275+
VHost);
265276
false -> undefined
266277
end,
267-
msg_store_client_init(?TRANSIENT_MSG_STORE, undefined, AsyncCallback));
278+
msg_store_client_init(?TRANSIENT_MSG_STORE, undefined, AsyncCallback, VHost));
268279

269280
%% We can be recovering a transient queue if it crashed
270281
init(#amqqueue { name = QueueName, durable = IsDurable }, Terms,
271282
AsyncCallback, MsgOnDiskFun, MsgIdxOnDiskFun, MsgAndIdxOnDiskFun) ->
272283
{PRef, RecoveryTerms} = process_recovery_terms(Terms),
284+
VHost = QueueName#resource.virtual_host,
273285
{PersistentClient, ContainsCheckFun} =
274286
case IsDurable of
275287
true -> C = msg_store_client_init(?PERSISTENT_MSG_STORE, PRef,
276-
MsgOnDiskFun, AsyncCallback),
288+
MsgOnDiskFun, AsyncCallback,
289+
VHost),
277290
{C, fun (MsgId) when is_binary(MsgId) ->
278291
rabbit_msg_store:contains(MsgId, C);
279292
(#basic_message{is_persistent = Persistent}) ->
@@ -282,11 +295,12 @@ init(#amqqueue { name = QueueName, durable = IsDurable }, Terms,
282295
false -> {undefined, fun(_MsgId) -> false end}
283296
end,
284297
TransientClient = msg_store_client_init(?TRANSIENT_MSG_STORE,
285-
undefined, AsyncCallback),
298+
undefined, AsyncCallback,
299+
VHost),
286300
{DeltaCount, DeltaBytes, IndexState} =
287301
rabbit_queue_index:recover(
288302
QueueName, RecoveryTerms,
289-
rabbit_msg_store:successfully_recovered_state(?PERSISTENT_MSG_STORE),
303+
rabbit_msg_store_vhost_sup:successfully_recovered_state(?PERSISTENT_MSG_STORE),
290304
ContainsCheckFun, MsgIdxOnDiskFun, MsgAndIdxOnDiskFun),
291305
init(IsDurable, IndexState, DeltaCount, DeltaBytes, RecoveryTerms,
292306
PersistentClient, TransientClient).
@@ -961,14 +975,16 @@ with_immutable_msg_store_state(MSCState, IsPersistent, Fun) ->
961975
end),
962976
Res.
963977

964-
msg_store_client_init(MsgStore, MsgOnDiskFun, Callback) ->
978+
msg_store_client_init(MsgStore, MsgOnDiskFun, Callback, VHost) ->
965979
msg_store_client_init(MsgStore, rabbit_guid:gen(), MsgOnDiskFun,
966-
Callback).
980+
Callback, VHost).
967981

968-
msg_store_client_init(MsgStore, Ref, MsgOnDiskFun, Callback) ->
982+
msg_store_client_init(MsgStore, Ref, MsgOnDiskFun, Callback, VHost) ->
969983
CloseFDsFun = msg_store_close_fds_fun(MsgStore =:= ?PERSISTENT_MSG_STORE),
970-
rabbit_msg_store:client_init(MsgStore, Ref, MsgOnDiskFun,
971-
fun () -> Callback(?MODULE, CloseFDsFun) end).
984+
rabbit_msg_store_vhost_sup:client_init(
985+
MsgStore, Ref, MsgOnDiskFun,
986+
fun () -> Callback(?MODULE, CloseFDsFun) end,
987+
VHost).
972988

973989
msg_store_write(MSCState, IsPersistent, MsgId, Msg) ->
974990
with_immutable_msg_store_state(

test/unit_inbroker_SUITE.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,10 @@ on_disk_stop(Pid) ->
468468

469469
msg_store_client_init_capture(MsgStore, Ref) ->
470470
Pid = spawn(fun on_disk_capture/0),
471-
{Pid, rabbit_msg_store:client_init(
471+
{Pid, rabbit_msg_store_vhost_sup:client_init(
472472
MsgStore, Ref, fun (MsgIds, _ActionTaken) ->
473473
Pid ! {on_disk, MsgIds}
474-
end, undefined)}.
474+
end, undefined, <<"/">>)}.
475475

476476
msg_store_contains(Atom, MsgIds, MSCState) ->
477477
Atom = lists:foldl(
@@ -548,14 +548,14 @@ test_msg_store_confirm_timer() ->
548548
Ref = rabbit_guid:gen(),
549549
MsgId = msg_id_bin(1),
550550
Self = self(),
551-
MSCState = rabbit_msg_store:client_init(
551+
MSCState = rabbit_msg_store_vhost_sup:client_init(
552552
?PERSISTENT_MSG_STORE, Ref,
553553
fun (MsgIds, _ActionTaken) ->
554554
case gb_sets:is_member(MsgId, MsgIds) of
555555
true -> Self ! on_disk;
556556
false -> ok
557557
end
558-
end, undefined),
558+
end, undefined, <<"/">>),
559559
ok = msg_store_write([MsgId], MSCState),
560560
ok = msg_store_keep_busy_until_confirm([msg_id_bin(2)], MSCState, false),
561561
ok = msg_store_remove([MsgId], MSCState),
@@ -1424,7 +1424,7 @@ nop(_) -> ok.
14241424
nop(_, _) -> ok.
14251425

14261426
msg_store_client_init(MsgStore, Ref) ->
1427-
rabbit_msg_store:client_init(MsgStore, Ref, undefined, undefined).
1427+
rabbit_msg_store_vhost_sup:client_init(MsgStore, Ref, undefined, undefined, <<"/">>).
14281428

14291429
variable_queue_init(Q, Recover) ->
14301430
rabbit_variable_queue:init(

0 commit comments

Comments
 (0)