NIFI-5718: Added performance-based unit test (Ignored) for LineDemarcator

Signed-off-by: Peter Wicks <patric...@gmail.com>

This closes #3100.


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

Branch: refs/heads/master
Commit: 830f7aa84d2f61781422daa43648a09c3a08f392
Parents: 564ad0c
Author: Mark Payne <marka...@hotmail.com>
Authored: Fri Nov 9 12:04:43 2018 -0500
Committer: Peter Wicks <patric...@gmail.com>
Committed: Fri Nov 9 14:27:32 2018 -0700

----------------------------------------------------------------------
 .../nifi/stream/io/util/TestLineDemarcator.java | 28 ++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/830f7aa8/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TestLineDemarcator.java
----------------------------------------------------------------------
diff --git 
a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TestLineDemarcator.java
 
b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TestLineDemarcator.java
index 768a60a..85cf85e 100644
--- 
a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TestLineDemarcator.java
+++ 
b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TestLineDemarcator.java
@@ -16,10 +16,13 @@
  */
 package org.apache.nifi.stream.io.util;
 
+import org.apache.nifi.stream.io.RepeatingInputStream;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
@@ -27,6 +30,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
 
@@ -95,6 +99,30 @@ public class TestLineDemarcator {
         assertEquals(Arrays.asList("\n", "The quick brown fox jumped over the 
lazy dog."), lines);
     }
 
+    @Test
+    @Ignore("Intended only for manual testing. While this can take a while to 
run, it can be very helpful for manual testing before and after a change to the 
class. However, we don't want this to " +
+        "run in automated tests because we have no way to compare from one run 
to another, so it will only slow down automated tests.")
+    public void testPerformance() throws IOException {
+        final String lines = 
"The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog.\r\n\n";
+        final byte[] bytes = lines.getBytes(StandardCharsets.UTF_8);
+
+        for (int i=0; i < 100; i++) {
+            final long start = System.nanoTime();
+
+            long count = 0;
+            try (final InputStream in = new RepeatingInputStream(bytes, 
1_000_000);
+                 final LineDemarcator demarcator = new LineDemarcator(in, 
StandardCharsets.UTF_8, 8192, 8192)) {
+
+                while (demarcator.nextLine() != null) {
+                    count++;
+                }
+            }
+
+            final long millis = 
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
+            System.out.println("Took " + millis + " millis to demarcate " + 
count + " lines");
+        }
+    }
+
     private List<String> getLines(final String text) throws IOException {
         return getLines(text, 8192, 8192);
     }

Reply via email to