66-include_lib (" eunit/include/eunit.hrl" ).
77-include_lib (" rabbit_common/include/rabbit.hrl" ).
88
9+ -import (rabbit_stream_utils ,
10+ [validate_super_stream_max_partitions /2 ]).
11+
912% %%===================================================================
1013% %% Common Test callbacks
1114% %%===================================================================
@@ -17,7 +20,12 @@ suite() ->
1720 [{timetrap , {seconds , 30 }}].
1821
1922groups () ->
20- [{tests , [], [sort_partitions , filter_spec , filter_defined ]}].
23+ [{tests , [],
24+ [sort_partitions ,
25+ filter_spec ,
26+ filter_defined ,
27+ test_validate_max_super_stream_partitions ,
28+ super_stream_partition_helpers ]}].
2129
2230init_per_suite (Config ) ->
2331 Config .
@@ -94,6 +102,66 @@ filter_spec(_) ->
94102 #{} = rabbit_stream_utils :filter_spec (#{<<" sac" >> => true }),
95103 ok .
96104
105+ test_validate_max_super_stream_partitions (_ ) ->
106+ % % infinity means no limit applies
107+ ? assertEqual (true , validate_super_stream_max_partitions ([], infinity )),
108+ ? assertEqual (true , validate_super_stream_max_partitions ([a , b , c ], infinity )),
109+ ? assertEqual (true , validate_super_stream_max_partitions (0 , infinity )),
110+ ? assertEqual (true , validate_super_stream_max_partitions (1000 , infinity )),
111+ % % max = 0: only an empty list and integer 0 are valid
112+ ? assertEqual (true , validate_super_stream_max_partitions ([], 0 )),
113+ ? assertEqual (false , validate_super_stream_max_partitions ([a ], 0 )),
114+ ? assertEqual (true , validate_super_stream_max_partitions (0 , 0 )),
115+ ? assertEqual (false , validate_super_stream_max_partitions (1 , 0 )),
116+ % % exactly at the limit is valid
117+ ? assertEqual (true , validate_super_stream_max_partitions ([a , b , c ], 3 )),
118+ ? assertEqual (true , validate_super_stream_max_partitions (3 , 3 )),
119+ % % one over the limit is invalid
120+ ? assertEqual (false , validate_super_stream_max_partitions ([a , b , c , d ], 3 )),
121+ ? assertEqual (false , validate_super_stream_max_partitions (4 , 3 )),
122+ ok .
123+
124+ super_stream_partition_helpers (_ ) ->
125+ % % streams_from_partitions/2
126+ ? assertEqual ([],
127+ rabbit_stream_utils :streams_from_partitions (<<" invoices" >>, 0 )),
128+ ? assertEqual ([<<" invoices-0" >>],
129+ rabbit_stream_utils :streams_from_partitions (<<" invoices" >>, 1 )),
130+ ? assertEqual ([<<" invoices-0" >>, <<" invoices-1" >>, <<" invoices-2" >>],
131+ rabbit_stream_utils :streams_from_partitions (<<" invoices" >>, 3 )),
132+
133+ % % streams_from_binding_keys/2
134+ ? assertEqual ([],
135+ rabbit_stream_utils :streams_from_binding_keys (<<" invoices" >>, [])),
136+ ? assertEqual ([<<" invoices-amer" >>],
137+ rabbit_stream_utils :streams_from_binding_keys (<<" invoices" >>,
138+ [<<" amer" >>])),
139+ ? assertEqual ([<<" invoices-amer" >>, <<" invoices-emea" >>, <<" invoices-apac" >>],
140+ rabbit_stream_utils :streams_from_binding_keys (<<" invoices" >>,
141+ [<<" amer" >>,
142+ <<" emea" >>,
143+ <<" apac" >>])),
144+
145+ % % routing_keys/1
146+ ? assertEqual ([], rabbit_stream_utils :routing_keys (0 )),
147+ ? assertEqual ([<<" 0" >>], rabbit_stream_utils :routing_keys (1 )),
148+ ? assertEqual ([<<" 0" >>, <<" 1" >>, <<" 2" >>],
149+ rabbit_stream_utils :routing_keys (3 )),
150+
151+ % % binding_keys/1
152+ ? assertEqual ([<<" amer" >>],
153+ rabbit_stream_utils :binding_keys (<<" amer" >>)),
154+ ? assertEqual ([<<" amer" >>, <<" emea" >>, <<" apac" >>],
155+ rabbit_stream_utils :binding_keys (<<" amer,emea,apac" >>)),
156+ ? assertEqual ([<<" amer" >>, <<" emea" >>, <<" apac" >>],
157+ rabbit_stream_utils :binding_keys (<<" amer, emea, apac" >>)),
158+ ? assertEqual ([],
159+ rabbit_stream_utils :binding_keys (<<" " >>)),
160+ ? assertEqual ([],
161+ rabbit_stream_utils :binding_keys (<<" " >>)),
162+
163+ ok .
164+
97165binding (Destination , Order ) ->
98166 # binding {destination = # resource {name = Destination },
99167 args = [{<<" x-stream-partition-order" >>, signedint , Order }]}.
0 commit comments