20
20
import com .google .common .base .Strings ;
21
21
import lombok .Getter ;
22
22
import lombok .SneakyThrows ;
23
+ import org .apache .shardingsphere .database .connector .core .spi .DatabaseTypedSPILoader ;
23
24
import org .apache .shardingsphere .database .connector .core .type .DatabaseType ;
24
25
import org .apache .shardingsphere .test .e2e .env .container .atomic .constants .StorageContainerConstants ;
25
- import org .apache .shardingsphere .test .e2e .env .container .atomic .storage .option .dialect .MariaDBStorageContainerConfigurationOption ;
26
- import org .apache .shardingsphere .test .e2e .env .container .atomic .storage .option .dialect .MySQLStorageContainerConfigurationOption ;
27
- import org .apache .shardingsphere .test .e2e .env .container .atomic .storage .option .dialect .OpenGaussStorageContainerConfigurationOption ;
28
- import org .apache .shardingsphere .test .e2e .env .container .atomic .storage .option .dialect .PostgreSQLStorageContainerConfigurationOption ;
26
+ import org .apache .shardingsphere .test .e2e .env .container .atomic .storage .option .StorageContainerConfigurationOption ;
29
27
import org .apache .shardingsphere .test .e2e .operation .pipeline .env .enums .PipelineEnvTypeEnum ;
30
28
import org .apache .shardingsphere .test .e2e .operation .pipeline .env .enums .PipelineProxyTypeEnum ;
31
29
@@ -48,25 +46,10 @@ public final class PipelineE2EEnvironment {
48
46
49
47
private final PipelineProxyTypeEnum itProxyType ;
50
48
51
- private final List <String > mysqlVersions ;
52
-
53
- private final List <String > mariadbVersions ;
54
-
55
- private final List <String > postgresqlVersions ;
56
-
57
- private final List <String > openGaussVersions ;
58
-
59
- private final List <String > oracleVersions ;
60
-
61
49
private PipelineE2EEnvironment () {
62
50
props = loadProperties ();
63
51
itEnvType = PipelineEnvTypeEnum .valueOf (props .getProperty ("pipeline.it.env.type" , PipelineEnvTypeEnum .NONE .name ()).toUpperCase ());
64
52
itProxyType = PipelineProxyTypeEnum .valueOf (props .getProperty ("pipeline.it.proxy.type" , PipelineProxyTypeEnum .NONE .name ()).toUpperCase ());
65
- mysqlVersions = Arrays .stream (props .getOrDefault ("pipeline.it.docker.mysql.version" , "" ).toString ().split ("," )).filter (each -> !Strings .isNullOrEmpty (each )).collect (Collectors .toList ());
66
- mariadbVersions = Arrays .stream (props .getOrDefault ("pipeline.it.docker.mariadb.version" , "" ).toString ().split ("," )).filter (each -> !Strings .isNullOrEmpty (each )).collect (Collectors .toList ());
67
- postgresqlVersions = Arrays .stream (props .getOrDefault ("pipeline.it.docker.postgresql.version" , "" ).toString ().split ("," )).filter (cs -> !Strings .isNullOrEmpty (cs )).collect (Collectors .toList ());
68
- openGaussVersions = Arrays .stream (props .getOrDefault ("pipeline.it.docker.opengauss.version" , "" ).toString ().split ("," )).filter (cs -> !Strings .isNullOrEmpty (cs )).collect (Collectors .toList ());
69
- oracleVersions = Arrays .stream (props .getOrDefault ("pipeline.it.docker.oracle.version" , "" ).toString ().split ("," )).filter (cs -> !Strings .isNullOrEmpty (cs )).collect (Collectors .toList ());
70
53
}
71
54
72
55
@ SneakyThrows (IOException .class )
@@ -82,27 +65,14 @@ private Properties loadProperties() {
82
65
}
83
66
84
67
/**
85
- * Get actual data source connection .
68
+ * Get actual database port .
86
69
*
87
70
* @param databaseType database type
88
- * @return jdbc connection
89
- * @throws UnsupportedOperationException unsupported operation exception
71
+ * @return actual database port
90
72
*/
91
73
public int getActualDatabasePort (final DatabaseType databaseType ) {
92
- switch (databaseType .getType ()) {
93
- case "MySQL" :
94
- return Integer .parseInt (props .getOrDefault ("pipeline.it.native.mysql.port" , new MySQLStorageContainerConfigurationOption ().getPort ()).toString ());
95
- case "MariaDB" :
96
- return Integer .parseInt (props .getOrDefault ("pipeline.it.native.mariadb.port" , new MariaDBStorageContainerConfigurationOption ().getPort ()).toString ());
97
- case "PostgreSQL" :
98
- return Integer .parseInt (props .getOrDefault ("pipeline.it.native.postgresql.port" , new PostgreSQLStorageContainerConfigurationOption ().getPort ()).toString ());
99
- case "openGauss" :
100
- return Integer .parseInt (props .getOrDefault ("pipeline.it.native.opengauss.port" , new OpenGaussStorageContainerConfigurationOption ().getPort ()).toString ());
101
- case "Oracle" :
102
- return Integer .parseInt (props .getOrDefault ("pipeline.it.native.oracle.port" , 1521 ).toString ());
103
- default :
104
- throw new UnsupportedOperationException ("Unsupported database type: " + databaseType .getType ());
105
- }
74
+ int defaultPort = DatabaseTypedSPILoader .getService (StorageContainerConfigurationOption .class , databaseType ).getPort ();
75
+ return Integer .parseInt (props .getProperty (String .format ("pipeline.it.native.%s.port" , databaseType .getType ().toLowerCase ()), String .valueOf (defaultPort )));
106
76
}
107
77
108
78
/**
@@ -148,26 +118,13 @@ public static PipelineE2EEnvironment getInstance() {
148
118
*
149
119
* @param databaseType database type
150
120
* @return database storage container images
151
- * @throws UnsupportedOperationException unsupported operation exception
152
121
*/
153
122
public List <String > listStorageContainerImages (final DatabaseType databaseType ) {
154
123
// Native mode needn't use docker image, just return a list which contain one item
155
- if (PipelineEnvTypeEnum .NATIVE == getItEnvType () ) {
124
+ if (PipelineEnvTypeEnum .NATIVE == itEnvType ) {
156
125
return databaseType .getType ().equalsIgnoreCase (getNativeDatabaseType ()) ? Collections .singletonList ("" ) : Collections .emptyList ();
157
126
}
158
- switch (databaseType .getType ()) {
159
- case "MySQL" :
160
- return mysqlVersions ;
161
- case "MariaDB" :
162
- return mariadbVersions ;
163
- case "PostgreSQL" :
164
- return postgresqlVersions ;
165
- case "openGauss" :
166
- return openGaussVersions ;
167
- case "Oracle" :
168
- return oracleVersions ;
169
- default :
170
- throw new UnsupportedOperationException ("Unsupported database type: " + databaseType .getType ());
171
- }
127
+ return Arrays .stream (props .getOrDefault (String .format ("pipeline.it.docker.%s.version" , databaseType .getType ().toLowerCase ()), "" ).toString ()
128
+ .split ("," )).filter (each -> !Strings .isNullOrEmpty (each )).collect (Collectors .toList ());
172
129
}
173
130
}
0 commit comments