From 696187bb16ae31ca2aa78be93c342604cc1290d1 Mon Sep 17 00:00:00 2001 From: Boglarka Egyed Date: Mon, 26 Nov 2018 12:05:03 +0100 Subject: [PATCH] SQOOP-3411: PostgresMetaConnectIncrementalImportTest fails if metastore tables are absent from the database This closes #51 (Szabolcs Vasas via Boglarka Egyed) --- .../MetaConnectIncrementalImportTestBase.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java b/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java index 53f55d1b..3dec9f37 100644 --- a/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java +++ b/src/test/org/apache/sqoop/metastore/MetaConnectIncrementalImportTestBase.java @@ -68,11 +68,24 @@ public MetaConnectIncrementalImportTestBase(String metaConnectString, String met @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 @@ protected String[] getExecJob(String metaConnectString, String metaUser, String @Test public void testIncrementalJob() throws SQLException { - resetTable(); - - initMetastoreConnection(); - - resetMetastoreSchema(); - //creates Job createJob(); @@ -148,8 +155,6 @@ public void testIncrementalJob() throws SQLException { //Ensures the last incremental value is updated correctly. checkIncrementalState(2); - - cm.close(); } private void checkIncrementalState(int expected) throws SQLException { @@ -195,9 +200,13 @@ private void resetMetastoreSchema() { 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()); + } } }