kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [kafka] Diff for: [GitHub] cmccabe merged pull request #6123: MINOR: Update Trogdor StringExpander regex to handle epilogue
Date Tue, 15 Jan 2019 04:49:26 GMT
diff --git a/tools/src/main/java/org/apache/kafka/trogdor/common/StringExpander.java b/tools/src/main/java/org/apache/kafka/trogdor/common/StringExpander.java
index 82f5003fbb6..3082a171a7f 100644
--- a/tools/src/main/java/org/apache/kafka/trogdor/common/StringExpander.java
+++ b/tools/src/main/java/org/apache/kafka/trogdor/common/StringExpander.java
@@ -29,7 +29,7 @@
  */
 public class StringExpander {
     private final static Pattern NUMERIC_RANGE_PATTERN =
-        Pattern.compile("(.*?)\\[([0-9]*)\\-([0-9]*)\\](.*?)");
+        Pattern.compile("(.*)\\[([0-9]*)\\-([0-9]*)\\](.*)");
 
     public static HashSet<String> expand(String val) {
         HashSet<String> set = new HashSet<>();
diff --git a/tools/src/test/java/org/apache/kafka/trogdor/common/StringExpanderTest.java b/tools/src/test/java/org/apache/kafka/trogdor/common/StringExpanderTest.java
index 72e1c202bd8..6fbb3473a10 100644
--- a/tools/src/test/java/org/apache/kafka/trogdor/common/StringExpanderTest.java
+++ b/tools/src/test/java/org/apache/kafka/trogdor/common/StringExpanderTest.java
@@ -58,5 +58,20 @@ public void testExpansions() throws Exception {
             "[[ wow52 ]]"
         ));
         assertEquals(expected3, StringExpander.expand("[[ wow[50-52] ]]"));
+
+        HashSet<String> expected4 = new HashSet<>(Arrays.asList(
+            "foo1bar",
+            "foo2bar",
+            "foo3bar"
+        ));
+        assertEquals(expected4, StringExpander.expand("foo[1-3]bar"));
+
+        // should expand latest range first
+        HashSet<String> expected5 = new HashSet<>(Arrays.asList(
+            "start[1-3]middle1epilogue",
+            "start[1-3]middle2epilogue",
+            "start[1-3]middle3epilogue"
+        ));
+        assertEquals(expected5, StringExpander.expand("start[1-3]middle[1-3]epilogue"));
     }
 }


With regards,
Apache Git Services

Mime
View raw message