From 8147d262d8ebb6b55e015d2e1f90adff4d2bbb30 Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Fri, 22 Jul 2011 20:03:39 +0000 Subject: [PATCH] Enable findbugs on build and fix all warnings. Some spurious warnings (and inconsequential warnings in test code) have been disabled by src/test/findbugsExcludeFile.xml. From: Aaron Kimball git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149874 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 49 ++++++++++- .../sqoop/manager/DirectMySQLManager.java | 2 +- .../manager/DirectPostgresqlManager.java | 1 - .../hadoop/sqoop/manager/MySQLManager.java | 13 ++- .../sqoop/manager/PostgresqlManager.java | 4 +- .../hadoop/sqoop/manager/SqlManager.java | 2 +- .../sqoop/mapreduce/MySQLDumpInputFormat.java | 3 - .../sqoop/mapreduce/MySQLDumpMapper.java | 4 +- .../hadoop/sqoop/util/NullAsyncSink.java | 2 +- src/test/findbugsExcludeFile.xml | 67 +++++++++++++++ .../apache/hadoop/sqoop/TestConnFactory.java | 2 +- .../org/apache/hadoop/sqoop/TestExport.java | 36 +++++--- .../io/TestSplittableBufferedWriter.java | 86 +++++++++++++++---- .../sqoop/lib/TestLargeObjectLoader.java | 9 +- .../hadoop/sqoop/lib/TestRecordParser.java | 33 +++---- .../hadoop/sqoop/manager/MySQLAuthTest.java | 28 ++++-- .../hadoop/sqoop/manager/MySQLCompatTest.java | 9 +- .../sqoop/manager/OracleManagerTest.java | 8 ++ .../hadoop/sqoop/manager/PostgresqlTest.java | 7 ++ .../hadoop/sqoop/orm/TestClassWriter.java | 15 ++-- .../sqoop/testutil/BaseSqoopTestCase.java | 9 +- .../sqoop/testutil/ExportJobTestCase.java | 86 +++++++++++++------ .../sqoop/testutil/HsqldbTestServer.java | 9 +- .../hadoop/sqoop/testutil/MockResultSet.java | 13 +-- 24 files changed, 375 insertions(+), 122 deletions(-) create mode 100644 src/test/findbugsExcludeFile.xml diff --git a/build.xml b/build.xml index 587e0cd3..cfdd5810 100644 --- a/build.xml +++ b/build.xml @@ -38,6 +38,7 @@ + @@ -52,6 +53,15 @@ + + + + + + @@ -93,7 +103,7 @@ - + @@ -118,12 +128,12 @@ - + @@ -228,6 +238,9 @@ timeout="${test.timeout}" dir="${build.test}/data"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/org/apache/hadoop/sqoop/TestConnFactory.java b/src/test/org/apache/hadoop/sqoop/TestConnFactory.java index 9f0aec34..908557ee 100644 --- a/src/test/org/apache/hadoop/sqoop/TestConnFactory.java +++ b/src/test/org/apache/hadoop/sqoop/TestConnFactory.java @@ -52,7 +52,7 @@ public void testExceptionForNoManager() { ConnFactory factory = new ConnFactory(conf); try { - ConnManager manager = factory.getManager(new SqoopOptions()); + factory.getManager(new SqoopOptions()); fail("factory.getManager() expected to throw IOException"); } catch (IOException ioe) { // Expected this. Test passes. diff --git a/src/test/org/apache/hadoop/sqoop/TestExport.java b/src/test/org/apache/hadoop/sqoop/TestExport.java index a5b36956..71c4867e 100644 --- a/src/test/org/apache/hadoop/sqoop/TestExport.java +++ b/src/test/org/apache/hadoop/sqoop/TestExport.java @@ -238,9 +238,12 @@ public void createTable(ColumnGenerator... extraColumns) throws SQLException { PreparedStatement statement = conn.prepareStatement( "DROP TABLE " + getTableName() + " IF EXISTS", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - statement.executeUpdate(); - conn.commit(); - statement.close(); + try { + statement.executeUpdate(); + conn.commit(); + } finally { + statement.close(); + } StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE "); @@ -254,9 +257,12 @@ public void createTable(ColumnGenerator... extraColumns) throws SQLException { statement = conn.prepareStatement(sb.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - statement.executeUpdate(); - conn.commit(); - statement.close(); + try { + statement.executeUpdate(); + conn.commit(); + } finally { + statement.close(); + } } /** Removing an existing table directory from the filesystem */ @@ -278,12 +284,18 @@ private void assertColValForRowId(int id, String colName, String expectedVal) PreparedStatement statement = conn.prepareStatement( "SELECT " + colName + " FROM " + getTableName() + " WHERE id = " + id, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = statement.executeQuery(); - rs.next(); - - String actualVal = rs.getString(1); - rs.close(); - statement.close(); + String actualVal = null; + try { + ResultSet rs = statement.executeQuery(); + try { + rs.next(); + actualVal = rs.getString(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } assertEquals("Got unexpected column value", expectedVal, actualVal); } diff --git a/src/test/org/apache/hadoop/sqoop/io/TestSplittableBufferedWriter.java b/src/test/org/apache/hadoop/sqoop/io/TestSplittableBufferedWriter.java index 8f99951c..52687443 100644 --- a/src/test/org/apache/hadoop/sqoop/io/TestSplittableBufferedWriter.java +++ b/src/test/org/apache/hadoop/sqoop/io/TestSplittableBufferedWriter.java @@ -112,6 +112,11 @@ private void verifyFileContents(InputStream is, String [] lines) r.readLine()); } finally { r.close(); + try { + is.close(); + } catch (IOException ioe) { + // ignore IOE; may be closed by reader. + } } } @@ -128,15 +133,23 @@ private void verifyFileDoesNotExist(Path p) throws IOException { public void testNonSplittingTextFile() throws IOException { SplittingOutputStream os = new SplittingOutputStream(getConf(), getWritePath(), "nonsplit-", 0, false); - SplittableBufferedWriter w = new SplittableBufferedWriter(os, true); try { - w.allowSplit(); - w.write("This is a string!"); - w.newLine(); - w.write("This is another string!"); - w.allowSplit(); + SplittableBufferedWriter w = new SplittableBufferedWriter(os, true); + try { + w.allowSplit(); + w.write("This is a string!"); + w.newLine(); + w.write("This is another string!"); + w.allowSplit(); + } finally { + w.close(); + } } finally { - w.close(); + try { + os.close(); + } catch (IOException ioe) { + // Ignored; may be thrown because w is already closed. + } } // Ensure we made exactly one file. @@ -150,8 +163,18 @@ public void testNonSplittingTextFile() throws IOException { "This is a string!", "This is another string!", }; - verifyFileContents(new FileInputStream(new File(getWriteDir(), - "nonsplit-00000")), expectedLines); + + InputStream fis = new FileInputStream(new File(getWriteDir(), + "nonsplit-00000")); + try { + verifyFileContents(fis, expectedLines); + } finally { + try { + fis.close(); + } catch (IOException ioe) { + // Ignored; may be closed by verifyFileContents(). + } + } } public void testNonSplittingGzipFile() throws IOException { @@ -187,14 +210,22 @@ public void testNonSplittingGzipFile() throws IOException { public void testSplittingTextFile() throws IOException { SplittingOutputStream os = new SplittingOutputStream(getConf(), getWritePath(), "split-", 10, false); - SplittableBufferedWriter w = new SplittableBufferedWriter(os, true); try { - w.allowSplit(); - w.write("This is a string!"); - w.newLine(); - w.write("This is another string!"); + SplittableBufferedWriter w = new SplittableBufferedWriter(os, true); + try { + w.allowSplit(); + w.write("This is a string!"); + w.newLine(); + w.write("This is another string!"); + } finally { + w.close(); + } } finally { - w.close(); + try { + os.close(); + } catch (IOException ioe) { + // Ignored; may be thrown because w is already closed. + } } // Ensure we made exactly two files. @@ -209,14 +240,31 @@ public void testSplittingTextFile() throws IOException { String [] expectedLines0 = { "This is a string!" }; - verifyFileContents(new FileInputStream(new File(getWriteDir(), - "split-00000")), expectedLines0); + InputStream fis = new FileInputStream(new File(getWriteDir(), + "split-00000")); + try { + verifyFileContents(fis, expectedLines0); + } finally { + try { + fis.close(); + } catch (IOException ioe) { + // ignored; may be generated because fis closed in verifyFileContents. + } + } String [] expectedLines1 = { "This is another string!", }; - verifyFileContents(new FileInputStream(new File(getWriteDir(), - "split-00001")), expectedLines1); + fis = new FileInputStream(new File(getWriteDir(), "split-00001")); + try { + verifyFileContents(fis, expectedLines1); + } finally { + try { + fis.close(); + } catch (IOException ioe) { + // Ignored; may be thrown because it's closed in verifyFileContents. + } + } } public void testSplittingGzipFile() throws IOException { diff --git a/src/test/org/apache/hadoop/sqoop/lib/TestLargeObjectLoader.java b/src/test/org/apache/hadoop/sqoop/lib/TestLargeObjectLoader.java index 13af3aa9..c12b84d3 100644 --- a/src/test/org/apache/hadoop/sqoop/lib/TestLargeObjectLoader.java +++ b/src/test/org/apache/hadoop/sqoop/lib/TestLargeObjectLoader.java @@ -135,9 +135,10 @@ public void testReadBlobRef() assertNotNull(blob); assertFalse(blob.isExternal()); byte [] data = blob.getData(); - assertEquals(MockResultSet.BLOB_DATA.length, data.length); + byte [] blobData = MockResultSet.BLOB_DATA(); + assertEquals(blobData.length, data.length); for (int i = 0; i < data.length; i++) { - assertEquals(MockResultSet.BLOB_DATA[i], data[i]); + assertEquals(blobData[i], data[i]); } // LOBs bigger than 4 bytes are now external. @@ -151,9 +152,9 @@ public void testReadBlobRef() int bytes = is.read(buf, 0, 4096); is.close(); - assertEquals(MockResultSet.BLOB_DATA.length, bytes); + assertEquals(blobData.length, bytes); for (int i = 0; i < bytes; i++) { - assertEquals(MockResultSet.BLOB_DATA[i], buf[i]); + assertEquals(blobData[i], buf[i]); } } } diff --git a/src/test/org/apache/hadoop/sqoop/lib/TestRecordParser.java b/src/test/org/apache/hadoop/sqoop/lib/TestRecordParser.java index 8be72fb4..c281472e 100644 --- a/src/test/org/apache/hadoop/sqoop/lib/TestRecordParser.java +++ b/src/test/org/apache/hadoop/sqoop/lib/TestRecordParser.java @@ -41,18 +41,20 @@ private void assertListsEqual(String msg, List expected, List ac } fail(msg); - } - - if (expected == null && actual == null) { + } else if (expected == null && actual == null) { return; // ok. Both null; nothing to do. } + assert(null != expected); + assert(null != actual); + int expectedLen = expected.size(); int actualLen = actual.size(); if (expectedLen != actualLen) { if (null == msg) { - msg = "Expected list of length " + expectedLen + "; got " + actualLen; + msg = "Expected list of length " + expectedLen + + "; got " + actualLen; } fail(msg); @@ -63,17 +65,19 @@ private void assertListsEqual(String msg, List expected, List ac String expectedElem = expected.get(i); String actualElem = actual.get(i); - if (expectedElem == null && actualElem != null) { - if (null == msg) { - msg = "Expected null element at position " + i + "; got [" + actualElem + "]"; + if (expectedElem == null) { + if (actualElem != null) { + if (null == msg) { + msg = "Expected null element at position " + i + + "; got [" + actualElem + "]"; + } + + fail(msg); } - - fail(msg); - } - - if (!expectedElem.equals(actualElem)) { + } else if (!expectedElem.equals(actualElem)) { if (null == msg) { - msg = "Expected [" + expectedElem + "] at position " + i + "; got [" + actualElem + "]"; + msg = "Expected [" + expectedElem + "] at position " + i + + "; got [" + actualElem + "]"; } fail(msg); @@ -235,7 +239,6 @@ public void testRequiredQuotes1() throws RecordParser.ParseError { public void testRequiredQuotes2() throws RecordParser.ParseError { RecordParser parser = new RecordParser(',', '\n', '\"', '\\', true); - String [] strings = { "field1", "field2" }; try { parser.parseRecord("\"field1\",field2"); fail("Expected parse error for required quotes"); @@ -246,7 +249,6 @@ public void testRequiredQuotes2() throws RecordParser.ParseError { public void testRequiredQuotes3() throws RecordParser.ParseError { RecordParser parser = new RecordParser(',', '\n', '\"', '\\', true); - String [] strings = { "field1", "field2" }; try { parser.parseRecord("field1,\"field2\""); fail("Expected parse error for required quotes"); @@ -257,7 +259,6 @@ public void testRequiredQuotes3() throws RecordParser.ParseError { public void testRequiredQuotes4() throws RecordParser.ParseError { RecordParser parser = new RecordParser(',', '\n', '\"', '\\', true); - String [] strings = { "field1", "field2" }; try { parser.parseRecord("field1,\"field2\"\n"); fail("Expected parse error for required quotes"); diff --git a/src/test/org/apache/hadoop/sqoop/manager/MySQLAuthTest.java b/src/test/org/apache/hadoop/sqoop/manager/MySQLAuthTest.java index 35b83867..8aa27f0a 100644 --- a/src/test/org/apache/hadoop/sqoop/manager/MySQLAuthTest.java +++ b/src/test/org/apache/hadoop/sqoop/manager/MySQLAuthTest.java @@ -77,8 +77,14 @@ public class MySQLAuthTest extends ImportJobTestCase { // instance variables populated during setUp, used during tests private DirectMySQLManager manager; + @Override + protected boolean useHsqldbTestServer() { + return false; + } + @Before public void setUp() { + super.setUp(); SqoopOptions options = new SqoopOptions(AUTH_CONNECT_STRING, AUTH_TABLE_NAME); options.setUsername(AUTH_TEST_USER); options.setPassword(AUTH_TEST_PASS); @@ -123,6 +129,7 @@ public void setUp() { @After public void tearDown() { + super.tearDown(); try { manager.close(); } catch (SQLException sqlE) { @@ -242,15 +249,18 @@ private void dropTimestampTables() throws SQLException { connection.setAutoCommit(false); st = connection.createStatement(); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable0"); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable1"); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable2"); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable3"); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable4"); - st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable5"); - connection.commit(); - st.close(); - connection.close(); + try { + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable0"); + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable1"); + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable2"); + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable3"); + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable4"); + st.executeUpdate("DROP TABLE IF EXISTS mysqlTimestampTable5"); + connection.commit(); + } finally { + st.close(); + connection.close(); + } } public void doZeroTimestampTest(int testNum, boolean expectSuccess, diff --git a/src/test/org/apache/hadoop/sqoop/manager/MySQLCompatTest.java b/src/test/org/apache/hadoop/sqoop/manager/MySQLCompatTest.java index 03017ae0..619d0f40 100644 --- a/src/test/org/apache/hadoop/sqoop/manager/MySQLCompatTest.java +++ b/src/test/org/apache/hadoop/sqoop/manager/MySQLCompatTest.java @@ -66,9 +66,12 @@ protected void dropTableIfExists(String table) throws SQLException { PreparedStatement statement = conn.prepareStatement( "DROP TABLE IF EXISTS " + table, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - statement.executeUpdate(); - statement.close(); - conn.commit(); + try { + statement.executeUpdate(); + conn.commit(); + } finally { + statement.close(); + } } @Override diff --git a/src/test/org/apache/hadoop/sqoop/manager/OracleManagerTest.java b/src/test/org/apache/hadoop/sqoop/manager/OracleManagerTest.java index 3ba137d8..d555c270 100644 --- a/src/test/org/apache/hadoop/sqoop/manager/OracleManagerTest.java +++ b/src/test/org/apache/hadoop/sqoop/manager/OracleManagerTest.java @@ -89,9 +89,16 @@ public class OracleManagerTest extends ImportJobTestCase { // instance variables populated during setUp, used during tests private OracleManager manager; + + @Override + protected boolean useHsqldbTestServer() { + return false; + } @Before public void setUp() { + super.setUp(); + SqoopOptions options = new SqoopOptions(OracleUtils.CONNECT_STRING, TABLE_NAME); OracleUtils.setOracleAuth(options); @@ -152,6 +159,7 @@ public void setUp() { @After public void tearDown() { + super.tearDown(); try { manager.close(); } catch (SQLException sqlE) { diff --git a/src/test/org/apache/hadoop/sqoop/manager/PostgresqlTest.java b/src/test/org/apache/hadoop/sqoop/manager/PostgresqlTest.java index acd46f24..e3b5513d 100644 --- a/src/test/org/apache/hadoop/sqoop/manager/PostgresqlTest.java +++ b/src/test/org/apache/hadoop/sqoop/manager/PostgresqlTest.java @@ -81,8 +81,15 @@ public class PostgresqlTest extends ImportJobTestCase { static final String TABLE_NAME = "EMPLOYEES_PG"; static final String CONNECT_STRING = HOST_URL + DATABASE_NAME; + @Override + protected boolean useHsqldbTestServer() { + return false; + } + @Before public void setUp() { + super.setUp(); + LOG.debug("Setting up another postgresql test..."); SqoopOptions options = new SqoopOptions(CONNECT_STRING, TABLE_NAME); diff --git a/src/test/org/apache/hadoop/sqoop/orm/TestClassWriter.java b/src/test/org/apache/hadoop/sqoop/orm/TestClassWriter.java index 8ee0b9be..1d2fa72f 100644 --- a/src/test/org/apache/hadoop/sqoop/orm/TestClassWriter.java +++ b/src/test/org/apache/hadoop/sqoop/orm/TestClassWriter.java @@ -297,11 +297,16 @@ public void testWeirdColumnNames() throws SQLException { String tableName = HsqldbTestServer.getTableName(); Connection connection = testServer.getConnection(); Statement st = connection.createStatement(); - st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS"); - st.executeUpdate("CREATE TABLE " + tableName + " (class INT, \"9field\" INT)"); - st.executeUpdate("INSERT INTO " + tableName + " VALUES(42, 41)"); - connection.commit(); - connection.close(); + try { + st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS"); + st.executeUpdate("CREATE TABLE " + tableName + + " (class INT, \"9field\" INT)"); + st.executeUpdate("INSERT INTO " + tableName + " VALUES(42, 41)"); + connection.commit(); + } finally { + st.close(); + connection.close(); + } String [] argv = { "--bindir", diff --git a/src/test/org/apache/hadoop/sqoop/testutil/BaseSqoopTestCase.java b/src/test/org/apache/hadoop/sqoop/testutil/BaseSqoopTestCase.java index d1d25dde..014b7e99 100644 --- a/src/test/org/apache/hadoop/sqoop/testutil/BaseSqoopTestCase.java +++ b/src/test/org/apache/hadoop/sqoop/testutil/BaseSqoopTestCase.java @@ -217,9 +217,12 @@ protected void dropTableIfExists(String table) throws SQLException { PreparedStatement statement = conn.prepareStatement( "DROP TABLE " + table + " IF EXISTS", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - statement.executeUpdate(); - statement.close(); - conn.commit(); + try { + statement.executeUpdate(); + conn.commit(); + } finally { + statement.close(); + } } /** diff --git a/src/test/org/apache/hadoop/sqoop/testutil/ExportJobTestCase.java b/src/test/org/apache/hadoop/sqoop/testutil/ExportJobTestCase.java index 2b36d199..2f9561d1 100644 --- a/src/test/org/apache/hadoop/sqoop/testutil/ExportJobTestCase.java +++ b/src/test/org/apache/hadoop/sqoop/testutil/ExportJobTestCase.java @@ -91,11 +91,18 @@ protected int getMinRowId() throws SQLException { PreparedStatement statement = conn.prepareStatement( "SELECT MIN(id) FROM " + getTableName(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = statement.executeQuery(); - rs.next(); - int minVal = rs.getInt(1); - rs.close(); - statement.close(); + int minVal = 0; + try { + ResultSet rs = statement.executeQuery(); + try { + rs.next(); + minVal = rs.getInt(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } return minVal; } @@ -106,11 +113,18 @@ protected int getMaxRowId() throws SQLException { PreparedStatement statement = conn.prepareStatement( "SELECT MAX(id) FROM " + getTableName(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = statement.executeQuery(); - rs.next(); - int maxVal = rs.getInt(1); - rs.close(); - statement.close(); + int maxVal = 0; + try { + ResultSet rs = statement.executeQuery(); + try { + rs.next(); + maxVal = rs.getInt(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } return maxVal; } @@ -128,11 +142,19 @@ protected void verifyExport(int expectedNumRecords) throws IOException, SQLExcep PreparedStatement statement = conn.prepareStatement( "SELECT COUNT(*) FROM " + getTableName(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = statement.executeQuery(); - rs.next(); - int actualNumRecords = rs.getInt(1); - rs.close(); - statement.close(); + int actualNumRecords = 0; + ResultSet rs = null; + try { + rs = statement.executeQuery(); + try { + rs.next(); + actualNumRecords = rs.getInt(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } assertEquals("Got back unexpected row count", expectedNumRecords, actualNumRecords); @@ -149,22 +171,36 @@ protected void verifyExport(int expectedNumRecords) throws IOException, SQLExcep statement = conn.prepareStatement("SELECT msg FROM " + getTableName() + " WHERE id = " + minVal, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - rs = statement.executeQuery(); - rs.next(); - String minMsg = rs.getString(1); - rs.close(); - statement.close(); + String minMsg = ""; + try { + rs = statement.executeQuery(); + try { + rs.next(); + minMsg = rs.getString(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } assertEquals("Invalid msg field for min value", getMsgPrefix() + minVal, minMsg); statement = conn.prepareStatement("SELECT msg FROM " + getTableName() + " WHERE id = " + maxVal, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - rs = statement.executeQuery(); - rs.next(); - String maxMsg = rs.getString(1); - rs.close(); - statement.close(); + String maxMsg = ""; + try { + rs = statement.executeQuery(); + try { + rs.next(); + maxMsg = rs.getString(1); + } finally { + rs.close(); + } + } finally { + statement.close(); + } assertEquals("Invalid msg field for min value", getMsgPrefix() + maxVal, maxMsg); } diff --git a/src/test/org/apache/hadoop/sqoop/testutil/HsqldbTestServer.java b/src/test/org/apache/hadoop/sqoop/testutil/HsqldbTestServer.java index c2ba6ad5..51512373 100644 --- a/src/test/org/apache/hadoop/sqoop/testutil/HsqldbTestServer.java +++ b/src/test/org/apache/hadoop/sqoop/testutil/HsqldbTestServer.java @@ -209,9 +209,12 @@ public void dropExistingSchema() throws SQLException { Connection conn = mgr.getConnection(); for (String table : tables) { Statement s = conn.createStatement(); - s.executeUpdate("DROP TABLE " + table); - conn.commit(); - s.close(); + try { + s.executeUpdate("DROP TABLE " + table); + conn.commit(); + } finally { + s.close(); + } } } } diff --git a/src/test/org/apache/hadoop/sqoop/testutil/MockResultSet.java b/src/test/org/apache/hadoop/sqoop/testutil/MockResultSet.java index 812fb2f6..33f3afb1 100644 --- a/src/test/org/apache/hadoop/sqoop/testutil/MockResultSet.java +++ b/src/test/org/apache/hadoop/sqoop/testutil/MockResultSet.java @@ -50,8 +50,10 @@ */ public class MockResultSet implements ResultSet { - public static final byte [] BLOB_DATA = { 0x0, 0x1, 0x2, 0x3, - 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF }; + public static final byte [] BLOB_DATA() { + return new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, + 0xA, 0xB, 0xC, 0xD, 0xE, 0xF }; + } public static final String CLOB_DATA = "This is the mock clob data!"; @@ -60,7 +62,7 @@ public class MockResultSet implements ResultSet { */ public static class MockBlob implements Blob { public InputStream getBinaryStream() { - return new ByteArrayInputStream(BLOB_DATA); + return new ByteArrayInputStream(BLOB_DATA()); } public InputStream getBinaryStream(long pos, long len) { @@ -71,14 +73,15 @@ public InputStream getBinaryStream(long pos, long len) { byte [] bytes = new byte[length]; int start = (int) pos - 1; // SQL uses 1-based arrays!! + byte [] blobData = BLOB_DATA(); for (int i = 0; i < length; i++) { - bytes[i] = BLOB_DATA[i + start]; + bytes[i] = blobData[i + start]; } return bytes; } public long length() { - return BLOB_DATA.length; + return BLOB_DATA().length; }