You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/09/18 06:39:54 UTC

[incubator-iotdb] branch master updated: [IOTDB-869] Failed to insert data via Windows CLI (#1714)

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

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d853dc  [IOTDB-869] Failed to insert data via Windows CLI (#1714)
0d853dc is described below

commit 0d853dc74b4587d79e3eb9d5cc1bde71c3adb1da
Author: wshao08 <59...@users.noreply.github.com>
AuthorDate: Fri Sep 18 14:39:36 2020 +0800

    [IOTDB-869] Failed to insert data via Windows CLI (#1714)
---
 server/pom.xml                                     |  6 ++
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |  6 +-
 .../apache/iotdb/db/conf/IoTDBDescriptorTest.java  | 76 ++++++++++++++++++++++
 3 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/server/pom.xml b/server/pom.xml
index 61d5276..cbdb003 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -186,6 +186,12 @@
             <artifactId>oauth2-oidc-sdk</artifactId>
             <version>8.3</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-core</artifactId>
+            <version>8.5.15</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index 16811ea..bdaa420 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.time.ZoneId;
 import java.util.Properties;
@@ -118,9 +119,10 @@ public class IoTDBDescriptor {
     else if(!urlString.endsWith(".properties")) {
       urlString += (File.separatorChar + IoTDBConfig.CONFIG_NAME);
     }
-    // If the url doesn't start with "file:" it's provided as a normal path.
+
+    // If the url doesn't start with "file:" or "classpath:", it's provided as a normal path.
     // So we need to add it to make it a real URL.
-    if(!urlString.startsWith("file:")) {
+    if(!urlString.startsWith("file:") && !urlString.startsWith("classpath:")) {
       urlString = "file:" + urlString;
     }
     try {
diff --git a/server/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorTest.java b/server/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorTest.java
new file mode 100644
index 0000000..14f2514
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.iotdb.db.conf;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URL;
+
+public class IoTDBDescriptorTest {
+  private final String confPath = System.getProperty(IoTDBConstant.IOTDB_CONF, null);
+
+  @Before
+  public void init() {
+    org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstance();
+  }
+
+  @After
+  public void clear() {
+    if (confPath != null) {
+      System.setProperty(IoTDBConstant.IOTDB_CONF, confPath);
+    } else {
+      System.clearProperty(IoTDBConstant.IOTDB_CONF);
+    }
+  }
+
+  @Test
+  public void testConfigURLWithFileProtocol() {
+    IoTDBDescriptor desc = IoTDBDescriptor.getInstance();
+    String pathString = "file:/usr/local/bin";
+
+    System.setProperty(IoTDBConstant.IOTDB_CONF, pathString);
+    URL confURL = desc.getPropsUrl();
+    Assert.assertTrue(confURL.toString().startsWith(pathString));
+  }
+
+  @Test
+  public void testConfigURLWithClasspathProtocol() {
+    IoTDBDescriptor desc = IoTDBDescriptor.getInstance();
+
+    String pathString = "classpath:/root/path";
+    System.setProperty(IoTDBConstant.IOTDB_CONF, pathString);
+    URL confURL = desc.getPropsUrl();
+    Assert.assertTrue(confURL.toString().startsWith(pathString));
+  }
+
+  @Test
+  public void testConfigURLWithPlainFilePath() {
+    IoTDBDescriptor desc = IoTDBDescriptor.getInstance();
+    URL path = IoTDBConfig.class.getResource("/" + IoTDBConfig.CONFIG_NAME);
+    // filePath is a plain path string
+    String filePath = path.getFile();
+    System.setProperty(IoTDBConstant.IOTDB_CONF, filePath);
+    URL confURL = desc.getPropsUrl();
+    Assert.assertEquals(confURL.toString(), path.toString());
+  }
+
+}