nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ijokaruma...@apache.org
Subject nifi git commit: NIFI-4830: Fixed logic errors in BLOB/CLOB processing in JdbcCommon
Date Fri, 09 Feb 2018 02:36:10 GMT
Repository: nifi
Updated Branches:
  refs/heads/master 4428fe28b -> 7d6bbce12


NIFI-4830: Fixed logic errors in BLOB/CLOB processing in JdbcCommon

This closes #2459.

Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/7d6bbce1
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/7d6bbce1
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/7d6bbce1

Branch: refs/heads/master
Commit: 7d6bbce123a75eb889ee6d2c8b2a0ed786b78cb7
Parents: 4428fe2
Author: Matthew Burgess <mattyb149@apache.org>
Authored: Thu Feb 8 14:02:58 2018 -0500
Committer: Koji Kawamura <ijokarumawak@apache.org>
Committed: Fri Feb 9 11:45:12 2018 +0900

----------------------------------------------------------------------
 .../nifi/processors/standard/util/JdbcCommon.java   |  4 ++--
 .../processors/standard/util/TestJdbcCommon.java    | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/7d6bbce1/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java
index 1a3714c..f8e88ef 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java
@@ -280,7 +280,7 @@ public class JdbcCommon {
                             InputStream is = clob.getAsciiStream();
                             int index = 0;
                             int c = is.read();
-                            while (c > 0) {
+                            while (c >= 0) {
                                 buffer[index++] = (char) c;
                                 c = is.read();
                             }
@@ -316,7 +316,7 @@ public class JdbcCommon {
                             InputStream is = blob.getBinaryStream();
                             int index = 0;
                             int c = is.read();
-                            while (c > 0) {
+                            while (c >= 0) {
                                 buffer[index++] = (byte) c;
                                 c = is.read();
                             }

http://git-wip-us.apache.org/repos/asf/nifi/blob/7d6bbce1/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcCommon.java
----------------------------------------------------------------------
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 afe7788..5eca32a 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
@@ -476,11 +476,13 @@ public class TestJdbcCommon {
     public void testClob() throws Exception {
         try (final Statement stmt = con.createStatement()) {
             stmt.executeUpdate("CREATE TABLE clobtest (id INT, text CLOB(64 K))");
-            stmt.execute("INSERT INTO blobtest VALUES (41, NULL)");
+            stmt.execute("INSERT INTO clobtest VALUES (41, NULL)");
             PreparedStatement ps = con.prepareStatement("INSERT INTO clobtest VALUES (?,
?)");
             ps.setInt(1, 42);
             final char[] buffer = new char[4002];
             IntStream.range(0, 4002).forEach((i) -> buffer[i] = String.valueOf(i % 10).charAt(0));
+            // Put a zero-byte in to test the buffer building logic
+            buffer[1] = 0;
             ReaderInputStream isr = new ReaderInputStream(new CharArrayReader(buffer), Charset.defaultCharset());
 
             // - set the value of the input parameter to the input stream
@@ -513,7 +515,10 @@ public class TestJdbcCommon {
                         assertNull(o);
                     } else {
                         assertNotNull(o);
-                        assertEquals(4002, o.toString().length());
+                        final String text = o.toString();
+                        assertEquals(4002, text.length());
+                        // Third character should be '2'
+                        assertEquals('2', text.charAt(2));
                     }
                 }
             }
@@ -529,6 +534,8 @@ public class TestJdbcCommon {
             ps.setInt(1, 42);
             final byte[] buffer = new byte[4002];
             IntStream.range(0, 4002).forEach((i) -> buffer[i] = (byte) ((i % 10) + 65));
+            // Put a zero-byte in to test the buffer building logic
+            buffer[1] = 0;
             ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
 
             // - set the value of the input parameter to the input stream
@@ -562,7 +569,10 @@ public class TestJdbcCommon {
                     } else {
                         assertNotNull(o);
                         assertTrue(o instanceof ByteBuffer);
-                        assertEquals(4002, ((ByteBuffer) o).array().length);
+                        final byte[] blob = ((ByteBuffer) o).array();
+                        assertEquals(4002, blob.length);
+                        // Third byte should be 67 ('C')
+                        assertEquals('C', blob[2]);
                     }
                 }
             }


Mime
View raw message