|
17 | 17 |
|
18 | 18 | package org.apache.shardingsphere.test.e2e.env.container.atomic.storage.type.docker;
|
19 | 19 |
|
| 20 | +import com.github.dockerjava.api.command.InspectContainerResponse; |
20 | 21 | import com.google.common.base.Preconditions;
|
21 | 22 | import com.google.common.base.Strings;
|
22 | 23 | import lombok.Getter;
|
| 24 | +import lombok.SneakyThrows; |
23 | 25 | import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
|
24 | 26 | import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
|
25 | 27 | import org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer;
|
|
29 | 31 | import org.apache.shardingsphere.test.e2e.env.container.atomic.storage.mount.MountSQLResourceGenerator;
|
30 | 32 | import org.apache.shardingsphere.test.e2e.env.container.atomic.storage.option.StorageContainerConfigurationOption;
|
31 | 33 | import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DockerImageVersion;
|
| 34 | +import org.apache.shardingsphere.test.e2e.env.container.atomic.util.SQLScriptUtils; |
32 | 35 | import org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtils;
|
33 | 36 | import org.apache.shardingsphere.test.e2e.env.container.wait.JdbcConnectionWaitStrategy;
|
34 | 37 | import org.apache.shardingsphere.test.e2e.env.runtime.datasource.DataSourceEnvironment;
|
35 | 38 | import org.apache.shardingsphere.test.e2e.env.runtime.scenario.database.DatabaseEnvironmentManager;
|
36 | 39 | import org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;
|
37 | 40 |
|
38 | 41 | import javax.sql.DataSource;
|
| 42 | +import java.sql.Connection; |
39 | 43 | import java.sql.DriverManager;
|
| 44 | +import java.sql.SQLException; |
40 | 45 | import java.time.Duration;
|
41 | 46 | import java.util.Collection;
|
42 | 47 | import java.util.Collections;
|
@@ -81,10 +86,17 @@ protected final void configure() {
|
81 | 86 | setCommands();
|
82 | 87 | addEnvironments();
|
83 | 88 | mapResources(new MountConfigurationResourceGenerator(option).generate(majorVersion, scenario));
|
84 |
| - mapResources(new MountSQLResourceGenerator(option).generate(majorVersion, scenario)); |
| 89 | + if (option.isSupportDockerEntrypoint()) { |
| 90 | + mapResources(new MountSQLResourceGenerator(option).generate(majorVersion, scenario)); |
| 91 | + } |
85 | 92 | setPrivilegedMode();
|
86 | 93 | withExposedPorts(getExposedPort());
|
87 |
| - setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(), StorageContainerConstants.CHECK_READY_USER, StorageContainerConstants.CHECK_READY_PASSWORD))); |
| 94 | + if (option.isSupportDockerEntrypoint()) { |
| 95 | + setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(), StorageContainerConstants.CHECK_READY_USER, StorageContainerConstants.CHECK_READY_PASSWORD))); |
| 96 | + } else { |
| 97 | + setWaitStrategy(new JdbcConnectionWaitStrategy(() -> DriverManager.getConnection(getURL(), |
| 98 | + option.getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""), option.getDefaultPasswordWhenUnsupportedDockerEntrypoint().orElse("")))); |
| 99 | + } |
88 | 100 | withStartupTimeout(Duration.ofSeconds(option.getStartupTimeoutSeconds()));
|
89 | 101 | }
|
90 | 102 |
|
@@ -112,6 +124,22 @@ private String getURL() {
|
112 | 124 | .orElseGet(() -> dataSourceEnvironment.getURL("localhost", getFirstMappedPort()));
|
113 | 125 | }
|
114 | 126 |
|
| 127 | + @SneakyThrows({SQLException.class, InterruptedException.class}) |
| 128 | + @Override |
| 129 | + protected final void containerIsStarted(final InspectContainerResponse containerInfo) { |
| 130 | + if (option.isSupportDockerEntrypoint()) { |
| 131 | + return; |
| 132 | + } |
| 133 | + Thread.sleep(10000L); |
| 134 | + try ( |
| 135 | + Connection connection = DriverManager.getConnection(DatabaseTypedSPILoader.getService(DataSourceEnvironment.class, option.getType()).getURL("localhost", getFirstMappedPort()), |
| 136 | + option.getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""), option.getDefaultPasswordWhenUnsupportedDockerEntrypoint().orElse(""))) { |
| 137 | + for (String each : new MountSQLResourceGenerator(option).generate(majorVersion, scenario).keySet()) { |
| 138 | + SQLScriptUtils.execute(connection, each); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
115 | 143 | @Override
|
116 | 144 | protected void postStart() {
|
117 | 145 | actualDataSourceMap.putAll(createAccessDataSources(getDataSourceNames(getDataSourceNameAndTypeMap(Type.ACTUAL))));
|
|
0 commit comments