31
31
import org .apache .shardingsphere .test .e2e .env .container .storage .mount .MountSQLResourceGenerator ;
32
32
import org .apache .shardingsphere .test .e2e .env .container .storage .option .StorageContainerConfigurationOption ;
33
33
import org .apache .shardingsphere .test .e2e .env .container .util .DockerImageVersion ;
34
+ import org .apache .shardingsphere .test .e2e .env .container .util .JdbcConnectCheckingWaitStrategy ;
34
35
import org .apache .shardingsphere .test .e2e .env .container .util .SQLScriptUtils ;
35
36
import org .apache .shardingsphere .test .e2e .env .container .util .StorageContainerUtils ;
36
- import org .apache .shardingsphere .test .e2e .env .container .util .JdbcConnectCheckingWaitStrategy ;
37
37
import org .apache .shardingsphere .test .e2e .env .runtime .datasource .DataSourceEnvironment ;
38
38
import org .apache .shardingsphere .test .e2e .env .runtime .scenario .database .DatabaseEnvironmentManager ;
39
39
import org .apache .shardingsphere .test .e2e .env .runtime .scenario .path .ScenarioDataPath .Type ;
@@ -63,6 +63,8 @@ public final class DockerStorageContainer extends DockerITContainer implements S
63
63
64
64
private final int majorVersion ;
65
65
66
+ private final DataSourceEnvironment dataSourceEnvironment ;
67
+
66
68
@ Getter
67
69
private final Map <String , DataSource > actualDataSourceMap = new LinkedHashMap <>();
68
70
@@ -74,6 +76,7 @@ public DockerStorageContainer(final String containerImage, final StorageContaine
74
76
this .option = option ;
75
77
this .scenario = scenario ;
76
78
majorVersion = new DockerImageVersion (getContainerImage (containerImage , option )).getMajorVersion ();
79
+ dataSourceEnvironment = DatabaseTypedSPILoader .getService (DataSourceEnvironment .class , option .getType ());
77
80
}
78
81
79
82
private static String getContainerImage (final String containerImage , final StorageContainerConfigurationOption option ) {
@@ -85,20 +88,11 @@ private static String getContainerImage(final String containerImage, final Stora
85
88
protected void configure () {
86
89
setCommands ();
87
90
addEnvironments ();
88
- mapResources (new MountConfigurationResourceGenerator (option ).generate (majorVersion , scenario ));
89
- if (option .isSupportDockerEntrypoint ()) {
90
- mapResources (new MountSQLResourceGenerator (option ).generate (majorVersion , scenario ));
91
- }
91
+ mountConfigurations ();
92
+ mountSQLFiles ();
92
93
setPrivilegedMode ();
93
94
withExposedPorts (getExposedPort ());
94
- if (option .isSupportDockerEntrypoint ()) {
95
- setWaitStrategy (new JdbcConnectCheckingWaitStrategy (() -> DriverManager .getConnection (
96
- getURL (), StorageContainerConstants .CHECK_READY_USER , StorageContainerConstants .CHECK_READY_PASSWORD )));
97
- } else {
98
- setWaitStrategy (new JdbcConnectCheckingWaitStrategy (() -> DriverManager .getConnection (
99
- getURL (), option .getDefaultUserWhenUnsupportedDockerEntrypoint ().orElse ("" ), option .getDefaultPasswordWhenUnsupportedDockerEntrypoint ().orElse ("" ))));
100
- }
101
- withStartupTimeout (Duration .ofSeconds (option .getStartupTimeoutSeconds ()));
95
+ setWaitStrategy ();
102
96
}
103
97
104
98
private void setCommands () {
@@ -112,14 +106,30 @@ private void addEnvironments() {
112
106
option .getEnvironments ().forEach (this ::addEnv );
113
107
}
114
108
109
+ private void mountConfigurations () {
110
+ mapResources (new MountConfigurationResourceGenerator (option ).generate (majorVersion , scenario ));
111
+ }
112
+
113
+ private void mountSQLFiles () {
114
+ if (option .isSupportDockerEntrypoint ()) {
115
+ mapResources (new MountSQLResourceGenerator (option ).generate (majorVersion , scenario ));
116
+ }
117
+ }
118
+
115
119
private void setPrivilegedMode () {
116
120
if (option .withPrivilegedMode ()) {
117
121
withPrivilegedMode (true );
118
122
}
119
123
}
120
124
125
+ private void setWaitStrategy () {
126
+ String user = option .isSupportDockerEntrypoint () ? StorageContainerConstants .CHECK_READY_USER : option .getDefaultUserWhenUnsupportedDockerEntrypoint ().orElse ("" );
127
+ String password = option .isSupportDockerEntrypoint () ? StorageContainerConstants .CHECK_READY_PASSWORD : option .getDefaultPasswordWhenUnsupportedDockerEntrypoint ().orElse ("" );
128
+ setWaitStrategy (new JdbcConnectCheckingWaitStrategy (() -> DriverManager .getConnection (getURL (), user , password )));
129
+ withStartupTimeout (Duration .ofSeconds (option .getStartupTimeoutSeconds ()));
130
+ }
131
+
121
132
private String getURL () {
122
- DataSourceEnvironment dataSourceEnvironment = DatabaseTypedSPILoader .getService (DataSourceEnvironment .class , option .getType ());
123
133
return option .getDefaultDatabaseName (majorVersion )
124
134
.map (optional -> dataSourceEnvironment .getURL ("localhost" , getFirstMappedPort (), optional ))
125
135
.orElseGet (() -> dataSourceEnvironment .getURL ("localhost" , getFirstMappedPort ()));
@@ -133,7 +143,7 @@ protected void containerIsStarted(final InspectContainerResponse containerInfo)
133
143
}
134
144
Thread .sleep (10000L );
135
145
try (
136
- Connection connection = DriverManager .getConnection (DatabaseTypedSPILoader . getService ( DataSourceEnvironment . class , option . getType ()) .getURL ("localhost" , getFirstMappedPort ()),
146
+ Connection connection = DriverManager .getConnection (dataSourceEnvironment .getURL ("localhost" , getFirstMappedPort ()),
137
147
option .getDefaultUserWhenUnsupportedDockerEntrypoint ().orElse ("" ), option .getDefaultPasswordWhenUnsupportedDockerEntrypoint ().orElse ("" ))) {
138
148
for (String each : new MountSQLResourceGenerator (option ).generate (majorVersion , scenario ).keySet ()) {
139
149
SQLScriptUtils .execute (connection , each );
0 commit comments