22
33import org .junit .Test ;
44
5- import java .io .IOException ;
65import java .util .Arrays ;
76import java .util .Collections ;
87
@@ -16,7 +15,7 @@ public class MarathonConstraintParserTest {
1615 static final String POD_NAME = "hello" ;
1716
1817 @ Test
19- public void testSplitConstraints () throws IOException {
18+ public void testSplitConstraints () {
2019 assertEquals (Arrays .asList (Arrays .asList ("" )),
2120 MarathonConstraintParser .splitConstraints ("" ));
2221 assertEquals (Arrays .asList (Arrays .asList ("a" )),
@@ -41,7 +40,7 @@ public void testSplitConstraints() throws IOException {
4140 }
4241
4342 @ Test
44- public void testUniqueOperator () throws IOException {
43+ public void testUniqueOperator () {
4544 // example from marathon documentation:
4645 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['hostname', 'UNIQUE']]" )).toString ();
4746 assertEquals ("MaxPerHostnameRule{max=1, task-filter=RegexMatcher{pattern='hello-.*'}}" , constraintStr );
@@ -56,7 +55,7 @@ public void testUniqueOperator() throws IOException {
5655 }
5756
5857 @ Test
59- public void testClusterOperator () throws IOException {
58+ public void testClusterOperator () {
6059 // example from marathon documentation:
6160 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['rack-id', 'CLUSTER', 'rack-1']]" )).toString ();
6261 assertEquals ("AttributeRule{matcher=ExactMatcher{str='rack-id:rack-1'}}" , constraintStr );
@@ -71,7 +70,7 @@ public void testClusterOperator() throws IOException {
7170 }
7271
7372 @ Test
74- public void testGroupByOperator () throws IOException {
73+ public void testGroupByOperator () {
7574 // example from marathon documentation:
7675 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['rack-id', 'GROUP_BY']]" )).toString ();
7776 assertEquals ("RoundRobinByAttributeRule{attribute=rack-id, attribute-count=Optional.empty, task-filter=RegexMatcher{pattern='hello-.*'}}" , constraintStr );
@@ -101,7 +100,7 @@ public void testGroupByOperator() throws IOException {
101100 }
102101
103102 @ Test
104- public void testLikeOperator () throws IOException {
103+ public void testLikeOperator () {
105104 // example from marathon documentation:
106105 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['rack-id', 'LIKE', 'rack-[1-3]']]" )).toString ();
107106 assertEquals ("AttributeRule{matcher=RegexMatcher{pattern='rack-id:rack-[1-3]'}}" , constraintStr );
@@ -115,7 +114,7 @@ public void testLikeOperator() throws IOException {
115114 }
116115
117116 @ Test
118- public void testIsOperator () throws IOException {
117+ public void testIsOperator () {
119118 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['foo', 'IS', 'bar']]" )).toString ();
120119 assertEquals ("AttributeRule{matcher=ExactMatcher{str='foo:bar'}}" , constraintStr );
121120 assertEquals (constraintStr , MarathonConstraintParser .parse (POD_NAME , unescape ("['foo', 'IS', 'bar']" )).toString ());
@@ -138,7 +137,7 @@ public void testIsOperator() throws IOException {
138137 }
139138
140139 @ Test
141- public void testUnlikeOperator () throws IOException {
140+ public void testUnlikeOperator () {
142141 // example from marathon documentation:
143142 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['rack-id', 'UNLIKE', 'rack-[7-9]']]" )).toString ();
144143 assertEquals ("NotRule{rule=AttributeRule{matcher=RegexMatcher{pattern='rack-id:rack-[7-9]'}}}" , constraintStr );
@@ -152,7 +151,7 @@ public void testUnlikeOperator() throws IOException {
152151 }
153152
154153 @ Test
155- public void testMaxPerOperator () throws IOException {
154+ public void testMaxPerOperator () {
156155 // example from marathon documentation:
157156 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape ("[['rack-id', 'MAX_PER', '2']]" )).toString ();
158157 assertEquals ("AndRule{rules=[AttributeRule{matcher=RegexMatcher{pattern='rack-id:.*'}}, " +
@@ -167,7 +166,7 @@ public void testMaxPerOperator() throws IOException {
167166 }
168167
169168 @ Test
170- public void testManyOperators () throws IOException {
169+ public void testManyOperators () {
171170 String constraintStr = MarathonConstraintParser .parse (POD_NAME , unescape (
172171 "[['hostname', 'UNIQUE'], "
173172 + "['rack-id', 'CLUSTER', 'rack-1'], "
@@ -194,79 +193,90 @@ public void testManyOperators() throws IOException {
194193 }
195194
196195 @ Test
197- public void testEscapedCommaRegex () throws IOException {
196+ public void testEscapedCommaRegex () {
198197 assertEquals ("AttributeRule{matcher=RegexMatcher{pattern='rack-id:rack-{1,3}'}}" ,
199198 MarathonConstraintParser .parse (POD_NAME , "rack-id:LIKE:rack-{1\\ ,3}" ).toString ());
200199 }
201200
202201 @ Test
203- public void testEscapedColonRegex () throws IOException {
202+ public void testEscapedColonRegex () {
204203 assertEquals ("AttributeRule{matcher=RegexMatcher{pattern='rack-id:foo:bar:baz'}}" ,
205204 MarathonConstraintParser .parse (POD_NAME , "rack-id:LIKE:foo\\ :bar\\ :baz" ).toString ());
206205 }
207206
208207 @ Test
209- public void testEmptyConstraint () throws IOException {
208+ public void testEmptyConstraint () {
210209 assertEquals ("PassthroughRule{}" , MarathonConstraintParser .parse (POD_NAME , "" ).toString ());
211210 }
212211
213212 @ Test
214- public void testEmptyArrayConstraint () throws IOException {
213+ public void testEmptyArrayConstraint () {
215214 assertEquals ("PassthroughRule{}" , MarathonConstraintParser .parse (POD_NAME , "[]" ).toString ());
216215 }
217216
218217 @ Test
219- public void testOverEscapedConstraintIsInvalid () throws IOException {
218+ public void testOverEscapedConstraintIsInvalid () {
220219 assertTrue ("too many \\ 's" , isInvalidConstraints ("[[\\ \" hostname\\ \" ,\\ \" MAX_PER\\ \" ,\\ \" 1\\ \" ]]" ));
221220 }
222221
223222 @ Test
224- public void testBadListConstraint () throws IOException {
223+ public void testBadListConstraint () {
225224 assertTrue ("missing ']]'" , isInvalidConstraints (unescape ("[['rack-id', 'MAX_PER', '2'" )));
226225 }
227226
228227 @ Test
229- public void testBadFlatConstraint () throws IOException {
228+ public void testBadFlatConstraint () {
230229 assertTrue ("Missing last element" , isInvalidConstraints ("rack-id:MAX_PER:," ));
231230 }
232231
233232 @ Test
234- public void testBadParamGroupBy () throws IOException {
233+ public void testBadParamGroupBy () {
235234 assertTrue ("Expected integer" , isInvalidConstraints ("rack-id:GROUP_BY:foo" ));
236235 }
237236
238237 @ Test
239- public void testBadParamMaxPer () throws IOException {
238+ public void testBadParamMaxPer () {
240239 assertTrue ("Expected integer" , isInvalidConstraints ("rack-id:MAX_PER:foo" ));
241240 }
242241
243242 @ Test
244- public void testMissingParamCluster () throws IOException {
243+ public void testExtraTokens () {
244+ for (String constraint : Arrays .asList (
245+ unescape ("['hostname','UNIQUE'],[['hostname','LIKE','10.0.3.6']" ),
246+ unescape ("['hostname','UNIQUE'],[" ),
247+ unescape ("[['hostname','UNIQUE'],['hostname','LIKE','10.0.3.6']" ),
248+ unescape ("[['hostname','UNIQUE']]," ))) {
249+ assertTrue ("Trailing tokens" , isInvalidConstraints (constraint ));
250+ }
251+ }
252+
253+ @ Test
254+ public void testMissingParamCluster () {
245255 assertTrue ("Expected parameter" , isInvalidConstraints ("rack-id:CLUSTER" ));
246256 }
247257
248258 @ Test
249- public void testMissingParamLike () throws IOException {
259+ public void testMissingParamLike () {
250260 assertTrue ("Expected parameter" , isInvalidConstraints ("rack-id:LIKE" ));
251261 }
252262
253263 @ Test
254- public void testMissingParamUnlike () throws IOException {
264+ public void testMissingParamUnlike () {
255265 assertTrue ("Expected parameter" , isInvalidConstraints ("rack-id:UNLIKE" ));
256266 }
257267
258268 @ Test
259- public void testMissingParamMaxPer () throws IOException {
269+ public void testMissingParamMaxPer () {
260270 assertTrue ("Expected parameter" , isInvalidConstraints ("rack-id:MAX_PER" ));
261271 }
262272
263273 @ Test
264- public void testUnknownCommand () throws IOException {
274+ public void testUnknownCommand () {
265275 assertTrue (isInvalidConstraints ("rack-id:FOO:foo" ));
266276 }
267277
268278 @ Test
269- public void testTooManyElemenents () throws IOException {
279+ public void testTooManyElemenents () {
270280 assertTrue (isInvalidConstraints ("rack-id:LIKE:foo:bar" ));
271281 }
272282
@@ -310,7 +320,7 @@ private static String unescape(String s) {
310320 return s .replace ('\'' , '"' );
311321 }
312322
313- private boolean isInvalidConstraints (String constraints ) throws IOException {
323+ private boolean isInvalidConstraints (String constraints ) {
314324 return MarathonConstraintParser .parse (POD_NAME , constraints ) instanceof InvalidPlacementRule ;
315325 }
316326}
0 commit comments