You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2019/02/27 02:19:56 UTC

[servicecomb-java-chassis] branch master updated: [SCB-1177] read vertx.disableFileCPResolving from dynamic config, default is false(don't create the .vertx directory) (#1110)

This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 161abb0  [SCB-1177] read vertx.disableFileCPResolving from dynamic config, default is false(don't create the .vertx directory) (#1110)
161abb0 is described below

commit 161abb0f7aa46a5e8ab4b913a154914dbe119fff
Author: 兴 <je...@163.com>
AuthorDate: Wed Feb 27 10:19:52 2019 +0800

    [SCB-1177] read vertx.disableFileCPResolving from dynamic config, default is false(don't create the .vertx directory) (#1110)
    
    * [SCB-1177] read vertx.disableFileCPResolving from dynamic config, default is false(don't create the .vertx directory)
    
    * [SCB-1177] default value will be true, do not create the .vertx directory.
    
    * [SCB-1177] code review, add not create folder test case
---
 .../src/main/resources/microservice.yaml           |  2 ++
 .../servicecomb/foundation/vertx/VertxUtils.java   | 14 ++++-----
 .../foundation/vertx/TestVertxUtils.java           | 33 +++++++++++++++++++++-
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index 24fc685..92dafaf 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -86,3 +86,5 @@ ssl.keyStoreValue: Changeme_123
 ssl.crl: revoke.crl
 ssl.sslCustomClass: org.apache.servicecomb.demo.DemoSSLCustom
 
+vertx.disableFileCPResolving: false  # false: create the .vertx directory, true: do not create
+
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
index bb6ff4a..2082ef0 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.Field;
-import java.lang.reflect.Proxy;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
@@ -38,6 +37,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.util.ReflectionUtils;
 import org.springframework.util.StringUtils;
 
+import com.netflix.config.DynamicPropertyFactory;
+
 import io.netty.buffer.ByteBuf;
 import io.vertx.core.AbstractVerticle;
 import io.vertx.core.DeploymentOptions;
@@ -78,7 +79,6 @@ public final class VertxUtils {
 
   public static <T extends AbstractVerticle> void deployVerticle(Vertx vertx, Class<T> cls, int instanceCount) {
     DeploymentOptions options = new DeploymentOptions().setInstances(instanceCount);
-
     vertx.deployVerticle(cls.getName(), options);
   }
 
@@ -134,7 +134,7 @@ public final class VertxUtils {
       LOGGER.info("in debug mode, disable blocked thread check.");
     }
 
-    configureVertxFileCaching();
+    configureVertxFileCaching(vertxOptions);
     Vertx vertx = Vertx.vertx(vertxOptions);
     enhanceVertx(name, vertx);
     return vertx;
@@ -158,10 +158,10 @@ public final class VertxUtils {
   /**
    * 配置vertx的文件缓存功能,默认关闭
    */
-  protected static void configureVertxFileCaching() {
-    if (System.getProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME) == null) {
-      System.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, "true");
-    }
+  protected static void configureVertxFileCaching(VertxOptions vertxOptions) {
+    boolean disableFileCPResolving = DynamicPropertyFactory.getInstance()
+        .getBooleanProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, true).get();
+    vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(!disableFileCPResolving);
   }
 
   // try to reference byte[]
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
index d3c1edd..ee800d2 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
@@ -18,12 +18,15 @@
 package org.apache.servicecomb.foundation.vertx;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.concurrent.CountDownLatch;
 
 import javax.xml.ws.Holder;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
 import org.junit.Assert;
 import org.junit.Test;
@@ -33,8 +36,10 @@ import io.netty.buffer.Unpooled;
 import io.vertx.core.Vertx;
 import io.vertx.core.VertxOptions;
 import io.vertx.core.buffer.Buffer;
+import io.vertx.core.file.impl.FileResolver;
 
 public class TestVertxUtils {
+
   @Test
   public void testGetOrCreateVertx() throws InterruptedException {
     Vertx vertx = VertxUtils.getOrCreateVertxByName("ut", null);
@@ -48,7 +53,33 @@ public class TestVertxUtils {
     latch.await();
 
     Assert.assertEquals(name.value, "ut-vert.x-eventloop-thread-0");
-    VertxUtils.closeVertxByName("ut");
+    VertxUtils.blockCloseVertxByName("ut");
+  }
+
+  @Test
+  public void testCreateVertxWithFileCPResolving() {
+    // Prepare
+    ArchaiusUtils.resetConfig();
+    String cacheDirBase = System.getProperty(FileResolver.CACHE_DIR_BASE_PROP_NAME, ".vertx");
+    File file = new File(cacheDirBase);
+
+    // create .vertx folder
+    FileUtils.deleteQuietly(file);
+    Assert.assertFalse(file.exists());
+    ArchaiusUtils.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, false);
+    VertxUtils.getOrCreateVertxByName("testCreateVertxWithFileCPResolvingFalse", null);
+    Assert.assertTrue(file.exists());
+    VertxUtils.blockCloseVertxByName("testCreateVertxWithFileCPResolvingFalse");
+
+    // don't create .vertx folder
+    FileUtils.deleteQuietly(file);
+    Assert.assertFalse(file.exists());
+    ArchaiusUtils.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, true);
+    VertxUtils.getOrCreateVertxByName("testCreateVertxWithFileCPResolvingTrue", null);
+    Assert.assertFalse(file.exists());
+    VertxUtils.blockCloseVertxByName("testCreateVertxWithFileCPResolvingTrue");
+
+    ArchaiusUtils.resetConfig();
   }
 
   @Test