kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject [kafka] branch trunk updated: MINOR: Update Trogdor StringExpander regex to handle an epilogue (#6123)
Date Tue, 15 Jan 2019 04:49:34 GMT
This is an automated email from the ASF dual-hosted git repository.

cmccabe pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 13f6790  MINOR: Update Trogdor StringExpander regex to handle an epilogue (#6123)
13f6790 is described below

commit 13f679013aaa93198d30df8dada4aba5614790ea
Author: Stanislav Kozlovski <stanislav_kozlovski@outlook.com>
AuthorDate: Tue Jan 15 06:49:24 2019 +0200

    MINOR: Update Trogdor StringExpander regex to handle an epilogue (#6123)
    
    Update the Trogdor StringExpander regex to handle an epilogue.  Previously the regex would
use a lazy quantifier at the end, which meant it would not catch anything after the range
expression.  Add a unit test.
    
    Reviewed-by: Colin P. McCabe <cmccabe@apache.org>
---
 .../org/apache/kafka/trogdor/common/StringExpander.java   |  2 +-
 .../apache/kafka/trogdor/common/StringExpanderTest.java   | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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 82f5003..3082a17 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 @@ import java.util.regex.Pattern;
  */
 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 72e1c20..6fbb347 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 class StringExpanderTest {
             "[[ 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"));
     }
 }


Mime
View raw message