Add comments to test
This commit is contained in:
parent
71c2ad1292
commit
c26201c4bb
|
@ -322,6 +322,7 @@ stream_filtering(Config) ->
|
||||||
Version = ?config(version, Config),
|
Version = ?config(version, Config),
|
||||||
Client = ?config(stomp_client, Config),
|
Client = ?config(stomp_client, Config),
|
||||||
Stream = atom_to_list(?FUNCTION_NAME) ++ "-" ++ integer_to_list(rand:uniform(10000)),
|
Stream = atom_to_list(?FUNCTION_NAME) ++ "-" ++ integer_to_list(rand:uniform(10000)),
|
||||||
|
%% subscription just to create the stream from STOMP
|
||||||
SubDestination = "/topic/stream-queue-test",
|
SubDestination = "/topic/stream-queue-test",
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client, "SUBSCRIBE",
|
Client, "SUBSCRIBE",
|
||||||
|
@ -329,6 +330,7 @@ stream_filtering(Config) ->
|
||||||
{"receipt", "foo"},
|
{"receipt", "foo"},
|
||||||
{"x-queue-name", Stream},
|
{"x-queue-name", Stream},
|
||||||
{"x-queue-type", "stream"},
|
{"x-queue-type", "stream"},
|
||||||
|
{?HEADER_X_STREAM_FILTER_SIZE_BYTES, "32"},
|
||||||
{"durable", "true"},
|
{"durable", "true"},
|
||||||
{"auto-delete", "false"},
|
{"auto-delete", "false"},
|
||||||
{"id", "1234"},
|
{"id", "1234"},
|
||||||
|
@ -341,7 +343,12 @@ stream_filtering(Config) ->
|
||||||
{"receipt", "bar"}]),
|
{"receipt", "bar"}]),
|
||||||
{ok, Client2, _, _} = stomp_receive(Client1, "RECEIPT"),
|
{ok, Client2, _, _} = stomp_receive(Client1, "RECEIPT"),
|
||||||
|
|
||||||
|
%% we are going to publish several waves of messages with and without filter values.
|
||||||
|
%% we will then create subscriptions with various filter options
|
||||||
|
%% and make sure we receive only what we asked for and not all the messages.
|
||||||
|
|
||||||
StreamDestination = "/amq/queue/" ++ Stream,
|
StreamDestination = "/amq/queue/" ++ Stream,
|
||||||
|
%% logic to publish a wave of messages with or without a filter value
|
||||||
WaveCount = 1000,
|
WaveCount = 1000,
|
||||||
Publish =
|
Publish =
|
||||||
fun(C, FilterValue) ->
|
fun(C, FilterValue) ->
|
||||||
|
@ -360,11 +367,14 @@ stream_filtering(Config) ->
|
||||||
C1
|
C1
|
||||||
end, C, lists:seq(1, WaveCount))
|
end, C, lists:seq(1, WaveCount))
|
||||||
end,
|
end,
|
||||||
|
%% publishing messages with the "apple" filter value
|
||||||
Client3 = Publish(Client2, "apple"),
|
Client3 = Publish(Client2, "apple"),
|
||||||
|
%% publishing messages with no filter value
|
||||||
Client4 = Publish(Client3, undefined),
|
Client4 = Publish(Client3, undefined),
|
||||||
|
%% publishing messages with the "orange" filter value
|
||||||
Client5 = Publish(Client4, "orange"),
|
Client5 = Publish(Client4, "orange"),
|
||||||
|
|
||||||
%% one filter
|
%% filtering on "apple"
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client5, "SUBSCRIBE",
|
Client5, "SUBSCRIBE",
|
||||||
[{"destination", StreamDestination},
|
[{"destination", StreamDestination},
|
||||||
|
@ -374,11 +384,14 @@ stream_filtering(Config) ->
|
||||||
{"x-stream-filter", "apple"},
|
{"x-stream-filter", "apple"},
|
||||||
{"x-stream-offset", "first"}]),
|
{"x-stream-offset", "first"}]),
|
||||||
{Client6, AppleMessages} = stomp_receive_messages(Client5, Version),
|
{Client6, AppleMessages} = stomp_receive_messages(Client5, Version),
|
||||||
|
%% we should get less than all the waves combined
|
||||||
?assert(length(AppleMessages) < WaveCount * 3),
|
?assert(length(AppleMessages) < WaveCount * 3),
|
||||||
|
%% client-side filtering
|
||||||
AppleFilteredMessages =
|
AppleFilteredMessages =
|
||||||
lists:filter(fun(H) ->
|
lists:filter(fun(H) ->
|
||||||
proplists:get_value("x-stream-filter-value", H) =:= "apple"
|
proplists:get_value("x-stream-filter-value", H) =:= "apple"
|
||||||
end, AppleMessages),
|
end, AppleMessages),
|
||||||
|
%% we should have only the "apple" messages
|
||||||
?assert(length(AppleFilteredMessages) =:= WaveCount),
|
?assert(length(AppleFilteredMessages) =:= WaveCount),
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client6, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
Client6, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
||||||
|
@ -386,7 +399,7 @@ stream_filtering(Config) ->
|
||||||
{"receipt", "bar"}]),
|
{"receipt", "bar"}]),
|
||||||
{ok, Client7, _, _} = stomp_receive(Client6, "RECEIPT"),
|
{ok, Client7, _, _} = stomp_receive(Client6, "RECEIPT"),
|
||||||
|
|
||||||
%% two filters
|
%% filtering on "apple" and "orange"
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client7, "SUBSCRIBE",
|
Client7, "SUBSCRIBE",
|
||||||
[{"destination", StreamDestination},
|
[{"destination", StreamDestination},
|
||||||
|
@ -396,12 +409,15 @@ stream_filtering(Config) ->
|
||||||
{"x-stream-filter", "apple,orange"},
|
{"x-stream-filter", "apple,orange"},
|
||||||
{"x-stream-offset", "first"}]),
|
{"x-stream-offset", "first"}]),
|
||||||
{Client8, AppleOrangeMessages} = stomp_receive_messages(Client7, Version),
|
{Client8, AppleOrangeMessages} = stomp_receive_messages(Client7, Version),
|
||||||
|
%% we should get less than all the waves combined
|
||||||
?assert(length(AppleOrangeMessages) < WaveCount * 3),
|
?assert(length(AppleOrangeMessages) < WaveCount * 3),
|
||||||
|
%% client-side filtering
|
||||||
AppleOrangeFilteredMessages =
|
AppleOrangeFilteredMessages =
|
||||||
lists:filter(fun(H) ->
|
lists:filter(fun(H) ->
|
||||||
proplists:get_value("x-stream-filter-value", H) =:= "apple" orelse
|
proplists:get_value("x-stream-filter-value", H) =:= "apple" orelse
|
||||||
proplists:get_value("x-stream-filter-value", H) =:= "orange"
|
proplists:get_value("x-stream-filter-value", H) =:= "orange"
|
||||||
end, AppleOrangeMessages),
|
end, AppleOrangeMessages),
|
||||||
|
%% we should have only the "apple" and "orange" messages
|
||||||
?assert(length(AppleOrangeFilteredMessages) =:= WaveCount * 2),
|
?assert(length(AppleOrangeFilteredMessages) =:= WaveCount * 2),
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client8, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
Client8, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
||||||
|
@ -409,7 +425,7 @@ stream_filtering(Config) ->
|
||||||
{"receipt", "bar"}]),
|
{"receipt", "bar"}]),
|
||||||
{ok, Client9, _, _} = stomp_receive(Client8, "RECEIPT"),
|
{ok, Client9, _, _} = stomp_receive(Client8, "RECEIPT"),
|
||||||
|
|
||||||
%% one filter and unfiltered
|
%% filtering on "apple" and messages without a filter value
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client9, "SUBSCRIBE",
|
Client9, "SUBSCRIBE",
|
||||||
[{"destination", StreamDestination},
|
[{"destination", StreamDestination},
|
||||||
|
@ -420,12 +436,15 @@ stream_filtering(Config) ->
|
||||||
{"x-stream-match-unfiltered", "true"},
|
{"x-stream-match-unfiltered", "true"},
|
||||||
{"x-stream-offset", "first"}]),
|
{"x-stream-offset", "first"}]),
|
||||||
{Client10, AppleUnfilteredMessages} = stomp_receive_messages(Client9, Version),
|
{Client10, AppleUnfilteredMessages} = stomp_receive_messages(Client9, Version),
|
||||||
|
%% we should get less than all the waves combined
|
||||||
?assert(length(AppleUnfilteredMessages) < WaveCount * 3),
|
?assert(length(AppleUnfilteredMessages) < WaveCount * 3),
|
||||||
|
%% client-side filtering
|
||||||
AppleUnfilteredFilteredMessages =
|
AppleUnfilteredFilteredMessages =
|
||||||
lists:filter(fun(H) ->
|
lists:filter(fun(H) ->
|
||||||
proplists:get_value("x-stream-filter-value", H) =:= "apple" orelse
|
proplists:get_value("x-stream-filter-value", H) =:= "apple" orelse
|
||||||
proplists:get_value("x-stream-filter-value", H) =:= undefined
|
proplists:get_value("x-stream-filter-value", H) =:= undefined
|
||||||
end, AppleUnfilteredMessages),
|
end, AppleUnfilteredMessages),
|
||||||
|
%% we should have only the "apple" messages and messages without a filter value
|
||||||
?assert(length(AppleUnfilteredFilteredMessages) =:= WaveCount * 2),
|
?assert(length(AppleUnfilteredFilteredMessages) =:= WaveCount * 2),
|
||||||
rabbit_stomp_client:send(
|
rabbit_stomp_client:send(
|
||||||
Client10, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
Client10, "UNSUBSCRIBE", [{"destination", StreamDestination},
|
||||||
|
|
Loading…
Reference in New Issue