This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allows controlling amount of cached msgs with argument
- Loading branch information
1 parent
d990c3b
commit 131ef8c
Showing
4 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-define(KEEP_NB, 20). | ||
-define(RH_TABLE, rh_exchange_table). | ||
-record(cached, {key, content}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
DEPS:=rabbitmq-server rabbitmq-erlang-client | ||
RETAIN_ORIGINAL_VERSION:=true | ||
WITH_BROKER_TEST_COMMANDS:=rabbit_exchange_type_recent_history_test:test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
%% The contents of this file are subject to the Mozilla Public License | ||
%% Version 1.1 (the "License"); you may not use this file except in | ||
%% compliance with the License. You may obtain a copy of the License | ||
%% at http://www.mozilla.org/MPL/ | ||
%% | ||
%% Software distributed under the License is distributed on an "AS IS" | ||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
%% the License for the specific language governing rights and | ||
%% limitations under the License. | ||
%% | ||
%% The Original Code is RabbitMQ Consistent Hash Exchange. | ||
%% | ||
%% The Initial Developer of the Original Code is GoPivotal, Inc. | ||
%% Copyright (c) 2011-2014 GoPivotal, Inc. All rights reserved. | ||
%% | ||
|
||
-module(rabbit_exchange_type_recent_history_test). | ||
|
||
-export([test/0]). | ||
|
||
-include_lib("eunit/include/eunit.hrl"). | ||
-include_lib("amqp_client/include/amqp_client.hrl"). | ||
-include("rabbit_recent_history.hrl"). | ||
|
||
test() -> | ||
t([<<"q0">>, <<"q1">>, <<"q2">>, <<"q3">>]). | ||
|
||
t(Qs) -> | ||
ok = test_with_default_length(Qs), | ||
ok = test_with_length(Qs), | ||
ok. | ||
|
||
test_with_default_length(Qs) -> | ||
test0(fun () -> | ||
#'basic.publish'{exchange = <<"e">>} | ||
end, | ||
fun() -> | ||
#amqp_msg{props = #'P_basic'{}, payload = <<>>} | ||
end, [], Qs, 100, length(Qs) * ?KEEP_NB). | ||
|
||
test_with_length(Qs) -> | ||
test0(fun () -> | ||
#'basic.publish'{exchange = <<"e">>} | ||
end, | ||
fun() -> | ||
#amqp_msg{props = #'P_basic'{}, payload = <<>>} | ||
end, [{<<"history-length">>, long, 30}], Qs, 100, length(Qs) * 30). | ||
|
||
test0(MakeMethod, MakeMsg, DeclareArgs, Queues, MsgCount, ExpectedCount) -> | ||
|
||
{ok, Conn} = amqp_connection:start(#amqp_params_network{}), | ||
{ok, Chan} = amqp_connection:open_channel(Conn), | ||
#'exchange.declare_ok'{} = | ||
amqp_channel:call(Chan, | ||
#'exchange.declare' { | ||
exchange = <<"e">>, | ||
type = <<"x-recent-history">>, | ||
auto_delete = true, | ||
arguments = DeclareArgs | ||
}), | ||
|
||
#'tx.select_ok'{} = amqp_channel:call(Chan, #'tx.select'{}), | ||
[amqp_channel:call(Chan, | ||
MakeMethod(), | ||
MakeMsg()) || _ <- lists:duplicate(MsgCount, const)], | ||
amqp_channel:call(Chan, #'tx.commit'{}), | ||
|
||
[#'queue.declare_ok'{} = | ||
amqp_channel:call(Chan, #'queue.declare' { | ||
queue = Q, exclusive = true }) || Q <- Queues], | ||
|
||
[#'queue.bind_ok'{} = | ||
amqp_channel:call(Chan, #'queue.bind' { queue = Q, | ||
exchange = <<"e">>, | ||
routing_key = <<"">>}) | ||
|| Q <- Queues], | ||
|
||
Counts = | ||
[begin | ||
#'queue.declare_ok'{message_count = M} = | ||
amqp_channel:call(Chan, #'queue.declare' {queue = Q, | ||
exclusive = true }), | ||
M | ||
end || Q <- Queues], | ||
|
||
|
||
?assertEqual(ExpectedCount, lists:sum(Counts)), | ||
|
||
amqp_channel:call(Chan, #'exchange.delete' { exchange = <<"e">> }), | ||
[amqp_channel:call(Chan, #'queue.delete' { queue = Q }) || Q <- Queues], | ||
amqp_channel:close(Chan), | ||
amqp_connection:close(Conn), | ||
ok. |