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 acc6402caab Add NativeStorageEnvironment (#36649)
acc6402caab is described below
commit acc6402caab96d4d7f2817a87ade0442dad59a8e
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Sep 20 23:49:24 2025 +0800
Add NativeStorageEnvironment (#36649)
---
.../impl/ShardingSphereProxyEmbeddedContainer.java | 7 ++--
.../storage/type/NativeStorageContainer.java | 17 ++++----
.../test/e2e/env/runtime/E2ETestEnvironment.java | 15 ++------
.../runtime/natived/NativeStorageEnvironment.java | 45 ++++++++++++++++++++++
4 files changed, 60 insertions(+), 24 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
index fec22a9e8e3..8082846db3f 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/adapter/impl/ShardingSphereProxyEmbeddedContainer.java
@@ -158,14 +158,15 @@ public final class ShardingSphereProxyEmbeddedContainer
implements EmbeddedITCon
result.putAll(getStorageConnectionInfoMap((NativeStorageContainer) each));
}
}
- result.put("username: " + StorageContainerConstants.OPERATION_USER,
"username: " + E2ETestEnvironment.getInstance().getNativeStorageUsername());
- result.put("password: " +
StorageContainerConstants.OPERATION_PASSWORD, "password: " +
E2ETestEnvironment.getInstance().getNativeStoragePassword());
+ result.put("username: " + StorageContainerConstants.OPERATION_USER,
"username: " +
E2ETestEnvironment.getInstance().getNativeStorageEnvironment().getUser());
+ result.put("password: " +
StorageContainerConstants.OPERATION_PASSWORD, "password: " +
E2ETestEnvironment.getInstance().getNativeStorageEnvironment().getPassword());
return result;
}
private Map<String, String> getStorageConnectionInfoMap(final
NativeStorageContainer container) {
return container.getNetworkAliases().stream().collect(Collectors.toMap(
- each -> each + ":" + container.getExposedPort(), each ->
E2ETestEnvironment.getInstance().getNativeStorageHost() + ":" +
E2ETestEnvironment.getInstance().getNativeStoragePort()));
+ each -> each + ":" + container.getExposedPort(),
+ each ->
E2ETestEnvironment.getInstance().getNativeStorageEnvironment().getHost() + ":"
+ E2ETestEnvironment.getInstance().getNativeStorageEnvironment().getPort()));
}
private File createTempDirectory() {
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/NativeStorageContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/NativeStorageContainer.java
index 8049a0d3798..40c28b615d5 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/NativeStorageContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/NativeStorageContainer.java
@@ -29,6 +29,7 @@ import
org.apache.shardingsphere.test.e2e.env.container.util.SQLScriptUtils;
import
org.apache.shardingsphere.test.e2e.env.container.util.StorageContainerUtils;
import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.natived.NativeStorageEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;
@@ -46,7 +47,7 @@ import java.util.stream.Collectors;
*/
public final class NativeStorageContainer implements StorageContainer {
- private final E2ETestEnvironment env;
+ private final NativeStorageEnvironment env;
private final DatabaseType databaseType;
@@ -65,7 +66,7 @@ public final class NativeStorageContainer implements
StorageContainer {
private List<String> networkAliases;
public NativeStorageContainer(final DatabaseType databaseType, final
String scenario) {
- env = E2ETestEnvironment.getInstance();
+ env = E2ETestEnvironment.getInstance().getNativeStorageEnvironment();
this.databaseType = databaseType;
this.scenario = scenario;
option =
DatabaseTypedSPILoader.findService(StorageContainerOption.class,
databaseType).orElse(null);
@@ -77,8 +78,7 @@ public final class NativeStorageContainer implements
StorageContainer {
private void initDatabase() {
if (null != option) {
DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
- DataSource dataSource = StorageContainerUtils.generateDataSource(
- dataSourceEnvironment.getURL(env.getNativeStorageHost(),
env.getNativeStoragePort()), env.getNativeStorageUsername(),
env.getNativeStoragePassword(), 2);
+ DataSource dataSource =
StorageContainerUtils.generateDataSource(dataSourceEnvironment.getURL(env.getHost(),
env.getPort()), env.getUser(), env.getPassword(), 2);
new MountSQLResourceGenerator(option).generate(0,
scenario).keySet().forEach(each -> SQLScriptUtils.execute(dataSource, each));
}
}
@@ -94,8 +94,7 @@ public final class NativeStorageContainer implements
StorageContainer {
DataSourceEnvironment dataSourceEnvironment =
DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, databaseType);
Map<String, DataSource> result = new HashMap<>(databaseNames.size(),
1F);
for (String each : databaseNames) {
- DataSource dataSource = StorageContainerUtils.generateDataSource(
- dataSourceEnvironment.getURL(env.getNativeStorageHost(),
env.getNativeStoragePort(), each), env.getNativeStorageUsername(),
env.getNativeStoragePassword(), 2);
+ DataSource dataSource =
StorageContainerUtils.generateDataSource(dataSourceEnvironment.getURL(env.getHost(),
env.getPort(), each), env.getUser(), env.getPassword(), 2);
result.put(each, dataSource);
}
return result;
@@ -123,10 +122,10 @@ public final class NativeStorageContainer implements
StorageContainer {
public Map<String, String> getLinkReplacements() {
Map<String, String> result = new HashMap<>(getNetworkAliases().size()
+ 2, 1F);
for (String each : getNetworkAliases()) {
- result.put(each + ":" + getExposedPort(),
env.getNativeStorageHost() + ":" + env.getNativeStoragePort());
+ result.put(each + ":" + getExposedPort(), env.getHost() + ":" +
env.getPort());
}
- result.put(StorageContainerConstants.OPERATION_USER,
env.getNativeStorageUsername());
- result.put(StorageContainerConstants.OPERATION_PASSWORD,
env.getNativeStoragePassword());
+ result.put(StorageContainerConstants.OPERATION_USER, env.getUser());
+ result.put(StorageContainerConstants.OPERATION_PASSWORD,
env.getPassword());
return result;
}
}
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
index 326721dbf59..2fab90854cb 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/E2ETestEnvironment.java
@@ -21,8 +21,8 @@ import com.google.common.base.Splitter;
import lombok.Getter;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.test.e2e.env.container.adapter.enums.AdapterMode;
-import
org.apache.shardingsphere.test.e2e.env.container.constants.StorageContainerConstants;
import
org.apache.shardingsphere.test.e2e.env.runtime.cluster.ClusterEnvironment;
+import
org.apache.shardingsphere.test.e2e.env.runtime.natived.NativeStorageEnvironment;
import
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioCommonPath;
import java.io.IOException;
@@ -52,13 +52,7 @@ public final class E2ETestEnvironment {
private final ClusterEnvironment clusterEnvironment;
- private final String nativeStorageHost;
-
- private final int nativeStoragePort;
-
- private final String nativeStorageUsername;
-
- private final String nativeStoragePassword;
+ private final NativeStorageEnvironment nativeStorageEnvironment;
private E2ETestEnvironment() {
Properties props = loadProperties();
@@ -70,10 +64,7 @@ public final class E2ETestEnvironment {
scenarios = getScenarios(props);
governanceCenter = props.getProperty("it.env.governance.center");
clusterEnvironment = new ClusterEnvironment(props);
- nativeStorageHost = props.getProperty("it.native.storage.host",
"127.0.0.1");
- nativeStoragePort =
Integer.parseInt(props.getProperty("it.native.storage.port", "0"));
- nativeStorageUsername =
props.getProperty("it.native.storage.username",
StorageContainerConstants.OPERATION_USER);
- nativeStoragePassword =
props.getProperty("it.native.storage.password",
StorageContainerConstants.OPERATION_PASSWORD);
+ nativeStorageEnvironment = new NativeStorageEnvironment(props);
}
@SneakyThrows(IOException.class)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/natived/NativeStorageEnvironment.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/natived/NativeStorageEnvironment.java
new file mode 100644
index 00000000000..8c430c02f85
--- /dev/null
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/natived/NativeStorageEnvironment.java
@@ -0,0 +1,45 @@
+/*
+ * 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.test.e2e.env.runtime.natived;
+
+import lombok.Getter;
+import
org.apache.shardingsphere.test.e2e.env.container.constants.StorageContainerConstants;
+
+import java.util.Properties;
+
+/**
+ * Native storage environment.
+ */
+@Getter
+public final class NativeStorageEnvironment {
+
+ private final String host;
+
+ private final int port;
+
+ private final String user;
+
+ private final String password;
+
+ public NativeStorageEnvironment(final Properties props) {
+ host = props.getProperty("it.native.storage.host", "127.0.0.1");
+ port = Integer.parseInt(props.getProperty("it.native.storage.port",
"0"));
+ user = props.getProperty("it.native.storage.username",
StorageContainerConstants.OPERATION_USER);
+ password = props.getProperty("it.native.storage.password",
StorageContainerConstants.OPERATION_PASSWORD);
+ }
+}