Skip to content

Commit 4bfdb6d

Browse files
authored
Merge pull request #54 from mlozbin-cybervisiontech/feature/CDAP-15658-generic-database-tests
CDAP-15658 Make the DB integration tests automated
2 parents 7d9e967 + 725d8a2 commit 4bfdb6d

File tree

38 files changed

+1048
-495
lines changed

38 files changed

+1048
-495
lines changed

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,13 @@ machine or in docker container. Tests create tables and sample data, so user con
55
corresponding permissions. To run integration tests execute following command in shell:
66
```
77
mvn clean test \
8-
-Dmysql.host=localhost -Dmysql.port=3306 -Dmysql.database=mydb -Dmysql.username=root -Dmysql.password=root \
9-
-Dpostgresql.host=localhost -Dpostgresql.port=54032 -Dpostgresql.database=test -Dpostgresql.username=postgres \
10-
-Dpostgresql.password=cdap \
11-
-Doracle.host=localhost -Doracle.port=1521 -Doracle.username=ora -Doracle.password=cdap -Doracle.database=EE \
12-
-Doracle.connectionType=SID \
13-
-Ddb2.host=localhost -Ddb2.port=50000 -Ddb2.database=SAMPLE -Ddb2.username=DB2INST -Db2.password=DB2INST1-pwd \
14-
-Dnetezza.host=localhost -Dnetezza.port=5480 -Dnetezza.database=test -Dnetezza.username=admin \
15-
-Dnetezza.password=password \
168
-DauroraMysql.clusterEndpoint=cdap-cluster.xyz.eu-central-1.rds.amazonaws.com -DauroraMysql.port=3306 \
179
-DauroraMysql.database=cdapdb -DauroraMysql.username=cdap -DauroraMysql.password=cdap \
1810
-DauroraPostgresql.clusterEndpoint=pginstance.cxywmbgwp60k.eu-central-1.rds.amazonaws.com -DauroraPostgresql.port=5432 \
19-
-DauroraPostgresql.database=cdappg -DauroraPostgresql.username=cdap -DauroraPostgresql.password=cdap
11+
-DauroraPostgresql.database=cdappg -DauroraPostgresql.username=cdap -DauroraPostgresql.password=cdap \
2012
-DjdbcDriversJars="/jdbc/drivers/jars/some.jar, "
2113
```
22-
14+
Notice that you must change properties for Aurora MySQL and Aurora Postgresql to real before running tests.
2315
## Setup Local Environment
2416
MySQL, Postgresql, MSSQL, DB2 are using prebuild images.
2517

@@ -36,43 +28,55 @@ cd docker-compose/db-plugins-env/
3628
docker-compose up -d
3729
```
3830
* [Install and start Netezza emulator](http://dwgeek.com/install-vmware-player-netezza-emulator.html/)
31+
* Create database `mydb` in Netezza emulator
3932

4033
### Properties
4134
#### MySQL
4235
* **mysql.host** - Server host. Default: localhost.
4336
* **mysql.port** - Server port. Default: 3306.
4437
* **mysql.database** - Server namespace for test databases. Default: mydb.
45-
* **mysql.username** - Server username Default: root.
38+
* **mysql.username** - Server username. Default: root.
4639
* **mysql.password** - Server password. Default: 123Qwe123.
4740
#### Postgresql
4841
* **postgresql.host** - Server host. Default: localhost.
4942
* **postgresql.port** - Server port. Default: 5432.
5043
* **postgresql.database** - Server namespace for test databases. Default: mydb.
51-
* **postgresql.username** - Server username Default: postgres.
44+
* **postgresql.username** - Server username. Default: postgres.
5245
* **postgresql.password** - Server password. Default: 123Qwe123.
5346
#### MSSQL
5447
* **mssql.host** - Server host. Default: localhost.
5548
* **mssql.port** - Server port. Default: 1433.
5649
* **mssql.database** - Server namespace for test databases. Default: tempdb.
57-
* **mssql.username** - Server username Default: sa.
50+
* **mssql.username** - Server username. Default: sa.
5851
* **mssql.password** - Server password. Default: 123Qwe123.
5952
#### DB2
6053
* **db2.host** - Server host. Default: localhost.
6154
* **db2.port** - Server port. Default: 50000.
6255
* **db2.database** - Server namespace for test databases. Default: mydb.
63-
* **db2.username** - Server username Default: db2inst1.
56+
* **db2.username** - Server username. Default: db2inst1.
6457
* **db2.password** - Server password. Default: 123Qwe123.
6558
#### Oracle
6659
* **oracle.host** - Server host. Default: localhost.
6760
* **oracle.port** - Server port. Default: 1521.
68-
* **oracle.username** - Server username Default: SYSTEM.
61+
* **oracle.username** - Server username. Default: SYSTEM.
6962
* **oracle.password** - Server password. Default: 123Qwe123.
7063
* **oracle.database** - Server sid/database. Default: cdap.
7164
* **oracle.connectionType** - Server connection type (service/sid) Default: sid.
7265
#### Netezza
7366
* **netezza.host** - Server host. Default: localhost.
7467
* **netezza.port** - Server port. Default: 5480.
7568
* **netezza.database** - Server namespace for test databases. Default: mydb.
76-
* **netezza.username** - Server username Default: admin.
69+
* **netezza.username** - Server username. Default: admin.
7770
* **netezza.password** - Server password. Default: password.
78-
71+
#### Aurora MySQL
72+
* **auroraMysql.clusterEndpoint** - Cluster endpoint.
73+
* **auroraMysql.port** - Server port.
74+
* **auroraMysql.database** - Server namespace for test databases.
75+
* **auroraMysql.username** - Server username.
76+
* **auroraMysql.password** - Server password.
77+
#### Aurora Postgresql
78+
* **auroraPostgresql.clusterEndpoint** - Cluster endpoint.
79+
* **auroraPostgresql.port** - Server port.
80+
* **auroraPostgresql.database** - Server namespace for test databases. Default: mydb.
81+
* **auroraPostgresql.username** - Server username.
82+
* **auroraPostgresql.password** - Server password.

aurora-mysql-plugin/src/test/java/io/cdap/plugin/aurora/mysql/AuroraMysqlPluginTestBase.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import java.util.TimeZone;
5656
import javax.sql.rowset.serial.SerialBlob;
5757

58-
public class AuroraMysqlPluginTestBase extends DatabasePluginTestBase {
58+
public abstract class AuroraMysqlPluginTestBase extends DatabasePluginTestBase {
5959
protected static final ArtifactId DATAPIPELINE_ARTIFACT_ID = NamespaceId.DEFAULT.artifact("data-pipeline", "3.2.0");
6060
protected static final ArtifactSummary DATAPIPELINE_ARTIFACT = new ArtifactSummary("data-pipeline", "3.2.0");
6161
protected static final long CURRENT_TS = System.currentTimeMillis();
@@ -73,11 +73,11 @@ public class AuroraMysqlPluginTestBase extends DatabasePluginTestBase {
7373
public static final TestConfiguration CONFIG = new TestConfiguration("explore.enabled", false);
7474

7575
protected static final Map<String, String> BASE_PROPS = ImmutableMap.<String, String>builder()
76-
.put(ConnectionConfig.HOST, System.getProperty("auroraMysql.clusterEndpoint"))
77-
.put(ConnectionConfig.PORT, System.getProperty("auroraMysql.port"))
78-
.put(ConnectionConfig.DATABASE, System.getProperty("auroraMysql.database"))
79-
.put(ConnectionConfig.USER, System.getProperty("auroraMysql.username"))
80-
.put(ConnectionConfig.PASSWORD, System.getProperty("auroraMysql.password"))
76+
.put(ConnectionConfig.HOST, getPropertyOrFail("auroraMysql.clusterEndpoint"))
77+
.put(ConnectionConfig.PORT, getPropertyOrFail("auroraMysql.port"))
78+
.put(ConnectionConfig.DATABASE, getPropertyOrFail("auroraMysql.database"))
79+
.put(ConnectionConfig.USER, getPropertyOrFail("auroraMysql.username"))
80+
.put(ConnectionConfig.PASSWORD, getPropertyOrFail("auroraMysql.password"))
8181
.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME)
8282
.build();
8383

@@ -185,7 +185,7 @@ protected static void prepareTestData(Connection conn) throws SQLException {
185185
}
186186
}
187187

188-
private static void populateData(PreparedStatement ...stmts) throws SQLException {
188+
private static void populateData(PreparedStatement... stmts) throws SQLException {
189189
// insert the same data into both tables: my_table and your_table
190190
for (PreparedStatement pStmt : stmts) {
191191
for (int i = 1; i <= 5; i++) {
@@ -228,6 +228,16 @@ private static void populateData(PreparedStatement ...stmts) throws SQLException
228228
}
229229
}
230230

231+
private static String getPropertyOrFail(String propertyName) {
232+
String value = System.getProperty(propertyName);
233+
234+
if (value == null) {
235+
throw new IllegalStateException("There is no value for property " + propertyName);
236+
}
237+
238+
return value;
239+
}
240+
231241
public static Connection createConnection() {
232242
try {
233243
Class.forName(DRIVER_CLASS);

aurora-postgresql-plugin/src/test/java/io/cdap/plugin/auroradb/postgres/AuroraPostgresPluginTestBase.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import java.util.Map;
5151
import java.util.TimeZone;
5252

53-
public class AuroraPostgresPluginTestBase extends DatabasePluginTestBase {
53+
public abstract class AuroraPostgresPluginTestBase extends DatabasePluginTestBase {
5454
protected static final ArtifactId DATAPIPELINE_ARTIFACT_ID = NamespaceId.DEFAULT.artifact("data-pipeline", "3.2.0");
5555
protected static final ArtifactSummary DATAPIPELINE_ARTIFACT = new ArtifactSummary("data-pipeline", "3.2.0");
5656
protected static final long CURRENT_TS = System.currentTimeMillis();
@@ -68,11 +68,11 @@ public class AuroraPostgresPluginTestBase extends DatabasePluginTestBase {
6868
public static final TestConfiguration CONFIG = new TestConfiguration("explore.enabled", false);
6969

7070
protected static final Map<String, String> BASE_PROPS = ImmutableMap.<String, String>builder()
71-
.put(ConnectionConfig.HOST, System.getProperty("auroraPostgresql.clusterEndpoint"))
72-
.put(ConnectionConfig.PORT, System.getProperty("auroraPostgresql.port"))
73-
.put(ConnectionConfig.DATABASE, System.getProperty("auroraPostgresql.database"))
74-
.put(ConnectionConfig.USER, System.getProperty("auroraPostgresql.username"))
75-
.put(ConnectionConfig.PASSWORD, System.getProperty("auroraPostgresql.password"))
71+
.put(ConnectionConfig.HOST, getPropertyOrFail("auroraPostgresql.clusterEndpoint"))
72+
.put(ConnectionConfig.PORT, getPropertyOrFail("auroraPostgresql.port"))
73+
.put(ConnectionConfig.DATABASE, getPropertyOrFail("auroraPostgresql.database"))
74+
.put(ConnectionConfig.USER, getPropertyOrFail("auroraPostgresql.username"))
75+
.put(ConnectionConfig.PASSWORD, getPropertyOrFail("auroraPostgresql.password"))
7676
.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME)
7777
.build();
7878

@@ -163,7 +163,7 @@ protected static void prepareTestData(Connection conn) throws SQLException {
163163
}
164164
}
165165

166-
private static void populateData(PreparedStatement ...stmts) throws SQLException {
166+
private static void populateData(PreparedStatement... stmts) throws SQLException {
167167
// insert the same data into both tables: my_table and your_table
168168
for (PreparedStatement pStmt : stmts) {
169169
for (int i = 1; i <= 5; i++) {
@@ -189,6 +189,16 @@ private static void populateData(PreparedStatement ...stmts) throws SQLException
189189
}
190190
}
191191

192+
private static String getPropertyOrFail(String propertyName) {
193+
String value = System.getProperty(propertyName);
194+
195+
if (value == null) {
196+
throw new IllegalStateException("There is no value for property " + propertyName);
197+
}
198+
199+
return value;
200+
}
201+
192202
public static Connection createConnection() {
193203
try {
194204
Class.forName(Driver.class.getCanonicalName());

database-commons/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<artifactId>cdap-api</artifactId>
6060
<scope>compile</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>com.mockrunner</groupId>
64+
<artifactId>mockrunner-jdbc</artifactId>
65+
<version>${mockrunner.version}</version>
66+
<scope>test</scope>
67+
</dependency>
6268
</dependencies>
6369

6470
<build>

database-commons/src/main/java/io/cdap/plugin/db/ColumnType.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.cdap.plugin.db;
1818

19+
import java.util.Objects;
20+
1921
/**
2022
* Stores SQL column name and type.
2123
*/
@@ -42,4 +44,32 @@ public String getTypeName() {
4244
public int getType() {
4345
return type;
4446
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) {
51+
return true;
52+
}
53+
if (o == null || getClass() != o.getClass()) {
54+
return false;
55+
}
56+
ColumnType that = (ColumnType) o;
57+
return type == that.type &&
58+
Objects.equals(name, that.name) &&
59+
Objects.equals(typeName, that.typeName);
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash(name, typeName, type);
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "ColumnType{" +
70+
"name='" + name + '\'' +
71+
", typeName='" + typeName + '\'' +
72+
", type=" + type +
73+
'}';
74+
}
4575
}

0 commit comments

Comments
 (0)