Skip to content

Commit bf7c4cc

Browse files
committed
Unit test rabbit_db_exchange and API updates
1 parent 3aeb081 commit bf7c4cc

File tree

6 files changed

+492
-105
lines changed

6 files changed

+492
-105
lines changed

deps/rabbit/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,11 @@ rabbitmq_integration_suite(
11181118
size = "small",
11191119
)
11201120

1121+
rabbitmq_integration_suite(
1122+
name = "unit_rabbit_db_exchange_SUITE",
1123+
size = "small",
1124+
)
1125+
11211126
assert_suites()
11221127

11231128
filegroup(

deps/rabbit/src/rabbit_db_binding.erl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
-export([create_index_route_table/0]).
3030

31+
%% For testing
32+
-export([clear/0]).
33+
3134
%% -------------------------------------------------------------------
3235
%% exists().
3336
%% -------------------------------------------------------------------
@@ -60,8 +63,7 @@ exists_in_mnesia(Binding) ->
6063
Binding :: rabbit_types:binding(),
6164
Src :: rabbit_types:r('exchange'),
6265
Dst :: rabbit_types:r('exchange') | rabbit_types:r('queue'),
63-
BindingType :: durable | semi_durable | transient,
64-
ChecksFun :: fun((Src, Dst) -> {ok, BindingType} | {error, Reason :: any()}),
66+
ChecksFun :: fun((Src, Dst) -> ok | {error, Reason :: any()}),
6567
Ret :: ok | {error, Reason :: any()}.
6668
%% @doc Writes a binding if it doesn't exist already and passes the validation in
6769
%% `ChecksFun` i.e. exclusive access
@@ -83,8 +85,7 @@ create(Binding, ChecksFun) ->
8385
Binding :: rabbit_types:binding(),
8486
Src :: rabbit_types:r('exchange'),
8587
Dst :: rabbit_types:r('exchange') | rabbit_types:r('queue'),
86-
BindingType :: durable | semi_durable | transient,
87-
ChecksFun :: fun((Src, Dst) -> {ok, BindingType} | {error, Reason :: any()}),
88+
ChecksFun :: fun((Src, Dst) -> ok | {error, Reason :: any()}),
8889
Ret :: ok | {error, Reason :: any()}.
8990
%% @doc Deletes a binding record from the database if it passes the validation in
9091
%% `ChecksFun`. It also triggers the deletion of auto-delete exchanges if needed.
@@ -557,7 +558,7 @@ recover_semi_durable_route(#route{binding = B} = Route, X) ->
557558
serial_in_mnesia(false, _) ->
558559
none;
559560
serial_in_mnesia(true, X) ->
560-
rabbit_db_exchange:next_serial_in_mnesia_tx(X).
561+
rabbit_db_exchange:next_serial_in_mnesia_tx(X#exchange.name).
561562

562563
sync_route(Route, durable, ShouldIndexTable, Fun) ->
563564
ok = Fun(rabbit_durable_route, Route, write),
@@ -621,6 +622,25 @@ continue('$end_of_table') -> false;
621622
continue({[_|_], _}) -> true;
622623
continue({[], Continuation}) -> continue(mnesia:select(Continuation)).
623624

625+
%% -------------------------------------------------------------------
626+
%% clear().
627+
%% -------------------------------------------------------------------
628+
629+
-spec clear() -> ok.
630+
%% @doc Deletes all bindings.
631+
%%
632+
%% @private
633+
634+
clear() ->
635+
rabbit_db:run(
636+
#{mnesia => fun() -> clear_in_mnesia() end}).
637+
638+
clear_in_mnesia() ->
639+
mnesia:clear_table(rabbit_route),
640+
mnesia:clear_table(rabbit_durable_route),
641+
mnesia:clear_table(rabbit_reverse_route),
642+
mnesia:clear_table(rabbit_index_route).
643+
624644
%% Routing. Hot code path
625645
%% -------------------------------------------------------------------------
626646
route_in_mnesia_v1(SrcName, [RoutingKey]) ->

0 commit comments

Comments
 (0)