SQOOP-3411: PostgresMetaConnectIncrementalImportTest fails if metastore tables are absent from the database
This closes #51
(Szabolcs Vasas via Boglarka Egyed)
diff --git a/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java b/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java
index 53f55d1..3dec9f3 100644
--- a/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java
+++ b/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java
@@ -68,11 +68,24 @@
@Before
public void setUp() {
super.setUp();
+ try {
+ initMetastoreConnection();
+ resetTable();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ resetMetastoreSchema();
}
@After
public void tearDown() {
super.tearDown();
+ resetMetastoreSchema();
+ try {
+ cm.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
}
protected String[] getIncrementalJob(String metaConnectString, String metaUser, String metaPass) {
@@ -123,12 +136,6 @@
@Test
public void testIncrementalJob() throws SQLException {
- resetTable();
-
- initMetastoreConnection();
-
- resetMetastoreSchema();
-
//creates Job
createJob();
@@ -148,8 +155,6 @@
//Ensures the last incremental value is updated correctly.
checkIncrementalState(2);
-
- cm.close();
}
private void checkIncrementalState(int expected) throws SQLException {
@@ -195,9 +200,13 @@
metastoreStatement.execute("DROP TABLE " + cm.escapeTableName("SQOOP_ROOT"));
metastoreStatement.execute("DROP TABLE " + cm.escapeTableName("SQOOP_SESSIONS"));
connMeta.commit();
- }
- catch (Exception e) {
- LOG.error( e.getLocalizedMessage() );
+ } catch (Exception e) {
+ LOG.error(e.getLocalizedMessage());
+ try {
+ connMeta.rollback();
+ } catch (SQLException innerException) {
+ LOG.error(innerException.getLocalizedMessage());
+ }
}
}