This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 741ffe0752d Add ZooKeeper and ETCD support for ShardingSphereURLLoader
(#37039)
741ffe0752d is described below
commit 741ffe0752ddac3ef81783166e00b25af9351ef8
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 8 16:26:49 2025 +0800
Add ZooKeeper and ETCD support for ShardingSphereURLLoader (#37039)
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
* Add ZooKeeper and ETCD support for ShardingSphereURLLoader
---
RELEASE-NOTES.md | 1 +
distribution/jdbc/pom.xml | 37 ++++++++++++++
.../url/core/ShardingSphereURLLoadEngine.java | 51 -------------------
.../infra/url/core/ShardingSphereURLTest.java | 9 +++-
infra/url/spi/pom.xml | 2 +-
....java => ShardingSphereLocalFileURLLoader.java} | 8 +--
... ShardingSphereModeConfigurationURLLoader.java} | 13 ++---
...er.java => AbsolutePathLocalFileURLLoader.java} | 8 +--
...infra.url.spi.ShardingSphereLocalFileURLLoader} | 2 +-
.../absolutepath/AbsolutePathURLLoaderTest.java | 2 +-
...oader.java => ClassPathLocalFileURLLoader.java} | 8 +--
...infra.url.spi.ShardingSphereLocalFileURLLoader} | 2 +-
.../url/classpath/ClassPathURLLoaderTest.java | 2 +-
infra/url/{spi => type/etcd}/pom.xml | 6 +--
.../url/etcd/EtcdModeConfigurationURLLoader.java | 42 +++++++++++++++
...l.spi.ShardingSphereModeConfigurationURLLoader} | 2 +-
.../etcd/EtcdModeConfigurationURLLoaderTest.java | 53 +++++++++++++++++++
infra/url/type/pom.xml | 2 +
infra/url/{spi => type/zookeeper}/pom.xml | 6 +--
.../ZooKeeperModeConfigurationURLLoader.java | 42 +++++++++++++++
...l.spi.ShardingSphereModeConfigurationURLLoader} | 2 +-
.../ZooKeeperModeConfigurationURLLoaderTest.java | 53 +++++++++++++++++++
.../jdbc/core/driver/DriverDataSourceCache.java | 8 ++-
.../core/driver/ShardingSphereURLLoadEngine.java | 59 ++++++++++++++++++++++
.../driver}/ShardingSphereURLLoadEngineTest.java | 12 +++--
25 files changed, 343 insertions(+), 89 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 1a200eb49a2..375d99e8785 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -22,6 +22,7 @@
1. Decouple database types as pluggable -
[#35346](https://github.com/apache/shardingsphere/pull/35346)
1. Decouple registry center types as pluggable -
[#36087](https://github.com/apache/shardingsphere/pull/36087)
1. Proxy: Support Firebird Proxy -
[#35937](https://github.com/apache/shardingsphere/pull/35937)
+1. JDBC: Support ZooKeeper and ETCD URL format -
[#37037](https://github.com/apache/shardingsphere/pull/37037)
### Enhancements
diff --git a/distribution/jdbc/pom.xml b/distribution/jdbc/pom.xml
index e4ea408a29e..27febce4836 100644
--- a/distribution/jdbc/pom.xml
+++ b/distribution/jdbc/pom.xml
@@ -178,12 +178,24 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-infra-url-type-zookeeper</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-cluster-mode-repository-etcd</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-url-type-etcd</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
@@ -354,12 +366,25 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-infra-url-type-zookeeper</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-cluster-mode-repository-etcd</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-url-type-etcd</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
@@ -641,6 +666,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-infra-url-type-zookeeper</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
</profile>
<profile>
@@ -652,6 +683,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-url-type-etcd</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
</profile>
diff --git
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngine.java
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngine.java
deleted file mode 100644
index 85ac4988e42..00000000000
---
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngine.java
+++ /dev/null
@@ -1,51 +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.
- */
-
-package org.apache.shardingsphere.infra.url.core;
-
-import org.apache.shardingsphere.infra.url.core.arg.URLArgumentLineRender;
-import
org.apache.shardingsphere.infra.url.core.arg.URLArgumentPlaceholderTypeFactory;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-/**
- * ShardingSphere URL load engine.
- */
-public final class ShardingSphereURLLoadEngine {
-
- private final ShardingSphereURL url;
-
- private final ShardingSphereURLLoader urlLoader;
-
- public ShardingSphereURLLoadEngine(final ShardingSphereURL url) {
- this.url = url;
- urlLoader = TypedSPILoader.getService(ShardingSphereURLLoader.class,
url.getSourceType());
- }
-
- /**
- * Load configuration content.
- *
- * @return loaded content
- */
- public byte[] loadContent() {
- Collection<String> lines =
Arrays.asList(urlLoader.load(url.getConfigurationSubject(),
url.getQueryProps()).split(System.lineSeparator()));
- return URLArgumentLineRender.render(lines,
URLArgumentPlaceholderTypeFactory.valueOf(url.getQueryProps()));
- }
-}
diff --git
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLTest.java
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLTest.java
index 4a8a4e42dd6..9b43fb962fe 100644
---
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLTest.java
+++
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLTest.java
@@ -50,13 +50,20 @@ class ShardingSphereURLTest {
Map<String, String> multiParams = new HashMap<>(2, 1F);
multiParams.put("databaseName", "sharding_db");
multiParams.put("placeholder-type", "none");
+ Map<String, String> regCenterParams = new HashMap<>(2, 1F);
+ regCenterParams.put("namespace", "foo_namespace");
+ regCenterParams.put("maxRetries", "3");
return
Stream.of(Arguments.of("absolutepath:/Users/shardingsphere/config.yaml",
"absolutepath:", "/Users/shardingsphere/config.yaml", Collections.emptyMap()),
Arguments.of("absolutepath:/Users/shardingsphere/config.yaml?",
"absolutepath:", "/Users/shardingsphere/config.yaml", Collections.emptyMap()),
Arguments.of("absolutepath:/Users/shardingsphere/config.yaml?databaseName",
"absolutepath:", "/Users/shardingsphere/config.yaml", Collections.emptyMap()),
Arguments.of("absolutepath:C:\\Users\\shardingsphere\\config.yaml",
"absolutepath:", "C:\\Users\\shardingsphere\\config.yaml",
Collections.emptyMap()),
Arguments.of("absolutepath:/Users/configDirName?databaseName=sharding_db",
"absolutepath:", "/Users/configDirName",
Collections.singletonMap("databaseName", "sharding_db")),
Arguments.of("absolutepath:/Users/configDirName/?databaseName=sharding_db",
"absolutepath:", "/Users/configDirName/",
Collections.singletonMap("databaseName", "sharding_db")),
-
Arguments.of("classpath:config/shardingsphere/config.yml?databaseName=sharding_db&placeholder-type=none",
"classpath:", "config/shardingsphere/config.yml", multiParams));
+
Arguments.of("classpath:config/shardingsphere/config.yml?databaseName=sharding_db&placeholder-type=none",
"classpath:", "config/shardingsphere/config.yml", multiParams),
+
Arguments.of("zookeeper:127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183?namespace=foo_namespace&maxRetries=3",
"zookeeper:", "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
+ regCenterParams),
+
Arguments.of("etcd:127.0.0.1:2379,127.0.0.2:2379,127.0.0.3:2379?namespace=foo_namespace&maxRetries=3",
"etcd:", "127.0.0.1:2379,127.0.0.2:2379,127.0.0.3:2379",
+ regCenterParams));
}
}
}
diff --git a/infra/url/spi/pom.xml b/infra/url/spi/pom.xml
index 25cc61030a5..f6ae74486e5 100644
--- a/infra/url/spi/pom.xml
+++ b/infra/url/spi/pom.xml
@@ -29,7 +29,7 @@
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-spi</artifactId>
+ <artifactId>shardingsphere-cluster-mode-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
diff --git
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereLocalFileURLLoader.java
similarity index 84%
copy from
infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
copy to
infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereLocalFileURLLoader.java
index d01e3722311..8ac1c8f6f78 100644
---
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
+++
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereLocalFileURLLoader.java
@@ -23,17 +23,17 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import java.util.Properties;
/**
- * ShardingSphere URL loader.
+ * ShardingSphere local file URL loader.
*/
@SingletonSPI
-public interface ShardingSphereURLLoader extends TypedSPI {
+public interface ShardingSphereLocalFileURLLoader extends TypedSPI {
/**
* Load configuration content.
*
- * @param configurationSubject configuration subject
+ * @param configSubject configuration subject
* @param queryProps query properties
* @return loaded content
*/
- String load(String configurationSubject, Properties queryProps);
+ String load(String configSubject, Properties queryProps);
}
diff --git
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereModeConfigurationURLLoader.java
similarity index 74%
rename from
infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
rename to
infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereModeConfigurationURLLoader.java
index d01e3722311..f73244146b7 100644
---
a/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereURLLoader.java
+++
b/infra/url/spi/src/main/java/org/apache/shardingsphere/infra/url/spi/ShardingSphereModeConfigurationURLLoader.java
@@ -17,23 +17,24 @@
package org.apache.shardingsphere.infra.url.spi;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import java.util.Properties;
/**
- * ShardingSphere URL loader.
+ * ShardingSphere mode configuration URL loader.
*/
@SingletonSPI
-public interface ShardingSphereURLLoader extends TypedSPI {
+public interface ShardingSphereModeConfigurationURLLoader extends TypedSPI {
/**
- * Load configuration content.
+ * Load mode configuration.
*
- * @param configurationSubject configuration subject
+ * @param serverLists server lists
* @param queryProps query properties
- * @return loaded content
+ * @return loaded mode configuration
*/
- String load(String configurationSubject, Properties queryProps);
+ ModeConfiguration load(String serverLists, Properties queryProps);
}
diff --git
a/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoader.java
b/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathLocalFileURLLoader.java
similarity index 76%
rename from
infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoader.java
rename to
infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathLocalFileURLLoader.java
index 8729bbb427b..729f96db00f 100644
---
a/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoader.java
+++
b/infra/url/type/absolutepath/src/main/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathLocalFileURLLoader.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.infra.url.absolutepath;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader;
import java.io.File;
import java.io.IOException;
@@ -30,12 +30,12 @@ import java.util.stream.Collectors;
/**
* Absolute path URL loader.
*/
-public final class AbsolutePathURLLoader implements ShardingSphereURLLoader {
+public final class AbsolutePathLocalFileURLLoader implements
ShardingSphereLocalFileURLLoader {
@Override
@SneakyThrows(IOException.class)
- public String load(final String configurationSubject, final Properties
queryProps) {
- return
Files.readAllLines(getAbsoluteFile(configurationSubject).toPath(),
StandardCharsets.UTF_8).stream().collect(Collectors.joining(System.lineSeparator()));
+ public String load(final String configSubject, final Properties
queryProps) {
+ return Files.readAllLines(getAbsoluteFile(configSubject).toPath(),
StandardCharsets.UTF_8).stream().collect(Collectors.joining(System.lineSeparator()));
}
private File getAbsoluteFile(final String configurationSubject) {
diff --git
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
b/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
similarity index 90%
copy from
infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
copy to
infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
index afaf4c86245..8507ec3c76d 100644
---
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
+++
b/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.url.absolutepath.AbsolutePathURLLoader
+org.apache.shardingsphere.infra.url.absolutepath.AbsolutePathLocalFileURLLoader
diff --git
a/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoaderTest.java
b/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoaderTest.java
index 0ef311cebfc..bb0245bdefb 100644
---
a/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoaderTest.java
+++
b/infra/url/type/absolutepath/src/test/java/org/apache/shardingsphere/infra/url/absolutepath/AbsolutePathURLLoaderTest.java
@@ -42,7 +42,7 @@ class AbsolutePathURLLoaderTest {
}
private void assertGetContent(final int expectedLength) {
- String actual = new AbsolutePathURLLoader().load(
+ String actual = new AbsolutePathLocalFileURLLoader().load(
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("config/absolutepath/fixture.yaml")).getPath(),
new Properties());
assertThat(actual.length(), is(expectedLength));
}
diff --git
a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java
b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathLocalFileURLLoader.java
similarity index 84%
rename from
infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java
rename to
infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathLocalFileURLLoader.java
index df3e6412e62..01e3e9dc3c8 100644
---
a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java
+++
b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathLocalFileURLLoader.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.infra.url.classpath;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader;
import java.io.BufferedReader;
import java.io.IOException;
@@ -32,12 +32,12 @@ import java.util.stream.Collectors;
/**
* Class path URL loader.
*/
-public final class ClassPathURLLoader implements ShardingSphereURLLoader {
+public final class ClassPathLocalFileURLLoader implements
ShardingSphereLocalFileURLLoader {
@Override
@SneakyThrows(IOException.class)
- public String load(final String configurationSubject, final Properties
queryProps) {
- try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationSubject))
{
+ public String load(final String configSubject, final Properties
queryProps) {
+ try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(configSubject))
{
Objects.requireNonNull(inputStream);
try (BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
return
reader.lines().collect(Collectors.joining(System.lineSeparator()));
diff --git
a/infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
b/infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
similarity index 91%
rename from
infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
rename to
infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
index f5e30ef389e..83f33fa92c5 100644
---
a/infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
+++
b/infra/url/type/classpath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader
+org.apache.shardingsphere.infra.url.classpath.ClassPathLocalFileURLLoader
diff --git
a/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoaderTest.java
b/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoaderTest.java
index d54a8a40101..79fe7981b26 100644
---
a/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoaderTest.java
+++
b/infra/url/type/classpath/src/test/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoaderTest.java
@@ -41,6 +41,6 @@ class ClassPathURLLoaderTest {
}
private void assertGetContent(final int expectedLength) {
- assertThat(new
ClassPathURLLoader().load("config/classpath/fixture.yaml", new
Properties()).length(), is(expectedLength));
+ assertThat(new
ClassPathLocalFileURLLoader().load("config/classpath/fixture.yaml", new
Properties()).length(), is(expectedLength));
}
}
diff --git a/infra/url/spi/pom.xml b/infra/url/type/etcd/pom.xml
similarity index 88%
copy from infra/url/spi/pom.xml
copy to infra/url/type/etcd/pom.xml
index 25cc61030a5..859464f1275 100644
--- a/infra/url/spi/pom.xml
+++ b/infra/url/type/etcd/pom.xml
@@ -20,16 +20,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-url</artifactId>
+ <artifactId>shardingsphere-infra-url-type</artifactId>
<version>5.5.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-infra-url-spi</artifactId>
+ <artifactId>shardingsphere-infra-url-type-etcd</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-spi</artifactId>
+ <artifactId>shardingsphere-infra-url-spi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
diff --git
a/infra/url/type/etcd/src/main/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoader.java
b/infra/url/type/etcd/src/main/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoader.java
new file mode 100644
index 00000000000..5e1eab18417
--- /dev/null
+++
b/infra/url/type/etcd/src/main/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoader.java
@@ -0,0 +1,42 @@
+/*
+ * 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.infra.url.etcd;
+
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader;
+import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+
+import java.util.Properties;
+
+/**
+ * Etcd mode configuration URL loader.
+ */
+public final class EtcdModeConfigurationURLLoader implements
ShardingSphereModeConfigurationURLLoader {
+
+ @Override
+ public ModeConfiguration load(final String serverLists, final Properties
queryProps) {
+
ShardingSpherePreconditions.checkState(queryProps.containsKey("namespace"), ()
-> new RuntimeException("Missing required property 'namespace' for ETCD URL
loader."));
+ return new ModeConfiguration("Cluster", new
ClusterPersistRepositoryConfiguration("etcd",
queryProps.getProperty("namespace"), serverLists, queryProps));
+ }
+
+ @Override
+ public String getType() {
+ return "etcd:";
+ }
+}
diff --git
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
b/infra/url/type/etcd/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
similarity index 91%
copy from
infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
copy to
infra/url/type/etcd/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
index afaf4c86245..d9779d8bfd8 100644
---
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
+++
b/infra/url/type/etcd/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.url.absolutepath.AbsolutePathURLLoader
+org.apache.shardingsphere.infra.url.etcd.EtcdModeConfigurationURLLoader
diff --git
a/infra/url/type/etcd/src/test/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoaderTest.java
b/infra/url/type/etcd/src/test/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoaderTest.java
new file mode 100644
index 00000000000..f6eaa4a4950
--- /dev/null
+++
b/infra/url/type/etcd/src/test/java/org/apache/shardingsphere/infra/url/etcd/EtcdModeConfigurationURLLoaderTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.infra.url.etcd;
+
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
+import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class EtcdModeConfigurationURLLoaderTest {
+
+ private final ShardingSphereModeConfigurationURLLoader urlLoader =
TypedSPILoader.getService(ShardingSphereModeConfigurationURLLoader.class,
"etcd:");
+
+ @Test
+ void assertLoadWithNamespace() {
+ ModeConfiguration actual =
urlLoader.load("localhost:2181,localhost:2182", PropertiesBuilder.build(new
Property("namespace", "foo_namespace"), new Property("timeout", "3000")));
+ assertThat(actual.getType(), is("Cluster"));
+ ClusterPersistRepositoryConfiguration actualRepositoryConfig =
(ClusterPersistRepositoryConfiguration) actual.getRepository();
+ assertThat(actualRepositoryConfig.getType(), is("etcd"));
+ assertThat(actualRepositoryConfig.getProps().getProperty("namespace"),
is("foo_namespace"));
+ assertThat(actualRepositoryConfig.getProps().getProperty("timeout"),
is("3000"));
+ }
+
+ @Test
+ void assertLoadWithoutNamespace() {
+ RuntimeException expectedException =
assertThrows(RuntimeException.class, () ->
urlLoader.load("localhost:2181,localhost:2182", new Properties()));
+ assertThat(expectedException.getMessage(), is("Missing required
property 'namespace' for ETCD URL loader."));
+ }
+}
diff --git a/infra/url/type/pom.xml b/infra/url/type/pom.xml
index 108c0f7b35f..1bc9804eb8f 100644
--- a/infra/url/type/pom.xml
+++ b/infra/url/type/pom.xml
@@ -30,5 +30,7 @@
<modules>
<module>classpath</module>
<module>absolutepath</module>
+ <module>zookeeper</module>
+ <module>etcd</module>
</modules>
</project>
diff --git a/infra/url/spi/pom.xml b/infra/url/type/zookeeper/pom.xml
similarity index 88%
copy from infra/url/spi/pom.xml
copy to infra/url/type/zookeeper/pom.xml
index 25cc61030a5..621b6835a4e 100644
--- a/infra/url/spi/pom.xml
+++ b/infra/url/type/zookeeper/pom.xml
@@ -20,16 +20,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-url</artifactId>
+ <artifactId>shardingsphere-infra-url-type</artifactId>
<version>5.5.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-infra-url-spi</artifactId>
+ <artifactId>shardingsphere-infra-url-type-zookeeper</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-spi</artifactId>
+ <artifactId>shardingsphere-infra-url-spi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
diff --git
a/infra/url/type/zookeeper/src/main/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoader.java
b/infra/url/type/zookeeper/src/main/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoader.java
new file mode 100644
index 00000000000..78e4eee13b3
--- /dev/null
+++
b/infra/url/type/zookeeper/src/main/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoader.java
@@ -0,0 +1,42 @@
+/*
+ * 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.infra.url.zookeeper;
+
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader;
+import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+
+import java.util.Properties;
+
+/**
+ * ZooKeeper mode configuration URL loader.
+ */
+public final class ZooKeeperModeConfigurationURLLoader implements
ShardingSphereModeConfigurationURLLoader {
+
+ @Override
+ public ModeConfiguration load(final String serverLists, final Properties
queryProps) {
+
ShardingSpherePreconditions.checkState(queryProps.containsKey("namespace"), ()
-> new RuntimeException("Missing required property 'namespace' for ZooKeeper
URL loader."));
+ return new ModeConfiguration("Cluster", new
ClusterPersistRepositoryConfiguration("ZooKeeper",
queryProps.getProperty("namespace"), serverLists, queryProps));
+ }
+
+ @Override
+ public String getType() {
+ return "zookeeper:";
+ }
+}
diff --git
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
b/infra/url/type/zookeeper/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
similarity index 90%
rename from
infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
rename to
infra/url/type/zookeeper/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
index afaf4c86245..25c6f49ae1b 100644
---
a/infra/url/type/absolutepath/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader
+++
b/infra/url/type/zookeeper/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.infra.url.absolutepath.AbsolutePathURLLoader
+org.apache.shardingsphere.infra.url.zookeeper.ZooKeeperModeConfigurationURLLoader
diff --git
a/infra/url/type/zookeeper/src/test/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoaderTest.java
b/infra/url/type/zookeeper/src/test/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoaderTest.java
new file mode 100644
index 00000000000..64053f4594b
--- /dev/null
+++
b/infra/url/type/zookeeper/src/test/java/org/apache/shardingsphere/infra/url/zookeeper/ZooKeeperModeConfigurationURLLoaderTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.infra.url.zookeeper;
+
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
+import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class ZooKeeperModeConfigurationURLLoaderTest {
+
+ private final ShardingSphereModeConfigurationURLLoader urlLoader =
TypedSPILoader.getService(ShardingSphereModeConfigurationURLLoader.class,
"zookeeper:");
+
+ @Test
+ void assertLoadWithNamespace() {
+ ModeConfiguration actual =
urlLoader.load("localhost:2181,localhost:2182", PropertiesBuilder.build(new
Property("namespace", "foo_namespace"), new Property("timeout", "3000")));
+ assertThat(actual.getType(), is("Cluster"));
+ ClusterPersistRepositoryConfiguration actualRepositoryConfig =
(ClusterPersistRepositoryConfiguration) actual.getRepository();
+ assertThat(actualRepositoryConfig.getType(), is("ZooKeeper"));
+ assertThat(actualRepositoryConfig.getProps().getProperty("namespace"),
is("foo_namespace"));
+ assertThat(actualRepositoryConfig.getProps().getProperty("timeout"),
is("3000"));
+ }
+
+ @Test
+ void assertLoadWithoutNamespace() {
+ RuntimeException expectedException =
assertThrows(RuntimeException.class, () ->
urlLoader.load("localhost:2181,localhost:2182", new Properties()));
+ assertThat(expectedException.getMessage(), is("Missing required
property 'namespace' for ZooKeeper URL loader."));
+ }
+}
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
index bd5c4f24440..ca2412a7daf 100644
---
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java
@@ -18,9 +18,10 @@
package org.apache.shardingsphere.driver.jdbc.core.driver;
import lombok.Getter;
+import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
import
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.url.core.ShardingSphereURL;
-import org.apache.shardingsphere.infra.url.core.ShardingSphereURLLoadEngine;
import javax.sql.DataSource;
import java.io.IOException;
@@ -54,7 +55,10 @@ public final class DriverDataSourceCache {
private <T extends Throwable> DataSource createDataSource(final
ShardingSphereURL url) throws T {
try {
ShardingSphereURLLoadEngine urlLoadEngine = new
ShardingSphereURLLoadEngine(url);
- return
YamlShardingSphereDataSourceFactory.createDataSource(urlLoadEngine.loadContent());
+ Object loadedContent = urlLoadEngine.loadContent();
+ return loadedContent instanceof ModeConfiguration
+ ?
ShardingSphereDataSourceFactory.createDataSource((ModeConfiguration)
loadedContent)
+ :
YamlShardingSphereDataSourceFactory.createDataSource((byte[]) loadedContent);
} catch (final IOException ex) {
throw (T) new SQLException(ex);
} catch (final SQLException ex) {
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLLoadEngine.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLLoadEngine.java
new file mode 100644
index 00000000000..6d3d0928bb4
--- /dev/null
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereURLLoadEngine.java
@@ -0,0 +1,59 @@
+/*
+ * 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 lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.url.core.ShardingSphereURL;
+import org.apache.shardingsphere.infra.url.core.arg.URLArgumentLineRender;
+import
org.apache.shardingsphere.infra.url.core.arg.URLArgumentPlaceholderTypeFactory;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereModeConfigurationURLLoader;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * ShardingSphere URL load engine.
+ */
+@RequiredArgsConstructor
+public final class ShardingSphereURLLoadEngine {
+
+ private final ShardingSphereURL url;
+
+ /**
+ * Load configuration content.
+ *
+ * @return loaded content
+ * @throws ServiceProviderNotFoundException service provider not found
exception
+ */
+ public Object loadContent() {
+ Optional<ShardingSphereLocalFileURLLoader> localFileURLLoader =
TypedSPILoader.findService(ShardingSphereLocalFileURLLoader.class,
url.getSourceType());
+ if (localFileURLLoader.isPresent()) {
+ Collection<String> lines =
Arrays.asList(localFileURLLoader.get().load(url.getConfigurationSubject(),
url.getQueryProps()).split(System.lineSeparator()));
+ return URLArgumentLineRender.render(lines,
URLArgumentPlaceholderTypeFactory.valueOf(url.getQueryProps()));
+ }
+ Optional<ShardingSphereModeConfigurationURLLoader> modeConfigURLLoader
= TypedSPILoader.findService(ShardingSphereModeConfigurationURLLoader.class,
url.getSourceType());
+ if (modeConfigURLLoader.isPresent()) {
+ return
modeConfigURLLoader.get().load(url.getConfigurationSubject(),
url.getQueryProps());
+ }
+ throw new
ServiceProviderNotFoundException(ShardingSphereModeConfigurationURLLoader.class,
url.getSourceType());
+ }
+}
diff --git
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
b/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereURLLoadEngineTest.java
similarity index 79%
rename from
infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
rename to
jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereURLLoadEngineTest.java
index ce57138193e..898c9eb36b5 100644
---
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/ShardingSphereURLLoadEngineTest.java
+++
b/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereURLLoadEngineTest.java
@@ -15,13 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.url.core;
+package org.apache.shardingsphere.driver;
+import
org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLLoadEngine;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader;
+import org.apache.shardingsphere.infra.url.core.ShardingSphereURL;
+import
org.apache.shardingsphere.infra.url.spi.ShardingSphereLocalFileURLLoader;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
+import java.util.Optional;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -35,10 +39,10 @@ class ShardingSphereURLLoadEngineTest {
void assertLoadContent() {
final String lineSeparator = System.lineSeparator();
String content = "foo_driver_fixture_db=2" + lineSeparator +
"storage_unit_count=2" + lineSeparator;
- ShardingSphereURLLoader urlLoader =
mock(ShardingSphereURLLoader.class);
+ ShardingSphereLocalFileURLLoader urlLoader =
mock(ShardingSphereLocalFileURLLoader.class);
when(urlLoader.load(any(), any())).thenReturn(content);
try (MockedStatic<TypedSPILoader> typedSPILoaderMockedStatic =
mockStatic(TypedSPILoader.class)) {
- typedSPILoaderMockedStatic.when(() ->
TypedSPILoader.getService(ShardingSphereURLLoader.class,
"classpath:")).thenReturn(urlLoader);
+ typedSPILoaderMockedStatic.when(() ->
TypedSPILoader.findService(ShardingSphereLocalFileURLLoader.class,
"classpath:")).thenReturn(Optional.of(urlLoader));
ShardingSphereURLLoadEngine loadEngine = new
ShardingSphereURLLoadEngine(ShardingSphereURL.parse("classpath:xxx"));
assertThat(loadEngine.loadContent(), is(content.getBytes()));
}