~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy-proposed

« back to all changes in this revision

Viewing changes to plugins-src/rabbitmq-old-federation/test/src/rabbit_federation_unit_test.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2013-05-02 11:19:31 UTC
  • mfrom: (0.5.2) (0.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20130502111931-xnoj0sejto2tewcj
Tags: 3.1.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/
5
 
%%
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.
10
 
%%
11
 
%% The Original Code is RabbitMQ Federation.
12
 
%%
13
 
%% The Initial Developer of the Original Code is VMware, Inc.
14
 
%% Copyright (c) 2007-2013 VMware, Inc.  All rights reserved.
15
 
%%
16
 
 
17
 
-module(rabbit_federation_unit_test).
18
 
 
19
 
-define(US_NAME, <<"upstream">>).
20
 
-define(DS_NAME, <<"downstream">>).
21
 
 
22
 
-include("rabbit_federation_old.hrl").
23
 
-include_lib("eunit/include/eunit.hrl").
24
 
-include_lib("rabbit_common/include/rabbit.hrl").
25
 
 
26
 
%% Test that we apply binding changes in the correct order even when
27
 
%% they arrive out of order.
28
 
serialisation_test() ->
29
 
    with_exchanges(
30
 
      fun(X) ->
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),
37
 
 
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)
41
 
      end).
42
 
 
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),
49
 
 
50
 
    Fun(X),
51
 
    rabbit_exchange:delete(r(?US_NAME), false),
52
 
    rabbit_exchange:delete(r(?DS_NAME), false),
53
 
    ok.
54
 
 
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).
58
 
 
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).
62
 
 
63
 
x() ->
64
 
    Args = [{<<"upstream-set">>, longstr, <<"upstream">>},
65
 
            {<<"type">>,         longstr, <<"fanout">>}],
66
 
    #exchange{name        = r(?DS_NAME),
67
 
              type        = 'x-federation',
68
 
              durable     = false,
69
 
              auto_delete = false,
70
 
              internal    = false,
71
 
              arguments   = Args}.
72
 
 
73
 
r(Name) -> rabbit_misc:r(<<"/">>, exchange, Name).
74
 
 
75
 
b(Key) ->
76
 
    #binding{source = ?DS_NAME, destination = <<"whatever">>,
77
 
             key = Key, args = []}.
78
 
 
79
 
scratch_space_test() ->
80
 
    A = <<"A">>,
81
 
    B = <<"B">>,
82
 
    DB = rabbit_federation_old_db,
83
 
    with_exchanges(
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))
93
 
      end).
94
 
 
95
 
upstream(ConnName) ->
96
 
    #upstream{connection_name = atom_to_list(ConnName),
97
 
              exchange        = <<"upstream">>}.