This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7e67bd0b267 Fix nightly build CI on Windows 11 (#30033)
7e67bd0b267 is described below
commit 7e67bd0b267f3c3a3f4f3c39bb787ea30725e7ee
Author: Ling Hengqian <[email protected]>
AuthorDate: Wed Feb 7 13:11:01 2024 +0800
Fix nightly build CI on Windows 11 (#30033)
---
.../driver/jdbc/core/driver/ArgsUtils.java | 109 +++++++++++++++++++++
.../spi/absolutepath/AbsolutePathURLProvider.java | 5 +-
.../AbsolutePathWithEnvironmentURLProvider.java | 26 ++---
.../AbstractAbsolutePathURLProvider.java | 10 +-
.../classpath/AbstractClasspathURLProvider.java | 21 +---
.../driver/spi/classpath/ClasspathURLProvider.java | 7 +-
.../ClasspathWithEnvironmentURLProvider.java | 28 ++----
.../ClasspathWithSystemPropsURLProvider.java | 25 ++---
.../core/driver/ShardingSphereURLManagerTest.java | 27 ++++-
.../ClasspathWithSystemPropsURLProviderTest.java | 7 +-
10 files changed, 168 insertions(+), 97 deletions(-)
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
new file mode 100644
index 00000000000..74e8395a508
--- /dev/null
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ArgsUtils.java
@@ -0,0 +1,109 @@
+/*
+ * 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.shardingsphere.driver.jdbc.core.driver;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+import java.io.InputStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Arguments Utils.
+ */
+public class ArgsUtils {
+
+ private static final String KEY_VALUE_SEPARATOR = "::";
+
+ private static final Pattern PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
+
+ public static String getKeyValueSeparator() {
+ return KEY_VALUE_SEPARATOR;
+ }
+
+ /**
+ * Get Pattern.
+ *
+ * @return {@link java.util.regex.Pattern}
+ */
+ public static Pattern getPattern() {
+ return PATTERN;
+ }
+
+ /**
+ * Get arg name and default value.
+ *
+ * @param matcher {@link Matcher}
+ * @return Argument name and default value.
+ */
+ public static String[] getArgNameAndDefaultValue(final Matcher matcher) {
+ String groupString = matcher.group(1);
+ return groupString.split(ArgsUtils.getKeyValueSeparator(), 2);
+ }
+
+ /**
+ * Replace argument.
+ *
+ * @param targetValue the value of the argument
+ * @param defaultValue the default value of the argument
+ * @param matcher {@link Matcher}
+ * @return {@link String}
+ */
+ public static String replaceArg(final String targetValue, final String
defaultValue, final Matcher matcher) {
+ if (Strings.isNullOrEmpty(targetValue) && defaultValue.isEmpty()) {
+ String modifiedLineWithSpace = matcher.replaceAll("");
+ return modifiedLineWithSpace.substring(0,
modifiedLineWithSpace.length() - 1);
+ }
+ if (Strings.isNullOrEmpty(targetValue)) {
+ return matcher.replaceAll(defaultValue);
+ }
+ return matcher.replaceAll(targetValue);
+ }
+
+ /**
+ * Get configuration file.
+ *
+ * @param url url
+ * @param urlPrefix url prefix
+ * @param pathType path type
+ * @return {@link String}
+ */
+ public static String getConfigurationFile(final String url, final String
urlPrefix, final String pathType) {
+ String configuredFile = url.substring(urlPrefix.length(),
url.contains("?") ? url.indexOf('?') : url.length());
+ String file = configuredFile.substring(pathType.length());
+ Preconditions.checkArgument(!file.isEmpty(), "Configuration file is
required in ShardingSphere URL.");
+ return file;
+ }
+
+ /**
+ * Get resource as stream from classpath.
+ *
+ * @param resource resource
+ * @return {@link InputStream}
+ * @throws IllegalArgumentException Can not find configuration file.
+ */
+ public static InputStream getResourceAsStreamFromClasspath(final String
resource) {
+ InputStream result =
Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ result = null == result ?
Thread.currentThread().getContextClassLoader().getResourceAsStream("/" +
resource) : result;
+ if (null != result) {
+ return result;
+ }
+ throw new IllegalArgumentException(String.format("Can not find
configuration file `%s`.", resource));
+ }
+}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
index 0c4c5e3be70..fb681ec96a3 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathURLProvider.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -31,7 +32,7 @@ import java.nio.file.Files;
/**
* Absolute path URL provider.
*/
-public final class AbsolutePathURLProvider extends
AbstractAbsolutePathURLProvider {
+public final class AbsolutePathURLProvider implements
AbstractAbsolutePathURLProvider {
private static final String PATH_TYPE = "absolutepath:";
@@ -43,7 +44,7 @@ public final class AbsolutePathURLProvider extends
AbstractAbsolutePathURLProvid
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
- String file = getConfigurationFile(url, urlPrefix, PATH_TYPE);
+ String file = ArgsUtils.getConfigurationFile(url, urlPrefix,
PATH_TYPE);
try (
InputStream stream = Files.newInputStream(new
File(file).toPath());
BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
index e6749403a54..d7d4662517d 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProvider.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -28,19 +29,14 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Absolute path with environment variables URL provider.
*/
-public class AbsolutePathWithEnvironmentURLProvider extends
AbstractAbsolutePathURLProvider {
+public class AbsolutePathWithEnvironmentURLProvider implements
AbstractAbsolutePathURLProvider {
private static final String PATH_TYPE = "absolutepath-environment:";
- private static final String KEY_VALUE_SEPARATOR = "::";
-
- private static final Pattern PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
-
@Override
public boolean accept(final String url) {
return !Strings.isNullOrEmpty(url) && url.contains(PATH_TYPE);
@@ -49,7 +45,7 @@ public class AbsolutePathWithEnvironmentURLProvider extends
AbstractAbsolutePath
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
- String file = getConfigurationFile(url, urlPrefix, PATH_TYPE);
+ String file = ArgsUtils.getConfigurationFile(url, urlPrefix,
PATH_TYPE);
try (
InputStream stream = Files.newInputStream(new
File(file).toPath());
BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
@@ -66,21 +62,13 @@ public class AbsolutePathWithEnvironmentURLProvider extends
AbstractAbsolutePath
}
private String replaceEnvironmentVariables(final String line) {
- Matcher matcher = PATTERN.matcher(line);
+ Matcher matcher = ArgsUtils.getPattern().matcher(line);
if (!matcher.find()) {
return line;
}
- String[] envNameAndDefaultValue =
matcher.group(1).split(KEY_VALUE_SEPARATOR, 2);
- String envName = envNameAndDefaultValue[0];
- String envValue = getEnvironmentVariables(envName);
- if (Strings.isNullOrEmpty(envValue) &&
envNameAndDefaultValue[1].isEmpty()) {
- String modifiedLineWithSpace = matcher.replaceAll("");
- return modifiedLineWithSpace.substring(0,
modifiedLineWithSpace.length() - 1);
- }
- if (Strings.isNullOrEmpty(envValue)) {
- envValue = envNameAndDefaultValue[1];
- }
- return matcher.replaceAll(envValue);
+ String[] envNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
+ String envValue = getEnvironmentVariables(envNameAndDefaultValue[0]);
+ return ArgsUtils.replaceArg(envValue, envNameAndDefaultValue[1],
matcher);
}
/**
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
index 9302dab62d0..42d73473e46 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbstractAbsolutePathURLProvider.java
@@ -17,18 +17,10 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
-import com.google.common.base.Preconditions;
import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;
/**
* Abstract absolute path URL provider.
*/
-public abstract class AbstractAbsolutePathURLProvider implements
ShardingSphereURLProvider {
-
- String getConfigurationFile(final String url, final String urlPrefix,
final String pathType) {
- String configuredFile = url.substring(urlPrefix.length(),
url.contains("?") ? url.indexOf('?') : url.length());
- String file = configuredFile.substring(pathType.length());
- Preconditions.checkArgument(!file.isEmpty(), "Configuration file is
required in ShardingSphere URL.");
- return file;
- }
+public interface AbstractAbsolutePathURLProvider extends
ShardingSphereURLProvider {
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
index 5e5f77ae367..32f95eff04e 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/AbstractClasspathURLProvider.java
@@ -17,29 +17,10 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
-import com.google.common.base.Preconditions;
import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;
-import java.io.InputStream;
-
/**
* Abstract classpath URL provider.
*/
-public abstract class AbstractClasspathURLProvider implements
ShardingSphereURLProvider {
-
- String getConfigurationFile(final String url, final String urlPrefix,
final String pathType) {
- String configuredFile = url.substring(urlPrefix.length(),
url.contains("?") ? url.indexOf('?') : url.length());
- String file = configuredFile.substring(pathType.length());
- Preconditions.checkArgument(!file.isEmpty(), "Configuration file is
required in ShardingSphere URL.");
- return file;
- }
-
- InputStream getResourceAsStream(final String resource) {
- InputStream result =
Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
- result = null == result ?
Thread.currentThread().getContextClassLoader().getResourceAsStream("/" +
resource) : result;
- if (null != result) {
- return result;
- }
- throw new IllegalArgumentException(String.format("Can not find
configuration file `%s`.", resource));
- }
+public interface AbstractClasspathURLProvider extends
ShardingSphereURLProvider {
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
index b9fe26f8e2a..6535923693e 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathURLProvider.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -29,7 +30,7 @@ import java.nio.charset.StandardCharsets;
/**
* Classpath URL provider.
*/
-public final class ClasspathURLProvider extends AbstractClasspathURLProvider {
+public final class ClasspathURLProvider implements
AbstractClasspathURLProvider {
private static final String PATH_TYPE = "classpath:";
@@ -41,9 +42,9 @@ public final class ClasspathURLProvider extends
AbstractClasspathURLProvider {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
- String file = getConfigurationFile(url, urlPrefix, PATH_TYPE);
+ String file = ArgsUtils.getConfigurationFile(url, urlPrefix,
PATH_TYPE);
try (
- InputStream stream = getResourceAsStream(file);
+ InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
index 0d13564e314..2f79f636632 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProvider.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -26,19 +27,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Classpath with environment variables URL provider.
*/
-public final class ClasspathWithEnvironmentURLProvider extends
AbstractClasspathURLProvider {
+public final class ClasspathWithEnvironmentURLProvider implements
AbstractClasspathURLProvider {
private static final String PATH_TYPE = "classpath-environment:";
- private static final String KEY_VALUE_SEPARATOR = "::";
-
- private static final Pattern PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
-
@Override
public boolean accept(final String url) {
return !Strings.isNullOrEmpty(url) && url.contains(PATH_TYPE);
@@ -47,9 +43,9 @@ public final class ClasspathWithEnvironmentURLProvider
extends AbstractClasspath
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
- String file = getConfigurationFile(url, urlPrefix, PATH_TYPE);
+ String file = ArgsUtils.getConfigurationFile(url, urlPrefix,
PATH_TYPE);
try (
- InputStream stream = getResourceAsStream(file);
+ InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
@@ -64,21 +60,13 @@ public final class ClasspathWithEnvironmentURLProvider
extends AbstractClasspath
}
private String replaceEnvironmentVariables(final String line) {
- Matcher matcher = PATTERN.matcher(line);
+ Matcher matcher = ArgsUtils.getPattern().matcher(line);
if (!matcher.find()) {
return line;
}
- String[] envNameAndDefaultValue =
matcher.group(1).split(KEY_VALUE_SEPARATOR, 2);
- String envName = envNameAndDefaultValue[0];
- String envValue = getEnvironmentVariables(envName);
- if (Strings.isNullOrEmpty(envValue) &&
envNameAndDefaultValue[1].isEmpty()) {
- String modifiedLineWithSpace = matcher.replaceAll("");
- return modifiedLineWithSpace.substring(0,
modifiedLineWithSpace.length() - 1);
- }
- if (Strings.isNullOrEmpty(envValue)) {
- envValue = envNameAndDefaultValue[1];
- }
- return matcher.replaceAll(envValue);
+ String[] envNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
+ String envValue = getEnvironmentVariables(envNameAndDefaultValue[0]);
+ return ArgsUtils.replaceArg(envValue, envNameAndDefaultValue[1],
matcher);
}
/**
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
index 43f5f824f9e..cc8a4e4294d 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -26,19 +27,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Classpath with system properties URL provider.
*/
-public final class ClasspathWithSystemPropsURLProvider extends
AbstractClasspathURLProvider {
+public final class ClasspathWithSystemPropsURLProvider implements
AbstractClasspathURLProvider {
private static final String PATH_TYPE = "classpath-system-props:";
- private static final String KEY_VALUE_SEPARATOR = "::";
-
- private static final Pattern PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
-
@Override
public boolean accept(final String url) {
return !Strings.isNullOrEmpty(url) && url.contains(PATH_TYPE);
@@ -47,9 +43,9 @@ public final class ClasspathWithSystemPropsURLProvider
extends AbstractClasspath
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
- String file = getConfigurationFile(url, urlPrefix, PATH_TYPE);
+ String file = ArgsUtils.getConfigurationFile(url, urlPrefix,
PATH_TYPE);
try (
- InputStream stream = getResourceAsStream(file);
+ InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
@@ -64,17 +60,12 @@ public final class ClasspathWithSystemPropsURLProvider
extends AbstractClasspath
}
private String replaceSystemProperties(final String line) {
- Matcher matcher = PATTERN.matcher(line);
+ Matcher matcher = ArgsUtils.getPattern().matcher(line);
if (!matcher.find()) {
return line;
}
- String[] systemPropNameAndDefaultValue =
matcher.group(1).split(KEY_VALUE_SEPARATOR, 2);
- String systemPropName = systemPropNameAndDefaultValue[0];
- String systemPropValue = System.getProperty(systemPropName,
systemPropNameAndDefaultValue[1]);
- if (Strings.isNullOrEmpty(systemPropValue)) {
- String modifiedLineWithSpace = matcher.replaceAll("");
- return modifiedLineWithSpace.substring(0,
modifiedLineWithSpace.length() - 1);
- }
- return matcher.replaceAll(systemPropValue);
+ String[] systemPropNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
+ String systemPropValue =
System.getProperty(systemPropNameAndDefaultValue[0]);
+ return ArgsUtils.replaceArg(systemPropValue,
systemPropNameAndDefaultValue[1], matcher);
}
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
index 6e27d45c130..8895cf518f6 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLManagerTest.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.driver.jdbc.core.driver;
import
org.apache.shardingsphere.driver.jdbc.exception.syntax.URLProviderNotFoundException;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Objects;
@@ -31,7 +33,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(AutoMockExtension.class)
class ShardingSphereURLManagerTest {
- private final int fooDriverConfigLength = 999;
+ private final int fooDriverConfigLengthOnUnix = 999;
+
+ private final int fooDriverConfigLengthOnWindows = 1040;
private final String urlPrefix = "jdbc:shardingsphere:";
@@ -41,15 +45,32 @@ class ShardingSphereURLManagerTest {
}
@Test
+ @EnabledOnOs({OS.LINUX, OS.MAC})
void assertToClasspathConfigurationFile() {
byte[] actual =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
urlPrefix);
- assertThat(actual.length, is(fooDriverConfigLength));
+ assertThat(actual.length, is(fooDriverConfigLengthOnUnix));
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ void assertToClasspathConfigurationFileOnWindows() {
+ byte[] actual =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
urlPrefix);
+ assertThat(actual.length, is(fooDriverConfigLengthOnWindows));
}
@Test
+ @EnabledOnOs({OS.LINUX, OS.MAC})
void assertToAbsolutePathConfigurationFile() {
String absolutePath =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
byte[] actual =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" +
absolutePath, urlPrefix);
- assertThat(actual.length, is(fooDriverConfigLength));
+ assertThat(actual.length, is(fooDriverConfigLengthOnUnix));
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ void assertToAbsolutePathConfigurationFileOnWindows() {
+ String absolutePath =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
+ byte[] actual =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" +
absolutePath, urlPrefix);
+ assertThat(actual.length, is(fooDriverConfigLengthOnWindows));
}
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
index a9fc9f71724..18cbab3a5d4 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
@@ -18,14 +18,13 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.nullValue;
class ClasspathWithSystemPropsURLProviderTest {
@@ -35,8 +34,8 @@ class ClasspathWithSystemPropsURLProviderTest {
@BeforeAll
static void beforeAll() {
- assertThat(System.getProperty(FIXTURE_JDBC_URL_KEY),
Matchers.is(nullValue()));
- assertThat(System.getProperty(FIXTURE_USERNAME_KEY),
Matchers.is(nullValue()));
+ assertThat(System.getProperty(FIXTURE_JDBC_URL_KEY), is(nullValue()));
+ assertThat(System.getProperty(FIXTURE_USERNAME_KEY), is(nullValue()));
System.setProperty(FIXTURE_JDBC_URL_KEY,
"jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
System.setProperty(FIXTURE_USERNAME_KEY, "sa");
}