Skip to content

Commit 5045a4b

Browse files
migrate to CDAP 6.5.0 and fix failed test suits (#120)
* migrate to CDAP 6.5.0 and fix failed test suits
1 parent c652e04 commit 5045a4b

File tree

41 files changed

+403
-787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+403
-787
lines changed

aurora-mysql-plugin/pom.xml

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@
6161
</dependency>
6262
<dependency>
6363
<groupId>io.cdap.cdap</groupId>
64-
<artifactId>cdap-data-pipeline</artifactId>
64+
<artifactId>cdap-data-pipeline2_2.11</artifactId>
6565
</dependency>
6666
<dependency>
6767
<groupId>junit</groupId>
6868
<artifactId>junit</artifactId>
6969
</dependency>
70+
<dependency>
71+
<groupId>mysql</groupId>
72+
<artifactId>mysql-connector-java</artifactId>
73+
<version>8.0.19</version>
74+
<scope>test</scope>
75+
</dependency>
7076
<dependency>
7177
<groupId>io.cdap.cdap</groupId>
7278
<artifactId>cdap-api</artifactId>
@@ -79,36 +85,8 @@
7985
<scope>compile</scope>
8086
</dependency>
8187
</dependencies>
82-
8388
<build>
8489
<plugins>
85-
<plugin>
86-
<groupId>org.apache.felix</groupId>
87-
<artifactId>maven-bundle-plugin</artifactId>
88-
<version>3.3.0</version>
89-
<extensions>true</extensions>
90-
<configuration>
91-
<instructions>
92-
<_exportcontents>
93-
io.cdap.plugin.*;
94-
org.apache.commons.lang;
95-
org.apache.commons.logging.*;
96-
org.codehaus.jackson.*
97-
</_exportcontents>
98-
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
99-
<Embed-Transitive>true</Embed-Transitive>
100-
<Embed-Directory>lib</Embed-Directory>
101-
</instructions>
102-
</configuration>
103-
<executions>
104-
<execution>
105-
<phase>package</phase>
106-
<goals>
107-
<goal>bundle</goal>
108-
</goals>
109-
</execution>
110-
</executions>
111-
</plugin>
11290
<plugin>
11391
<groupId>io.cdap</groupId>
11492
<artifactId>cdap-maven-plugin</artifactId>

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.google.common.base.Charsets;
2020
import com.google.common.base.Throwables;
21-
import com.google.common.collect.ImmutableMap;
2221
import com.google.common.collect.Sets;
2322
import io.cdap.cdap.api.artifact.ArtifactSummary;
2423
import io.cdap.cdap.api.plugin.PluginClass;
@@ -38,6 +37,8 @@
3837
import org.junit.AfterClass;
3938
import org.junit.BeforeClass;
4039
import org.junit.ClassRule;
40+
import org.slf4j.Logger;
41+
import org.slf4j.LoggerFactory;
4142

4243
import java.math.BigDecimal;
4344
import java.sql.Connection;
@@ -49,44 +50,40 @@
4950
import java.sql.Time;
5051
import java.sql.Timestamp;
5152
import java.sql.Types;
53+
import java.util.Arrays;
5254
import java.util.Calendar;
5355
import java.util.Collections;
56+
import java.util.HashMap;
5457
import java.util.Map;
5558
import java.util.TimeZone;
5659
import javax.sql.rowset.serial.SerialBlob;
5760

5861
public abstract class AuroraMysqlPluginTestBase extends DatabasePluginTestBase {
62+
private static final Logger LOGGER = LoggerFactory.getLogger(AuroraMysqlPluginTestBase.class);
5963
protected static final ArtifactId DATAPIPELINE_ARTIFACT_ID = NamespaceId.DEFAULT.artifact("data-pipeline", "3.2.0");
6064
protected static final ArtifactSummary DATAPIPELINE_ARTIFACT = new ArtifactSummary("data-pipeline", "3.2.0");
6165
protected static final long CURRENT_TS = System.currentTimeMillis();
6266
protected static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
6367
protected static final String JDBC_DRIVER_NAME = "mysql";
68+
protected static final Map<String, String> BASE_PROPS = new HashMap<>();
6469

6570
protected static String connectionUrl;
6671
protected static int year;
6772
protected static final int PRECISION = 10;
6873
protected static final int SCALE = 6;
69-
protected static boolean tearDown = true;
7074
private static int startCount;
7175

7276
@ClassRule
7377
public static final TestConfiguration CONFIG = new TestConfiguration("explore.enabled", false);
7478

75-
protected static final Map<String, String> BASE_PROPS = ImmutableMap.<String, String>builder()
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"))
81-
.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME)
82-
.build();
83-
8479
@BeforeClass
8580
public static void setupTest() throws Exception {
8681
if (startCount++ > 0) {
8782
return;
8883
}
8984

85+
getProperties();
86+
9087
Calendar calendar = Calendar.getInstance();
9188
calendar.setTime(new Date(CURRENT_TS));
9289
year = calendar.get(Calendar.YEAR);
@@ -118,6 +115,15 @@ public static void setupTest() throws Exception {
118115
prepareTestData(conn);
119116
}
120117

118+
private static void getProperties() {
119+
BASE_PROPS.put(ConnectionConfig.HOST, getPropertyOrSkip("auroraMysql.clusterEndpoint"));
120+
BASE_PROPS.put(ConnectionConfig.PORT, getPropertyOrSkip("auroraMysql.port"));
121+
BASE_PROPS.put(ConnectionConfig.DATABASE, getPropertyOrSkip("auroraMysql.database"));
122+
BASE_PROPS.put(ConnectionConfig.USER, getPropertyOrSkip("auroraMysql.username"));
123+
BASE_PROPS.put(ConnectionConfig.PASSWORD, getPropertyOrSkip("auroraMysql.password"));
124+
BASE_PROPS.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME);
125+
}
126+
121127
protected static void createTestTables(Connection conn) throws SQLException {
122128
try (Statement stmt = conn.createStatement()) {
123129
// create a table that the action will truncate at the end of the run
@@ -228,19 +234,8 @@ private static void populateData(PreparedStatement... stmts) throws SQLException
228234
}
229235
}
230236

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-
241237
public static Connection createConnection() {
242238
try {
243-
Class.forName(DRIVER_CLASS);
244239
return DriverManager.getConnection(connectionUrl, BASE_PROPS.get(ConnectionConfig.USER),
245240
BASE_PROPS.get(ConnectionConfig.PASSWORD));
246241
} catch (Exception e) {
@@ -249,18 +244,17 @@ public static Connection createConnection() {
249244
}
250245

251246
@AfterClass
252-
public static void tearDownDB() throws SQLException {
253-
if (!tearDown) {
254-
return;
255-
}
247+
public static void tearDownDB() {
256248

257249
try (Connection conn = createConnection();
258250
Statement stmt = conn.createStatement()) {
259-
stmt.execute("DROP TABLE my_table");
260-
stmt.execute("DROP TABLE your_table");
261-
stmt.execute("DROP TABLE postActionTest");
262-
stmt.execute("DROP TABLE dbActionTest");
263-
stmt.execute("DROP TABLE MY_DEST_TABLE");
251+
executeCleanup(Arrays.<Cleanup>asList(() -> stmt.execute("DROP TABLE my_table"),
252+
() -> stmt.execute("DROP TABLE your_table"),
253+
() -> stmt.execute("DROP TABLE postActionTest"),
254+
() -> stmt.execute("DROP TABLE dbActionTest"),
255+
() -> stmt.execute("DROP TABLE MY_DEST_TABLE")), LOGGER);
256+
} catch (Exception e) {
257+
LOGGER.warn("Fail to tear down.", e);
264258
}
265259
}
266260
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package io.cdap.plugin.aurora.mysql;
1818

1919
import io.cdap.cdap.common.test.TestSuite;
20-
import org.junit.AfterClass;
21-
import org.junit.BeforeClass;
2220
import org.junit.runner.RunWith;
2321
import org.junit.runners.Suite;
2422

@@ -34,14 +32,4 @@
3432
AuroraMysqlPostActionTestRun.class
3533
})
3634
public class AuroraMysqlPluginTestSuite extends AuroraMysqlPluginTestBase {
37-
38-
@BeforeClass
39-
public static void setup() {
40-
tearDown = false;
41-
}
42-
43-
@AfterClass
44-
public static void tearDown() throws Exception {
45-
tearDown = true;
46-
}
4735
}

aurora-postgresql-plugin/pom.xml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</dependency>
6868
<dependency>
6969
<groupId>io.cdap.cdap</groupId>
70-
<artifactId>cdap-data-pipeline</artifactId>
70+
<artifactId>cdap-data-pipeline2_2.11</artifactId>
7171
</dependency>
7272
<dependency>
7373
<groupId>junit</groupId>
@@ -85,36 +85,8 @@
8585
<scope>compile</scope>
8686
</dependency>
8787
</dependencies>
88-
8988
<build>
9089
<plugins>
91-
<plugin>
92-
<groupId>org.apache.felix</groupId>
93-
<artifactId>maven-bundle-plugin</artifactId>
94-
<version>3.3.0</version>
95-
<extensions>true</extensions>
96-
<configuration>
97-
<instructions>
98-
<_exportcontents>
99-
io.cdap.plugin.*;
100-
org.apache.commons.lang;
101-
org.apache.commons.logging.*;
102-
org.codehaus.jackson.*
103-
</_exportcontents>
104-
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
105-
<Embed-Transitive>true</Embed-Transitive>
106-
<Embed-Directory>lib</Embed-Directory>
107-
</instructions>
108-
</configuration>
109-
<executions>
110-
<execution>
111-
<phase>package</phase>
112-
<goals>
113-
<goal>bundle</goal>
114-
</goals>
115-
</execution>
116-
</executions>
117-
</plugin>
11890
<plugin>
11991
<groupId>io.cdap</groupId>
12092
<artifactId>cdap-maven-plugin</artifactId>

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.google.common.base.Charsets;
2020
import com.google.common.base.Throwables;
21-
import com.google.common.collect.ImmutableMap;
2221
import com.google.common.collect.Sets;
2322
import io.cdap.cdap.api.artifact.ArtifactSummary;
2423
import io.cdap.cdap.api.plugin.PluginClass;
@@ -35,6 +34,8 @@
3534
import org.junit.BeforeClass;
3635
import org.junit.ClassRule;
3736
import org.postgresql.Driver;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
3839

3940
import java.math.BigDecimal;
4041
import java.sql.Connection;
@@ -45,43 +46,39 @@
4546
import java.sql.Statement;
4647
import java.sql.Time;
4748
import java.sql.Timestamp;
49+
import java.util.Arrays;
4850
import java.util.Calendar;
4951
import java.util.Collections;
52+
import java.util.HashMap;
5053
import java.util.Map;
5154
import java.util.TimeZone;
5255

5356
public abstract class AuroraPostgresPluginTestBase extends DatabasePluginTestBase {
57+
private static final Logger LOGGER = LoggerFactory.getLogger(AuroraPostgresPluginTestBase.class);
5458
protected static final ArtifactId DATAPIPELINE_ARTIFACT_ID = NamespaceId.DEFAULT.artifact("data-pipeline", "3.2.0");
5559
protected static final ArtifactSummary DATAPIPELINE_ARTIFACT = new ArtifactSummary("data-pipeline", "3.2.0");
5660
protected static final long CURRENT_TS = System.currentTimeMillis();
5761

5862
protected static final String JDBC_DRIVER_NAME = "postrgesql";
63+
protected static final Map<String, String> BASE_PROPS = new HashMap<>();
5964

6065
protected static String connectionUrl;
6166
protected static int year;
6267
protected static final int PRECISION = 10;
6368
protected static final int SCALE = 6;
64-
protected static boolean tearDown = true;
6569
private static int startCount;
6670

6771
@ClassRule
6872
public static final TestConfiguration CONFIG = new TestConfiguration("explore.enabled", false);
6973

70-
protected static final Map<String, String> BASE_PROPS = ImmutableMap.<String, String>builder()
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"))
76-
.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME)
77-
.build();
78-
7974
@BeforeClass
8075
public static void setupTest() throws Exception {
8176
if (startCount++ > 0) {
8277
return;
8378
}
8479

80+
getProperties();
81+
8582
Calendar calendar = Calendar.getInstance();
8683
calendar.setTime(new Date(CURRENT_TS));
8784
year = calendar.get(Calendar.YEAR);
@@ -111,6 +108,15 @@ public static void setupTest() throws Exception {
111108
prepareTestData(conn);
112109
}
113110

111+
private static void getProperties() {
112+
BASE_PROPS.put(ConnectionConfig.HOST, getPropertyOrSkip("auroraPostgresql.clusterEndpoint"));
113+
BASE_PROPS.put(ConnectionConfig.PORT, getPropertyOrSkip("auroraPostgresql.port"));
114+
BASE_PROPS.put(ConnectionConfig.DATABASE, getPropertyOrSkip("auroraPostgresql.database"));
115+
BASE_PROPS.put(ConnectionConfig.USER, getPropertyOrSkip("auroraPostgresql.username"));
116+
BASE_PROPS.put(ConnectionConfig.PASSWORD, getPropertyOrSkip("auroraPostgresql.password"));
117+
BASE_PROPS.put(ConnectionConfig.JDBC_PLUGIN_NAME, JDBC_DRIVER_NAME);
118+
}
119+
114120
protected static void createTestTables(Connection conn) throws SQLException {
115121
try (Statement stmt = conn.createStatement()) {
116122
// create a table that the action will truncate at the end of the run
@@ -189,16 +195,6 @@ private static void populateData(PreparedStatement... stmts) throws SQLException
189195
}
190196
}
191197

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-
202198
public static Connection createConnection() {
203199
try {
204200
Class.forName(Driver.class.getCanonicalName());
@@ -210,18 +206,16 @@ public static Connection createConnection() {
210206
}
211207

212208
@AfterClass
213-
public static void tearDownDB() throws SQLException {
214-
if (!tearDown) {
215-
return;
216-
}
217-
209+
public static void tearDownDB() {
218210
try (Connection conn = createConnection();
219211
Statement stmt = conn.createStatement()) {
220-
stmt.execute("DROP TABLE my_table");
221-
stmt.execute("DROP TABLE your_table");
222-
stmt.execute("DROP TABLE \"postActionTest\"");
223-
stmt.execute("DROP TABLE \"dbActionTest\"");
224-
stmt.execute("DROP TABLE \"MY_DEST_TABLE\"");
212+
executeCleanup(Arrays.<Cleanup>asList(() -> stmt.execute("DROP TABLE my_table"),
213+
() -> stmt.execute("DROP TABLE your_table"),
214+
() -> stmt.execute("DROP TABLE postActionTest"),
215+
() -> stmt.execute("DROP TABLE dbActionTest"),
216+
() -> stmt.execute("DROP TABLE MY_DEST_TABLE")), LOGGER);
217+
} catch (Exception e) {
218+
LOGGER.warn("Fail to tear down.", e);
225219
}
226220
}
227221
}

0 commit comments

Comments
 (0)