1717
1818package com .hivemq .client .internal .mqtt .handler .publish .incoming ;
1919
20+ import com .hivemq .client .internal .mqtt .datatypes .MqttTopicFilterImpl ;
21+ import com .hivemq .client .internal .mqtt .datatypes .MqttTopicImpl ;
22+ import org .jetbrains .annotations .NotNull ;
23+ import org .junit .jupiter .params .ParameterizedTest ;
24+ import org .junit .jupiter .params .provider .CsvSource ;
25+
26+ import static org .junit .jupiter .api .Assertions .*;
27+
2028/**
2129 * @author Silvio Giebl
2230 */
@@ -26,4 +34,65 @@ class MqttSubscriptionFlowTreeTest extends MqttSubscriptionFlowsTest {
2634 super (MqttSubscriptionFlowTree ::new );
2735 }
2836
37+ @ ParameterizedTest
38+ @ CsvSource ({
39+ "unsubscribe, test/topic1, test/topic2, test/topic3, test/topic1, test/topic2, test/topic3" ,
40+ "unsubscribe, test/+, test/topic2, test/topic3, test/topic1, test/topic2, test/topic3" ,
41+ "unsubscribe, test/topic/filter1, test/topic/filter2, test/topic/filter3, test/topic/filter1, test/topic/filter2, test/topic/filter3" ,
42+ "unsubscribe, test/topic/+, test/topic/filter2, test/topic/filter3, test/topic/filter1, test/topic/filter2, test/topic/filter3" ,
43+ "unsubscribe, test/topic1/filter, test/topic2/filter, test/topic3/filter, test/topic1/filter, test/topic2/filter, test/topic3/filter" ,
44+ "unsubscribe, test/+/filter, test/topic2/filter, test/topic3/filter, test/topic1/filter, test/topic2/filter, test/topic3/filter" ,
45+ "unsubscribe, test/topic/filter, test/topic//filter, test/topic///filter, test/topic/filter, test/topic//filter, test/topic///filter" ,
46+ "remove, test/topic1, test/topic2, test/topic3, test/topic1, test/topic2, test/topic3" ,
47+ "remove, test/+, test/topic2, test/topic3, test/topic1, test/topic2, test/topic3" ,
48+ "remove, test/topic/filter1, test/topic/filter2, test/topic/filter3, test/topic/filter1, test/topic/filter2, test/topic/filter3" ,
49+ "remove, test/topic/+, test/topic/filter2, test/topic/filter3, test/topic/filter1, test/topic/filter2, test/topic/filter3" ,
50+ "remove, test/topic1/filter, test/topic2/filter, test/topic3/filter, test/topic1/filter, test/topic2/filter, test/topic3/filter" ,
51+ "remove, test/+/filter, test/topic2/filter, test/topic3/filter, test/topic1/filter, test/topic2/filter, test/topic3/filter" ,
52+ "remove, test/topic/filter, test/topic//filter, test/topic///filter, test/topic/filter, test/topic//filter, test/topic///filter" ,
53+ })
54+ void branching_compaction (
55+ final @ NotNull String compactOperation , final @ NotNull String filter1 , final @ NotNull String filter2 ,
56+ final @ NotNull String filter3 , final @ NotNull String topic1 , final @ NotNull String topic2 ,
57+ final @ NotNull String topic3 ) {
58+
59+ flows .subscribe (MqttTopicFilterImpl .of (filter1 ), null );
60+ flows .subscribe (MqttTopicFilterImpl .of (filter2 ), null );
61+ flows .subscribe (MqttTopicFilterImpl .of (filter3 ), null );
62+
63+ final MqttMatchingPublishFlows matching1 = new MqttMatchingPublishFlows ();
64+ flows .findMatching (MqttTopicImpl .of (topic1 ), matching1 );
65+ assertTrue (matching1 .subscriptionFound );
66+ final MqttMatchingPublishFlows matching2 = new MqttMatchingPublishFlows ();
67+ flows .findMatching (MqttTopicImpl .of (topic2 ), matching2 );
68+ assertTrue (matching2 .subscriptionFound );
69+ final MqttMatchingPublishFlows matching3 = new MqttMatchingPublishFlows ();
70+ flows .findMatching (MqttTopicImpl .of (topic3 ), matching3 );
71+ assertTrue (matching3 .subscriptionFound );
72+
73+ switch (compactOperation ) {
74+ case "unsubscribe" :
75+ flows .unsubscribe (MqttTopicFilterImpl .of (filter1 ), null );
76+ flows .unsubscribe (MqttTopicFilterImpl .of (filter2 ), null );
77+ flows .unsubscribe (MqttTopicFilterImpl .of (filter3 ), null );
78+ break ;
79+ case "remove" :
80+ flows .remove (MqttTopicFilterImpl .of (filter1 ), null );
81+ flows .remove (MqttTopicFilterImpl .of (filter2 ), null );
82+ flows .remove (MqttTopicFilterImpl .of (filter3 ), null );
83+ break ;
84+ default :
85+ fail ();
86+ }
87+
88+ final MqttMatchingPublishFlows matching4 = new MqttMatchingPublishFlows ();
89+ flows .findMatching (MqttTopicImpl .of (topic1 ), matching4 );
90+ assertFalse (matching4 .subscriptionFound );
91+ final MqttMatchingPublishFlows matching5 = new MqttMatchingPublishFlows ();
92+ flows .findMatching (MqttTopicImpl .of (topic2 ), matching5 );
93+ assertFalse (matching5 .subscriptionFound );
94+ final MqttMatchingPublishFlows matching6 = new MqttMatchingPublishFlows ();
95+ flows .findMatching (MqttTopicImpl .of (topic3 ), matching6 );
96+ assertFalse (matching6 .subscriptionFound );
97+ }
2998}
0 commit comments