1
%% The contents of this file are subject to the Mozilla Public License
2
%% Version 1.1 (the "License"); you may not use this file except in
3
%% compliance with the License. You may obtain a copy of the License
4
%% at http://www.mozilla.org/MPL/
6
%% Software distributed under the License is distributed on an "AS IS"
7
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8
%% the License for the specific language governing rights and
9
%% limitations under the License.
11
%% The Original Code is RabbitMQ Federation.
13
%% The Initial Developer of the Original Code is VMware, Inc.
14
%% Copyright (c) 2007-2013 VMware, Inc. All rights reserved.
17
-module(rabbit_federation_unit_test).
19
-define(US_NAME, <<"upstream">>).
20
-define(DS_NAME, <<"downstream">>).
22
-include("rabbit_federation_old.hrl").
23
-include_lib("eunit/include/eunit.hrl").
24
-include_lib("rabbit_common/include/rabbit.hrl").
26
%% Test that we apply binding changes in the correct order even when
27
%% they arrive out of order.
28
serialisation_test() ->
31
[B1, B2, B3] = [b(K) || K <- [<<"1">>, <<"2">>, <<"3">>]],
32
remove_bindings(4, X, [B1, B3]),
33
add_binding(5, X, B1),
34
add_binding(1, X, B1),
35
add_binding(2, X, B2),
36
add_binding(3, X, B3),
38
%% List of lists because one for each link
39
Keys = rabbit_federation_old_link:list_routing_keys(X#exchange.name),
40
?assertEqual([[<<"1">>, <<"2">>]], Keys)
43
with_exchanges(Fun) ->
44
rabbit_exchange:declare(r(?US_NAME), fanout,
45
false, false, false, []),
46
X = #exchange{arguments = Args} = x(),
47
rabbit_exchange:declare(r(?DS_NAME), 'x-federation',
48
false, false, false, Args),
51
rabbit_exchange:delete(r(?US_NAME), false),
52
rabbit_exchange:delete(r(?DS_NAME), false),
55
add_binding(Ser, X, B) ->
56
rabbit_federation_old_exchange:add_binding(transaction, X, B),
57
rabbit_federation_old_exchange:add_binding(Ser, X, B).
59
remove_bindings(Ser, X, Bs) ->
60
rabbit_federation_old_exchange:remove_bindings(transaction, X, Bs),
61
rabbit_federation_old_exchange:remove_bindings(Ser, X, Bs).
64
Args = [{<<"upstream-set">>, longstr, <<"upstream">>},
65
{<<"type">>, longstr, <<"fanout">>}],
66
#exchange{name = r(?DS_NAME),
67
type = 'x-federation',
73
r(Name) -> rabbit_misc:r(<<"/">>, exchange, Name).
76
#binding{source = ?DS_NAME, destination = <<"whatever">>,
77
key = Key, args = []}.
79
scratch_space_test() ->
82
DB = rabbit_federation_old_db,
84
fun(#exchange{name = N}) ->
85
DB:set_active_suffix(N, upstream(x), A),
86
DB:set_active_suffix(N, upstream(y), A),
87
DB:prune_scratch(N, [upstream(y), upstream(z)]),
88
DB:set_active_suffix(N, upstream(y), B),
89
DB:set_active_suffix(N, upstream(z), A),
90
?assertEqual(none, DB:get_active_suffix(N, upstream(x), none)),
91
?assertEqual(B, DB:get_active_suffix(N, upstream(y), none)),
92
?assertEqual(A, DB:get_active_suffix(N, upstream(z), none))
96
#upstream{connection_name = atom_to_list(ConnName),
97
exchange = <<"upstream">>}.