You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/05/30 08:08:49 UTC

[GitHub] liubao68 closed pull request #733: [SCB-611]Provide URLMappedEdgeDispatcher to using edge service easier

liubao68 closed pull request #733: [SCB-611]Provide URLMappedEdgeDispatcher to using edge service easier
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/733
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
index 9a91656de..699957768 100644
--- a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
+++ b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
@@ -29,6 +29,9 @@ public static void main(String[] args) throws Exception {
     new Consumer().run("api");
     System.out.println("Running rest dispater.");
     new Consumer().run("rest");
+    System.out.println("Running url dispater.");
+    new Consumer().run("url");
 
+    System.out.println("All test case finished.");
   }
 }
diff --git a/demo/demo-edge/edge-service/src/main/resources/config/log4j.properties b/demo/demo-edge/edge-service/src/main/resources/config/log4j.properties
index 3fc9f8bd2..efd6a27d9 100644
--- a/demo/demo-edge/edge-service/src/main/resources/config/log4j.properties
+++ b/demo/demo-edge/edge-service/src/main/resources/config/log4j.properties
@@ -16,3 +16,4 @@
 #
 
 log4j.rootLogger=INFO,stdout
+log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss,SSS/zzz}][%t][%p]%m %l%n
\ No newline at end of file
diff --git a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
index 27b17dbb2..7bfa1b94c 100644
--- a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
+++ b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
@@ -44,4 +44,17 @@ servicecomb:
           enabled: true
           prefix: rest
           withVersion: true
-          pathIndex: 2
+          prefixSegmentCount: 1
+        url:
+          enabled: true
+          mappings:
+            businessV1:
+              prefixSegmentCount: 1
+              path: "/url/business/v1/.*"
+              microserviceName: business
+              versionRule: 1.0.0-2.0.0
+            businessV2:
+              prefixSegmentCount: 1
+              path: "/url/business/v2/.*"
+              microserviceName: business
+              versionRule: 2.0.0-3.0.0
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
index 3070240e6..20ecb21cc 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
@@ -26,7 +26,7 @@
 import io.vertx.ext.web.handler.CookieHandler;
 
 /**
- * Provide an easy mapping dispatcher. User can configure prefix to easily using edge service.
+ * Provide an easy mapping dispatcher that starts with a common prefix pattern.
  */
 public class DefaultEdgeDispatcher extends AbstractEdgeDispatcher {
   private static final String KEY_ENABLED = "servicecomb.http.dispatcher.edge.default.enabled";
@@ -35,7 +35,7 @@
 
   private static final String KEY_WITH_VERSION = "servicecomb.http.dispatcher.edge.default.withVersion";
 
-  private static final String KEY_PATH_INDEX = "servicecomb.http.dispatcher.edge.default.pathIndex";
+  private static final String KEY_PREFIX_SEGMENT_COUNT = "servicecomb.http.dispatcher.edge.default.prefixSegmentCount";
 
   private CompatiblePathVersionMapper versionMapper = new CompatiblePathVersionMapper();
 
@@ -43,7 +43,7 @@
 
   private boolean withVersion;
 
-  private int pathIndex;
+  private int prefixSegmentCount;
 
   @Override
   public int getOrder() {
@@ -59,7 +59,7 @@ public boolean enabled() {
   public void init(Router router) {
     prefix = DynamicPropertyFactory.getInstance().getStringProperty(KEY_PREFIX, "api").get();
     withVersion = DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_WITH_VERSION, true).get();
-    pathIndex = DynamicPropertyFactory.getInstance().getIntProperty(KEY_PATH_INDEX, 2).get();
+    prefixSegmentCount = DynamicPropertyFactory.getInstance().getIntProperty(KEY_PREFIX_SEGMENT_COUNT, 1).get();
     String regex;
     if (withVersion) {
       regex = "/" + prefix + "/([^\\\\/]+)/([^\\\\/]+)/(.*)";
@@ -74,7 +74,7 @@ public void init(Router router) {
   protected void onRequest(RoutingContext context) {
     Map<String, String> pathParams = context.pathParams();
     String microserviceName = pathParams.get("param0");
-    String path = findActualPath(context.request().path());
+    String path = Utils.findActualPath(context.request().path(), prefixSegmentCount);
 
     EdgeInvocation edgeInvocation = new EdgeInvocation();
     if (withVersion) {
@@ -84,19 +84,4 @@ protected void onRequest(RoutingContext context) {
     edgeInvocation.init(microserviceName, context, path, httpServerFilters);
     edgeInvocation.edgeInvoke();
   }
-
-  protected String findActualPath(String path) {
-    int fromIndex = 0;
-    int counter = pathIndex;
-    char[] chars = path.toCharArray();
-    for (int i = 0; i < chars.length; i++) {
-      if (chars[i] == '/') {
-        if (--counter <= 0) {
-          fromIndex = i;
-          break;
-        }
-      }
-    }
-    return path.substring(fromIndex > 0 ? fromIndex : 0);
-  }
 }
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
new file mode 100644
index 000000000..f8c169501
--- /dev/null
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.edge.core;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.netflix.config.ConcurrentCompositeConfiguration;
+import com.netflix.config.DynamicPropertyFactory;
+
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.RoutingContext;
+import io.vertx.ext.web.handler.CookieHandler;
+
+/**
+ * Provide a URL mapping based dispatcher. Users configure witch URL patterns dispatch to a target service.
+ */
+public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
+  class ConfigurationItem {
+    String microserviceName;
+
+    String versionRule;
+
+    int prefixSegmentCount;
+
+    Pattern pattern;
+
+    String stringPattern;
+  }
+
+  private static final Logger LOG = LoggerFactory.getLogger(URLMappedEdgeDispatcher.class);
+
+  private static final String PATTERN_ANY = "/(.*)";
+
+  private static final String KEY_ENABLED = "servicecomb.http.dispatcher.edge.url.enabled";
+
+  private static final String KEY_MAPPING_PREIX = "servicecomb.http.dispatcher.edge.url.mappings";
+
+  private static final String KEY_MAPPING_PATH = ".path";
+
+  private static final String KEY_MAPPING_SERVICE_NAME = "servicecomb.http.dispatcher.edge.url.mappings.%s.microserviceName";
+
+  private static final String KEY_MAPPING_VERSION_RULE = "servicecomb.http.dispatcher.edge.url.mappings.%s.versionRule";
+
+  private static final String KEY_MAPPING_PREFIX_SEGMENT_COUNT = "servicecomb.http.dispatcher.edge.url.mappings.%s.prefixSegmentCount";
+
+  private Map<String, ConfigurationItem> configurations = new HashMap<>();
+
+  public URLMappedEdgeDispatcher() {
+    if(this.enabled()) {
+      loadConfigurations();
+    }
+  }
+
+  @Override
+  public int getOrder() {
+    return 30000;
+  }
+
+  @Override
+  public boolean enabled() {
+    return DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
+  }
+
+  @Override
+  public void init(Router router) {
+    router.routeWithRegex(PATTERN_ANY).handler(CookieHandler.create());
+    router.routeWithRegex(PATTERN_ANY).handler(createBodyHandler());
+    router.routeWithRegex(PATTERN_ANY).failureHandler(this::onFailure).handler(this::onRequest);
+  }
+
+  private void loadConfigurations() {
+    ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
+        .getBackingConfigurationSource();
+    loadConfigurations(config);
+    config.addConfigurationListener(event -> {
+      if (event.getPropertyName().startsWith(KEY_MAPPING_PREIX)) {
+        LOG.info("Map rule have been changed. Reload configurations. Event=" + event.getType());
+        loadConfigurations(config);
+      }
+    });
+  }
+
+  private void loadConfigurations(ConcurrentCompositeConfiguration config) {
+    Map<String, ConfigurationItem> configurations = new HashMap<>();
+    Iterator<String> configsItems = config.getKeys(KEY_MAPPING_PREIX);
+    while (configsItems.hasNext()) {
+      String pathKey = configsItems.next();
+      if (pathKey.endsWith(KEY_MAPPING_PATH)) {
+        ConfigurationItem configurationItem = new ConfigurationItem();
+        String pattern = DynamicPropertyFactory.getInstance()
+            .getStringProperty(pathKey, null).get();
+        if (StringUtils.isEmpty(pattern)) {
+          continue;
+        }
+        configurationItem.pattern = Pattern.compile(pattern);
+        configurationItem.stringPattern = pattern;
+        String pathKeyItem = pathKey
+            .substring(KEY_MAPPING_PREIX.length() + 1, pathKey.length() - KEY_MAPPING_PATH.length());
+        configurationItem.microserviceName = DynamicPropertyFactory.getInstance()
+            .getStringProperty(String.format(KEY_MAPPING_SERVICE_NAME, pathKeyItem), null).get();
+        if (StringUtils.isEmpty(configurationItem.microserviceName)) {
+          continue;
+        }
+        configurationItem.prefixSegmentCount = DynamicPropertyFactory.getInstance()
+            .getIntProperty(String.format(KEY_MAPPING_PREFIX_SEGMENT_COUNT, pathKeyItem), 0).get();
+        configurationItem.versionRule = DynamicPropertyFactory.getInstance()
+            .getStringProperty(String.format(KEY_MAPPING_VERSION_RULE, pathKeyItem), "0.0.0+").get();
+        configurations.put(pathKeyItem, configurationItem);
+      }
+    }
+    this.configurations = configurations;
+    logConfigurations();
+  }
+
+  private void logConfigurations() {
+    for (String key : this.configurations.keySet()) {
+      ConfigurationItem item = this.configurations.get(key);
+      LOG.info("config item: key=" + key + ";pattern=" + item.stringPattern + ";service=" + item.microserviceName
+          + ";versionRule=" + item.versionRule);
+    }
+  }
+
+  protected void onRequest(RoutingContext context) {
+    ConfigurationItem configurationItem = findConfigurationItem(context.request().path());
+    if (configurationItem == null) {
+      context.next();
+      return;
+    }
+
+    String path = Utils.findActualPath(context.request().path(), configurationItem.prefixSegmentCount);
+
+    EdgeInvocation edgeInvocation = new EdgeInvocation();
+    if (configurationItem.versionRule != null) {
+      edgeInvocation.setVersionRule(configurationItem.versionRule);
+    }
+    edgeInvocation.init(configurationItem.microserviceName, context, path, httpServerFilters);
+    edgeInvocation.edgeInvoke();
+  }
+
+  private ConfigurationItem findConfigurationItem(String path) {
+    for (ConfigurationItem item : configurations.values()) {
+      if (item.pattern.matcher(path).matches()) {
+        return item;
+      }
+    }
+    return null;
+  }
+}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/Utils.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/Utils.java
new file mode 100644
index 000000000..9bbefb9f0
--- /dev/null
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/Utils.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.edge.core;
+
+/**
+ * Commonly used methods in this package.
+ */
+public final class Utils {
+  private Utils() {
+
+  }
+
+  /**
+   * Get the actual path without prefix
+   * @param path full path
+   * @param pathIndex the index of / that after prefix
+   * @return actual path
+   */
+  public static String findActualPath(String path, int pathIndex) {
+    if (pathIndex <= 0) {
+      return path;
+    }
+
+    int fromIndex = 0;
+    int counter = pathIndex;
+    char[] chars = path.toCharArray();
+    for (int i = 0; i < chars.length; i++) {
+      if (chars[i] == '/') {
+        if (--counter < 0) {
+          fromIndex = i;
+          break;
+        }
+      }
+    }
+    return fromIndex > 0 ? path.substring(fromIndex) : "";
+  }
+}
diff --git a/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher b/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
index cc2856f7f..d81bb2257 100644
--- a/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
+++ b/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
@@ -15,4 +15,5 @@
 # limitations under the License.
 #
 
-org.apache.servicecomb.edge.core.DefaultEdgeDispatcher
\ No newline at end of file
+org.apache.servicecomb.edge.core.DefaultEdgeDispatcher
+org.apache.servicecomb.edge.core.URLMappedEdgeDispatcher
\ No newline at end of file
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestServiceAndVersionDispatcher.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestDefaultEdgeDispatcher.java
similarity index 95%
rename from edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestServiceAndVersionDispatcher.java
rename to edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestDefaultEdgeDispatcher.java
index 55efc1010..518740a82 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestServiceAndVersionDispatcher.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestDefaultEdgeDispatcher.java
@@ -35,7 +35,7 @@
 import mockit.Expectations;
 import mockit.Mocked;
 
-public class TestServiceAndVersionDispatcher {
+public class TestDefaultEdgeDispatcher {
   @Before
   public void setUp() {
 
@@ -79,7 +79,7 @@ public void testOnRequest(@Mocked Router router, @Mocked Route route
     };
     dispatcher.init(router);
     Assert.assertEquals(dispatcher.enabled(), false);
-    Assert.assertEquals(dispatcher.findActualPath("/api/test"), "/test");
+    Assert.assertEquals(Utils.findActualPath("/api/test", 1), "/test");
     Assert.assertEquals(dispatcher.getOrder(), 20000);
 
     dispatcher.onRequest(context);
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
new file mode 100644
index 000000000..3bbf5e6c3
--- /dev/null
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.edge.core;
+
+import java.util.Map;
+
+import org.apache.servicecomb.edge.core.URLMappedEdgeDispatcher.ConfigurationItem;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.ext.web.RoutingContext;
+import mockit.Deencapsulation;
+import mockit.Expectations;
+import mockit.Mocked;
+
+public class TestURLMappedEdgeDispatcher {
+  @Before
+  public void setUp() throws Exception {
+    Log4jUtils.init();
+  }
+
+  @After
+  public void tearDown() {
+    ArchaiusUtils.resetConfig();
+  }
+
+  @Test
+  @SuppressWarnings(value = "unchecked")
+  public void testConfigurations(@Mocked RoutingContext context
+      , @Mocked HttpServerRequest requst
+      , @Mocked EdgeInvocation invocation) {
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.enabled", true);
+
+    URLMappedEdgeDispatcher dispatcher = new URLMappedEdgeDispatcher();
+    Map<String, ConfigurationItem> items = Deencapsulation
+        .getField(dispatcher, "configurations");
+    Assert.assertEquals(items.size(), 0);
+
+    new Expectations() {
+      {
+        context.next();
+      }
+    };
+    dispatcher.onRequest(context);
+
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.path", "/a/b/c/.*");
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName", "serviceName");
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount", 2);
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule", "2.0.0+");
+    items = Deencapsulation.getField(dispatcher, "configurations");
+    Assert.assertEquals(items.size(), 1);
+    ConfigurationItem item = items.get("service1");
+    Assert.assertEquals(item.microserviceName, "serviceName");
+    Assert.assertEquals(item.prefixSegmentCount, 2);
+    Assert.assertEquals(item.stringPattern, "/a/b/c/.*");
+    Assert.assertEquals(item.versionRule, "2.0.0+");
+
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service2.versionRule", "2.0.0+");
+    ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service3.path", "/b/c/d/.*");
+    items = Deencapsulation.getField(dispatcher, "configurations");
+    Assert.assertEquals(items.size(), 1);
+    item = items.get("service1");
+    Assert.assertEquals(item.microserviceName, "serviceName");
+    Assert.assertEquals(item.prefixSegmentCount, 2);
+    Assert.assertEquals(item.stringPattern, "/a/b/c/.*");
+    Assert.assertEquals(item.versionRule, "2.0.0+");
+
+    new Expectations() {
+      {
+        context.request();
+        result = requst;
+        requst.path();
+        result = "/a/b/c/d/e";
+        invocation.setVersionRule("2.0.0+");
+        invocation.init("serviceName", context, "/c/d/e",
+            Deencapsulation.getField(dispatcher, "httpServerFilters"));
+        invocation.edgeInvoke();
+      }
+    };
+    dispatcher.onRequest(context);
+  }
+}
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestUtils.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestUtils.java
new file mode 100644
index 000000000..c92373fb3
--- /dev/null
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestUtils.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.edge.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUtils {
+  @Test
+  public void testUtisl() {
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", -1), "/a/b/c");
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", 0), "/a/b/c");
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", 1), "/b/c");
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", 2), "/c");
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", 3), "");
+    Assert.assertEquals(Utils.findActualPath("/a/b/c", 100), "");
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services