From e1588d41367287af05ab3b5bd33dc1df80960024 Mon Sep 17 00:00:00 2001 From: smarthi Date: Tue, 19 Jan 2016 12:00:02 -0500 Subject: [PATCH] [NIFI-1411] - TestJdbcTypesDerby: java.sql.SQLSyntaxErrorException: TYPE 'DATETIME' does not exist --- .../standard/util/TestJdbcCommon.java | 30 +++++++++---------- .../standard/util/TestJdbcHugeStream.java | 22 +++++++------- .../standard/util/TestJdbcTypesDerby.java | 26 ++++++++-------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcCommon.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcCommon.java index 266d4265e9..7b29cf8eec 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcCommon.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcCommon.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; @@ -44,14 +43,17 @@ import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.DatumReader; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; public class TestJdbcCommon { - final static String DB_LOCATION = "target/db"; + @Rule + public TemporaryFolder folder = new TemporaryFolder(); @BeforeClass public static void setup() { @@ -65,10 +67,9 @@ public class TestJdbcCommon { public void testCreateSchema() throws ClassNotFoundException, SQLException { // remove previous test database, if any - final File dbLocation = new File(DB_LOCATION); - dbLocation.delete(); + folder.delete(); - final Connection con = createConnection(); + final Connection con = createConnection(folder.getRoot().getAbsolutePath()); final Statement st = con.createStatement(); try { @@ -102,10 +103,9 @@ public class TestJdbcCommon { @Test public void testConvertToBytes() throws ClassNotFoundException, SQLException, IOException { // remove previous test database, if any - final File dbLocation = new File(DB_LOCATION); - dbLocation.delete(); + folder.delete(); - final Connection con = createConnection(); + final Connection con = createConnection(folder.getRoot().getAbsolutePath()); final Statement st = con.createStatement(); try { @@ -136,8 +136,8 @@ public class TestJdbcCommon { final InputStream instream = new ByteArrayInputStream(serializedBytes); - final DatumReader datumReader = new GenericDatumReader(); - try (final DataFileStream dataFileReader = new DataFileStream(instream, datumReader)) { + final DatumReader datumReader = new GenericDatumReader<>(); + try (final DataFileStream dataFileReader = new DataFileStream<>(instream, datumReader)) { GenericRecord record = null; while (dataFileReader.hasNext()) { // Reuse record object by passing it to next(). This saves us from @@ -282,8 +282,8 @@ public class TestJdbcCommon { final InputStream instream = new ByteArrayInputStream(serializedBytes); - final DatumReader datumReader = new GenericDatumReader(); - try (final DataFileStream dataFileReader = new DataFileStream(instream, datumReader)) { + final DatumReader datumReader = new GenericDatumReader<>(); + try (final DataFileStream dataFileReader = new DataFileStream<>(instream, datumReader)) { GenericRecord record = null; while (dataFileReader.hasNext()) { record = dataFileReader.next(record); @@ -300,11 +300,9 @@ public class TestJdbcCommon { assertNotNull(clazz); } - private Connection createConnection() throws ClassNotFoundException, SQLException { - + private Connection createConnection(String location) throws ClassNotFoundException, SQLException { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); - final Connection con = DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";create=true"); - return con; + return DriverManager.getConnection("jdbc:derby:" + location + ";create=true"); } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcHugeStream.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcHugeStream.java index 0eb7dce884..19161ee3bc 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcHugeStream.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcHugeStream.java @@ -18,7 +18,6 @@ package org.apache.nifi.processors.standard.util; import static org.junit.Assert.assertEquals; -import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -36,7 +35,9 @@ import org.apache.avro.generic.GenericDatumReader; import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.DatumReader; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; /** * Test streaming using large number of result set rows. 1. Read data from @@ -52,7 +53,8 @@ import org.junit.Test; */ public class TestJdbcHugeStream { - final static String DB_LOCATION = "target/db"; + @Rule + public TemporaryFolder folder = new TemporaryFolder(); @BeforeClass public static void setup() { @@ -63,10 +65,9 @@ public class TestJdbcHugeStream { public void readSend2StreamHuge_FileBased() throws ClassNotFoundException, SQLException, IOException { // remove previous test database, if any - final File dbLocation = new File(DB_LOCATION); - dbLocation.delete(); + folder.delete(); - try (final Connection con = createConnection()) { + try (final Connection con = createConnection(folder.getRoot().getAbsolutePath())) { loadTestData2Database(con, 100, 100, 100); try (final Statement st = con.createStatement()) { @@ -127,17 +128,17 @@ public class TestJdbcHugeStream { // tables may not exist, this is not serious problem. try { st.executeUpdate(dropPersons); - } catch (final Exception e) { + } catch (final Exception ignored) { } try { st.executeUpdate(dropProducts); - } catch (final Exception e) { + } catch (final Exception ignored) { } try { st.executeUpdate(dropRelationships); - } catch (final Exception e) { + } catch (final Exception ignored) { } st.executeUpdate(createPersons); @@ -186,10 +187,9 @@ public class TestJdbcHugeStream { return new String(text); } - private Connection createConnection() throws ClassNotFoundException, SQLException { + private Connection createConnection(String location) throws ClassNotFoundException, SQLException { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); - final Connection con = DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";create=true"); - return con; + return DriverManager.getConnection("jdbc:derby:" + location + ";create=true"); } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesDerby.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesDerby.java index fc2bccd782..79a1c84fc2 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesDerby.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesDerby.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertNotNull; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; @@ -35,7 +34,9 @@ import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.DatumReader; import org.junit.BeforeClass; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; /** * Useless test, Derby is so much different from MySQL @@ -46,7 +47,8 @@ import org.junit.Test; @Ignore public class TestJdbcTypesDerby { - final static String DB_LOCATION = "target/db"; + @Rule + public TemporaryFolder folder = new TemporaryFolder(); @BeforeClass public static void setup() { @@ -59,9 +61,9 @@ public class TestJdbcTypesDerby { + " password varchar(255) DEFAULT NULL, " + " activation_code varchar(255) DEFAULT NULL, " + " forgotten_password_code varchar(255) DEFAULT NULL, " - + " forgotten_password_time datetime DEFAULT NULL, " - + " created datetime NOT NULL, " - + " active tinyint NOT NULL DEFAULT 0, " + + " forgotten_password_time DATE DEFAULT NULL, " + + " created DATE NOT NULL, " + + " active CHAR NOT NULL DEFAULT 'N', " + " home_module_id int DEFAULT NULL, " + " PRIMARY KEY (id) ) " ; @@ -70,10 +72,9 @@ public class TestJdbcTypesDerby { @Test public void testSQLTypesMapping() throws ClassNotFoundException, SQLException, IOException { // remove previous test database, if any - final File dbLocation = new File(DB_LOCATION); - dbLocation.delete(); + folder.delete(); - final Connection con = createConnection(); + final Connection con = createConnection(folder.getRoot().getAbsolutePath()); final Statement st = con.createStatement(); try { @@ -103,8 +104,8 @@ public class TestJdbcTypesDerby { final InputStream instream = new ByteArrayInputStream(serializedBytes); - final DatumReader datumReader = new GenericDatumReader(); - try (final DataFileStream dataFileReader = new DataFileStream(instream, datumReader)) { + final DatumReader datumReader = new GenericDatumReader<>(); + try (final DataFileStream dataFileReader = new DataFileStream<>(instream, datumReader)) { GenericRecord record = null; while (dataFileReader.hasNext()) { // Reuse record object by passing it to next(). This saves us from @@ -123,11 +124,10 @@ public class TestJdbcTypesDerby { assertNotNull(clazz); } - private Connection createConnection() throws ClassNotFoundException, SQLException { + private Connection createConnection(String location) throws ClassNotFoundException, SQLException { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); - final Connection con = DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";create=true"); - return con; + return DriverManager.getConnection("jdbc:derby:" + location + ";create=true"); } }