This is an automated email from the ASF dual-hosted git repository.
panjuan 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 728b7aeefb3 Add ConfigurationContentReader (#30119)
728b7aeefb3 is described below
commit 728b7aeefb30a1ec70b030b7593ef8e66ea041f8
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 14 14:57:02 2024 +0800
Add ConfigurationContentReader (#30119)
---
.../ConfigurationContentReader.java} | 49 +++++++++++-------
.../reader/ConfigurationContentReaderType.java | 26 ++++++++++
.../AbsolutePathWithEnvironmentURLProvider.java | 38 ++------------
.../ClasspathWithEnvironmentURLProvider.java | 37 ++------------
.../ClasspathWithSystemPropsURLProvider.java | 30 ++---------
.../ConfigurationContentReaderTest.java} | 30 ++++++-----
...AbsolutePathWithEnvironmentURLProviderTest.java | 24 ++-------
.../ClasspathWithEnvironmentURLProviderTest.java | 23 ++-------
.../ClasspathWithSystemPropsURLProviderTest.java | 4 +-
.../foo-driver-environment-variables-fixture.yaml | 58 ----------------------
...yaml => foo-driver-to-be-replaced-fixture.yaml} | 0
11 files changed, 97 insertions(+), 222 deletions(-)
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/reader/ConfigurationContentReader.java
similarity index 55%
copy from
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProvider.java
copy to
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReader.java
index b0e4d5dbb69..9fbca672ed2 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/reader/ConfigurationContentReader.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.reader;
-import lombok.SneakyThrows;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
import java.io.BufferedReader;
@@ -28,26 +29,30 @@ import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
/**
- * Classpath with system properties URL provider.
+ * Configuration content reader.
*/
-public final class ClasspathWithSystemPropsURLProvider implements
AbstractClasspathURLProvider {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ConfigurationContentReader {
- @Override
- public String getConfigurationType() {
- return "classpath-system-props:";
- }
-
- @Override
- @SneakyThrows(IOException.class)
- public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
+ /**
+ * Read content.
+ *
+ * @param inputStream input stream
+ * @param type type
+ * @return content
+ * @throws IOException IO exception
+ */
+ public static byte[] read(final InputStream inputStream, final
ConfigurationContentReaderType type) throws IOException {
+ try (BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while (null != (line = reader.readLine())) {
if (!line.startsWith("#")) {
- line = replaceSystemProperties(line);
+ if (ConfigurationContentReaderType.SYSTEM_PROPS == type) {
+ line = replaceSystemProperties(line);
+ } else if (ConfigurationContentReaderType.ENVIRONMENT ==
type) {
+ line = replaceEnvironmentVariables(line);
+ }
builder.append(line).append(System.lineSeparator());
}
}
@@ -55,7 +60,7 @@ public final class ClasspathWithSystemPropsURLProvider
implements AbstractClassp
}
}
- private String replaceSystemProperties(final String line) {
+ private static String replaceSystemProperties(final String line) {
Matcher matcher = ArgsUtils.getPattern().matcher(line);
if (!matcher.find()) {
return line;
@@ -64,4 +69,14 @@ public final class ClasspathWithSystemPropsURLProvider
implements AbstractClassp
String systemPropValue =
System.getProperty(systemPropNameAndDefaultValue[0]);
return ArgsUtils.replaceArg(systemPropValue,
systemPropNameAndDefaultValue[1], matcher);
}
+
+ private static String replaceEnvironmentVariables(final String line) {
+ Matcher matcher = ArgsUtils.getPattern().matcher(line);
+ if (!matcher.find()) {
+ return line;
+ }
+ String[] envNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
+ String envValue = System.getenv(envNameAndDefaultValue[0]);
+ return ArgsUtils.replaceArg(envValue, envNameAndDefaultValue[1],
matcher);
+ }
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
new file mode 100644
index 00000000000..8aadb9ea2f0
--- /dev/null
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderType.java
@@ -0,0 +1,26 @@
+/*
+ * 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.reader;
+
+/**
+ * Configuration content reader type.
+ */
+public enum ConfigurationContentReaderType {
+
+ SYSTEM_PROPS, ENVIRONMENT
+}
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 7a524fb2134..edb83440476 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
@@ -18,16 +18,13 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.regex.Matcher;
/**
* Absolute path with environment variables URL provider.
@@ -42,35 +39,8 @@ public final class AbsolutePathWithEnvironmentURLProvider
implements AbstractAbs
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream = Files.newInputStream(new
File(configurationSubject).toPath());
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = reader.readLine())) {
- if (!line.startsWith("#")) {
- line = replaceEnvironmentVariables(line);
- builder.append(line).append(System.lineSeparator());
- }
- }
- return builder.toString().getBytes(StandardCharsets.UTF_8);
+ try (InputStream inputStream = Files.newInputStream(new
File(configurationSubject).toPath())) {
+ return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.ENVIRONMENT);
}
}
-
- private String replaceEnvironmentVariables(final String line) {
- Matcher matcher = ArgsUtils.getPattern().matcher(line);
- if (!matcher.find()) {
- return line;
- }
- String[] envNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
- String envValue = getEnvironmentVariables(envNameAndDefaultValue[0]);
- return ArgsUtils.replaceArg(envValue, envNameAndDefaultValue[1],
matcher);
- }
-
- /*
- * This method is only used for mocking environment variables in unit
tests and should not be used under any circumstances.
- */
- String getEnvironmentVariables(final String name) {
- return System.getenv(name);
- }
}
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 6128fe2dfa3..8ac47a1daf6 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,13 +19,11 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import lombok.SneakyThrows;
import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Matcher;
/**
* Classpath with environment variables URL provider.
@@ -40,35 +38,8 @@ public final class ClasspathWithEnvironmentURLProvider
implements AbstractClassp
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = reader.readLine())) {
- if (!line.startsWith("#")) {
- line = replaceEnvironmentVariables(line);
- builder.append(line).append(System.lineSeparator());
- }
- }
- return builder.toString().getBytes(StandardCharsets.UTF_8);
+ try (InputStream inputStream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject)) {
+ return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.ENVIRONMENT);
}
}
-
- private String replaceEnvironmentVariables(final String line) {
- Matcher matcher = ArgsUtils.getPattern().matcher(line);
- if (!matcher.find()) {
- return line;
- }
- String[] envNameAndDefaultValue =
ArgsUtils.getArgNameAndDefaultValue(matcher);
- String envValue = getEnvironmentVariables(envNameAndDefaultValue[0]);
- return ArgsUtils.replaceArg(envValue, envNameAndDefaultValue[1],
matcher);
- }
-
- /*
- * This method is only used for mocking environment variables in unit
tests and should not be used under any circumstances.
- */
- String getEnvironmentVariables(final String name) {
- return System.getenv(name);
- }
}
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 b0e4d5dbb69..00274134bf2 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,13 +19,11 @@ package
org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
import lombok.SneakyThrows;
import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReader;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.reader.ConfigurationContentReaderType;
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Matcher;
/**
* Classpath with system properties URL provider.
@@ -40,28 +38,8 @@ public final class ClasspathWithSystemPropsURLProvider
implements AbstractClassp
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String
configurationSubject) {
- try (
- InputStream stream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = reader.readLine())) {
- if (!line.startsWith("#")) {
- line = replaceSystemProperties(line);
- builder.append(line).append(System.lineSeparator());
- }
- }
- return builder.toString().getBytes(StandardCharsets.UTF_8);
+ try (InputStream inputStream =
ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject)) {
+ return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.SYSTEM_PROPS);
}
}
-
- private String replaceSystemProperties(final String line) {
- Matcher matcher = ArgsUtils.getPattern().matcher(line);
- if (!matcher.find()) {
- return line;
- }
- 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/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderTest.java
similarity index 61%
copy from
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithSystemPropsURLProviderTest.java
copy to
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/reader/ConfigurationContentReaderTest.java
index c5b452d9317..e09414da9ce 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/reader/ConfigurationContentReaderTest.java
@@ -15,18 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath;
+package org.apache.shardingsphere.driver.jdbc.core.driver.reader;
-import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Objects;
+
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-class ClasspathWithSystemPropsURLProviderTest {
+class ConfigurationContentReaderTest {
private static final String FIXTURE_JDBC_URL_KEY =
"fixture.config.driver.jdbc-url";
@@ -34,8 +36,6 @@ class ClasspathWithSystemPropsURLProviderTest {
@BeforeAll
static void beforeAll() {
- 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");
}
@@ -47,12 +47,16 @@ class ClasspathWithSystemPropsURLProviderTest {
}
@Test
- void assertReplaceEnvironmentVariables() {
- final String urlPrefix = "jdbc:shardingsphere:";
- ClasspathWithSystemPropsURLProvider urlProvider = new
ClasspathWithSystemPropsURLProvider();
- byte[] actual =
urlProvider.getContent("jdbc:shardingsphere:classpath-system-props:config/driver/foo-driver-system-properties-fixture.yaml",
- "config/driver/foo-driver-system-properties-fixture.yaml");
- byte[] actualOrigin =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
urlPrefix);
- assertThat(actual, is(actualOrigin));
+ void assertReadWithSystemProperties() throws IOException {
+ byte[] actual =
readContent("config/driver/foo-driver-to-be-replaced-fixture.yaml");
+ byte[] expected = readContent("config/driver/foo-driver-fixture.yaml");
+ assertThat(actual, is(expected));
+ }
+
+ private byte[] readContent(final String name) throws IOException {
+ String path =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(name)).getPath();
+ try (FileInputStream inputStream = new FileInputStream(path)) {
+ return ConfigurationContentReader.read(inputStream,
ConfigurationContentReaderType.SYSTEM_PROPS);
+ }
}
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
index 4dc8a7c1801..618004f3a41 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/absolutepath/AbsolutePathWithEnvironmentURLProviderTest.java
@@ -24,30 +24,14 @@ import java.util.Objects;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
class AbsolutePathWithEnvironmentURLProviderTest {
@Test
void assertGetContent() {
- assertThat(getActual(createURLProvider()), is(getExpected()));
- }
-
- private AbsolutePathWithEnvironmentURLProvider createURLProvider() {
- AbsolutePathWithEnvironmentURLProvider result = spy(new
AbsolutePathWithEnvironmentURLProvider());
-
when(result.getEnvironmentVariables("FIXTURE_JDBC_URL")).thenReturn("jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-
when(result.getEnvironmentVariables("FIXTURE_USERNAME")).thenReturn("sa");
- return result;
- }
-
- private byte[] getActual(final AbsolutePathWithEnvironmentURLProvider
urlProvider) {
- String absoluteActualPath =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-environment-variables-fixture.yaml")).getPath();
- return
urlProvider.getContent("jdbc:shardingsphere:absolutepath-environment:" +
absoluteActualPath, absoluteActualPath);
- }
-
- private byte[] getExpected() {
- String absoluteExpectedPath =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
- return
ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" +
absoluteExpectedPath, "jdbc:shardingsphere:");
+ String path =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
+ byte[] actual = new
AbsolutePathWithEnvironmentURLProvider().getContent("jdbc:shardingsphere:absolutepath-environment:"
+ path, path);
+ byte[] expected =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" + path,
"jdbc:shardingsphere:");
+ assertThat(actual, is(expected));
}
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
index 8e529c593e0..b70d27c5ca2 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/spi/classpath/ClasspathWithEnvironmentURLProviderTest.java
@@ -22,29 +22,14 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
class ClasspathWithEnvironmentURLProviderTest {
@Test
void assertGetContent() {
- assertThat(getActual(createURLProvider()), is(getExpected()));
- }
-
- private ClasspathWithEnvironmentURLProvider createURLProvider() {
- ClasspathWithEnvironmentURLProvider result = spy(new
ClasspathWithEnvironmentURLProvider());
-
when(result.getEnvironmentVariables("FIXTURE_JDBC_URL")).thenReturn("jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-
when(result.getEnvironmentVariables("FIXTURE_USERNAME")).thenReturn("sa");
- return result;
- }
-
- private byte[] getActual(final ClasspathWithEnvironmentURLProvider
urlProvider) {
- return urlProvider.getContent(
-
"jdbc:shardingsphere:classpath-environment:config/driver/foo-driver-environment-variables-fixture.yaml",
"config/driver/foo-driver-environment-variables-fixture.yaml");
- }
-
- private byte[] getExpected() {
- return
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
"jdbc:shardingsphere:");
+ byte[] actual = new ClasspathWithEnvironmentURLProvider().getContent(
+
"jdbc:shardingsphere:classpath-environment:config/driver/foo-driver-fixture.yaml",
"config/driver/foo-driver-fixture.yaml");
+ byte[] expected =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath-environment:config/driver/foo-driver-fixture.yaml",
"jdbc:shardingsphere:");
+ assertThat(actual, is(expected));
}
}
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 c5b452d9317..e78cc97b11d 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
@@ -50,8 +50,8 @@ class ClasspathWithSystemPropsURLProviderTest {
void assertReplaceEnvironmentVariables() {
final String urlPrefix = "jdbc:shardingsphere:";
ClasspathWithSystemPropsURLProvider urlProvider = new
ClasspathWithSystemPropsURLProvider();
- byte[] actual =
urlProvider.getContent("jdbc:shardingsphere:classpath-system-props:config/driver/foo-driver-system-properties-fixture.yaml",
- "config/driver/foo-driver-system-properties-fixture.yaml");
+ byte[] actual =
urlProvider.getContent("jdbc:shardingsphere:classpath-system-props:config/driver/foo-driver-to-be-replaced-fixture.yaml",
+ "config/driver/foo-driver-to-be-replaced-fixture.yaml");
byte[] actualOrigin =
ShardingSphereURLManager.getContent("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml",
urlPrefix);
assertThat(actual, is(actualOrigin));
}
diff --git
a/jdbc/core/src/test/resources/config/driver/foo-driver-environment-variables-fixture.yaml
b/jdbc/core/src/test/resources/config/driver/foo-driver-environment-variables-fixture.yaml
deleted file mode 100644
index 36b2aaf73c2..00000000000
---
a/jdbc/core/src/test/resources/config/driver/foo-driver-environment-variables-fixture.yaml
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# 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.
-#
-
-# After `ShardingSphereURLManager.getContent`, this file should be equivalent
to `foo-driver-fixture.yaml` in the same folder.
-databaseName: foo_driver_fixture_db
-
-dataSources:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.h2.Driver
- jdbcUrl:
jdbc:h2:mem:foo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
- username: sa
- password:
- ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: $${FIXTURE_DRIVER_CLASS_NAME::org.h2.Driver}
- jdbcUrl: $${FIXTURE_JDBC_URL::jdbc:h2:mem:foo_ds_do_not_use}
- username: $${FIXTURE_USERNAME::}
- password: $${FIXTURE_PASSWORD::}
-
-rules:
- - !SHARDING
- autoTables:
- t_order:
- actualDataSources: ds_0,ds_1
- shardingStrategy:
- standard:
- shardingColumn: order_id
- shardingAlgorithmName: auto_mod
- keyGenerateStrategy:
- column: user_id
- keyGeneratorName: snowflake
- shardingAlgorithms:
- auto_mod:
- type: HASH_MOD
- props:
- sharding-count: 2
-
- keyGenerators:
- snowflake:
- type: SNOWFLAKE
-
-props:
- sql-show: true
diff --git
a/jdbc/core/src/test/resources/config/driver/foo-driver-system-properties-fixture.yaml
b/jdbc/core/src/test/resources/config/driver/foo-driver-to-be-replaced-fixture.yaml
similarity index 100%
rename from
jdbc/core/src/test/resources/config/driver/foo-driver-system-properties-fixture.yaml
rename to
jdbc/core/src/test/resources/config/driver/foo-driver-to-be-replaced-fixture.yaml