@@ -947,6 +947,32 @@ mod tests {
947947 assert ! ( !window_compatible( & config, 600_000 ) ) ;
948948 }
949949
950+ #[ test]
951+ fn sliding_window_compatibility_boundary_matrix ( ) {
952+ let mut config = make_config ( 1 , "req" , "Sum" , "" , 5_000 , "sliding" , & [ ] , "" ) ;
953+ config. slide_interval_ms = 1_000 ;
954+ assert ! ( window_compatible( & config, 5_000 ) ) ;
955+ assert ! ( window_compatible( & config, 10_000 ) ) ;
956+ assert ! ( !window_compatible( & config, 6_000 ) ) ;
957+
958+ config. slide_interval_ms = 2_000 ;
959+ assert ! ( !window_compatible( & config, 10_000 ) ) ;
960+
961+ config. window_size_ms = 1_000 ;
962+ config. slide_interval_ms = 5_000 ;
963+ assert ! ( !window_compatible( & config, 1_000 ) ) ;
964+ }
965+
966+ #[ test]
967+ fn sliding_window_compatibility_rejects_zero_fields ( ) {
968+ let mut config = make_config ( 1 , "req" , "Sum" , "" , 5_000 , "sliding" , & [ ] , "" ) ;
969+ config. slide_interval_ms = 0 ;
970+ assert ! ( !window_compatible( & config, 5_000 ) ) ;
971+ config. slide_interval_ms = 1_000 ;
972+ config. window_size_ms = 0 ;
973+ assert ! ( !window_compatible( & config, 5_000 ) ) ;
974+ }
975+
950976 #[ test]
951977 fn window_compatible_still_accepts_tumbling_delta_set_aggregator ( ) {
952978 let config = make_config (
@@ -1101,6 +1127,85 @@ mod tests {
11011127 . is_none( ) ) ;
11021128 }
11031129
1130+ #[ test]
1131+ fn tumbling_set_pairing_normalizes_zero_slide_to_window_size ( ) {
1132+ let mut value = make_config ( 10 , "req" , "CountMinSketch" , "" , 5_000 , "tumbling" , & [ ] , "" ) ;
1133+ let mut key = make_config ( 11 , "req" , "SetAggregator" , "" , 5_000 , "tumbling" , & [ ] , "" ) ;
1134+ value. slide_interval_ms = 0 ;
1135+ key. slide_interval_ms = 0 ;
1136+ assert ! ( key_agg_compatible_with_value( & value, & key) ) ;
1137+ key. slide_interval_ms = 5_000 ;
1138+ assert ! ( key_agg_compatible_with_value( & value, & key) ) ;
1139+ }
1140+
1141+ #[ test]
1142+ fn set_pairing_rejects_each_grid_mismatch_dimension ( ) {
1143+ let value = make_config ( 10 , "req" , "CountMinSketch" , "" , 5_000 , "sliding" , & [ ] , "" ) ;
1144+ let mut key = make_config ( 11 , "req" , "SetAggregator" , "" , 5_000 , "sliding" , & [ ] , "" ) ;
1145+ key. slide_interval_ms = 1_000 ;
1146+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1147+ key. slide_interval_ms = 5_000 ;
1148+ key. window_size_ms = 10_000 ;
1149+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1150+ key. window_size_ms = 5_000 ;
1151+ key. window_type = WindowType :: Tumbling ;
1152+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1153+ }
1154+
1155+ #[ test]
1156+ fn delta_set_pairing_truth_table_checks_both_divisors ( ) {
1157+ let mut value = make_config ( 10 , "req" , "CountMinSketch" , "" , 6_000 , "sliding" , & [ ] , "" ) ;
1158+ value. slide_interval_ms = 2_000 ;
1159+ let mut key = make_config (
1160+ 11 ,
1161+ "req" ,
1162+ "DeltaSetAggregator" ,
1163+ "" ,
1164+ 2_000 ,
1165+ "tumbling" ,
1166+ & [ ] ,
1167+ "" ,
1168+ ) ;
1169+ assert ! ( key_agg_compatible_with_value( & value, & key) ) ;
1170+ key. window_size_ms = 3_000 ;
1171+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1172+ key. window_size_ms = 4_000 ;
1173+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1174+ value. slide_interval_ms = 3_000 ;
1175+ key. window_size_ms = 2_000 ;
1176+ assert ! ( !key_agg_compatible_with_value( & value, & key) ) ;
1177+ }
1178+
1179+ #[ test]
1180+ fn delta_set_pairing_for_tumbling_values_does_not_apply_sliding_rules ( ) {
1181+ let value = make_config ( 10 , "req" , "CountMinSketch" , "" , 6_000 , "tumbling" , & [ ] , "" ) ;
1182+ let key = make_config (
1183+ 11 ,
1184+ "req" ,
1185+ "DeltaSetAggregator" ,
1186+ "" ,
1187+ 1_000 ,
1188+ "tumbling" ,
1189+ & [ ] ,
1190+ "" ,
1191+ ) ;
1192+ assert ! ( key_agg_compatible_with_value( & value, & key) ) ;
1193+ }
1194+
1195+ #[ test]
1196+ fn matching_skips_incompatible_key_candidate_and_selects_compatible_one ( ) {
1197+ let value = make_config ( 10 , "req" , "CountMinSketch" , "" , 6_000 , "sliding" , & [ ] , "" ) ;
1198+ let mut incompatible =
1199+ make_config ( 11 , "req" , "SetAggregator" , "" , 6_000 , "sliding" , & [ ] , "" ) ;
1200+ incompatible. slide_interval_ms = 2_000 ;
1201+ let compatible = make_config ( 12 , "req" , "SetAggregator" , "" , 6_000 , "sliding" , & [ ] , "" ) ;
1202+ let configs = HashMap :: from ( [ ( 10 , value) , ( 11 , incompatible) , ( 12 , compatible) ] ) ;
1203+ let result =
1204+ find_compatible_aggregation ( & configs, & req ( "req" , & [ Statistic :: Count ] , 6_000 , & [ ] , "" ) )
1205+ . expect ( "the compatible key candidate should be selected" ) ;
1206+ assert_eq ! ( result. aggregation_id_for_key, 12 ) ;
1207+ }
1208+
11041209 // --- avg (Vec<Statistic>) ---
11051210
11061211 #[ test]
0 commit comments