Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit policy merging for boolean keys #3880

Merged
merged 1 commit into from Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion deps/rabbit/src/rabbit_policies.erl
Expand Up @@ -176,4 +176,6 @@ merge_policy_value(<<"max-length-bytes">>, Val, OpVal) -> min(Val, OpVal);
merge_policy_value(<<"max-in-memory-length">>, Val, OpVal) -> min(Val, OpVal);
merge_policy_value(<<"max-in-memory-bytes">>, Val, OpVal) -> min(Val, OpVal);
merge_policy_value(<<"expires">>, Val, OpVal) -> min(Val, OpVal);
merge_policy_value(<<"delivery-limit">>, Val, OpVal) -> min(Val, OpVal).
merge_policy_value(<<"delivery-limit">>, Val, OpVal) -> min(Val, OpVal);
%% use operator policy value for booleans
merge_policy_value(_Key, Val, OpVal) when is_boolean(Val) andalso is_boolean(OpVal) -> OpVal.
55 changes: 52 additions & 3 deletions deps/rabbit/test/unit_operator_policy_SUITE.erl
Expand Up @@ -21,7 +21,8 @@ all() ->
groups() ->
[
{parallel_tests, [parallel], [
merge_operator_policy_definitions
merge_operator_policy_definitions,
conflict_resolution_for_booleans
]}
].

Expand Down Expand Up @@ -102,6 +103,54 @@ merge_operator_policy_definitions(_Config) ->
[{definition, [
{<<"message-ttl">>, 3000}
]}])
),
).


passed.
conflict_resolution_for_booleans(_Config) ->
?assertEqual(
[
{<<"remote-dc-replicate">>, true}
],
rabbit_policy:merge_operator_definitions(
#{definition => #{
<<"remote-dc-replicate">> => true
}},
[{definition, [
{<<"remote-dc-replicate">>, true}
]}])),

?assertEqual(
[
{<<"remote-dc-replicate">>, false}
],
rabbit_policy:merge_operator_definitions(
#{definition => #{
<<"remote-dc-replicate">> => false
}},
[{definition, [
{<<"remote-dc-replicate">>, false}
]}])),

?assertEqual(
[
{<<"remote-dc-replicate">>, true}
],
rabbit_policy:merge_operator_definitions(
#{definition => #{
<<"remote-dc-replicate">> => false
}},
[{definition, [
{<<"remote-dc-replicate">>, true}
]}])),

?assertEqual(
[
{<<"remote-dc-replicate">>, false}
],
rabbit_policy:merge_operator_definitions(
#{definition => #{
<<"remote-dc-replicate">> => true
}},
[{definition, [
{<<"remote-dc-replicate">>, false}
]}])).