You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2020/01/16 12:11:48 UTC

[nifi] branch master updated (23c8234 -> 91e9e65)

This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git.


    from 23c8234  NIFI-7031 updating copyright year on NOTICES
     new 48d4e6d  Add support for onUnscheduled method
     new 91e9e65  NIFI-6543: Added unit tests for lifecycle methods

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../processors/groovyx/ExecuteGroovyScript.java    |  9 ++++++
 .../additionalDetails.html                         |  6 +++-
 .../groovyx/ExecuteGroovyScriptTest.java           | 36 ++++++++++++++++++++++
 .../resources/groovy/test_onStart_onStop.groovy}   | 25 ++++++++++-----
 .../resources/groovy/test_onUnscheduled.groovy     | 11 +++----
 5 files changed, 71 insertions(+), 16 deletions(-)
 copy nifi-nar-bundles/{nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/message/NodeConnectionStatusRequestMessage.java => nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onStart_onStop.groovy} (72%)
 copy nifi-api/src/main/java/org/apache/nifi/documentation/ExtensionType.java => nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onUnscheduled.groovy (84%)


[nifi] 01/02: Add support for onUnscheduled method

Posted by pv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 48d4e6d14c6d835e091d7609930b7eec5b977db3
Author: wagggz <mi...@gmail.com>
AuthorDate: Sat Aug 10 12:17:53 2019 -0400

    Add support for onUnscheduled method
    
    Add support for onUnscheduled method1
    
    Add support for onUnscheduled method
    
    Add support for onUnscheduled method
---
 .../org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java  | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
index 5516aeb..627ec2c 100644
--- a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
+++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
@@ -27,6 +27,7 @@ import org.apache.nifi.annotation.documentation.CapabilityDescription;
 import org.apache.nifi.annotation.documentation.SeeAlso;
 import org.apache.nifi.annotation.documentation.Tags;
 import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
 import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.RequiredPermission;
@@ -270,6 +271,14 @@ public class ExecuteGroovyScript extends AbstractProcessor {
             throw new ProcessException("onStart failed: " + t, t);
         }
     }
+    @OnUnscheduled
+    public void onUnscheduled(final ProcessContext context) {
+        try {
+            callScriptStatic("onUnscheduled", context);
+        } catch (Throwable t) {
+            throw new ProcessException("onUnscheduled failed: " + t, t);
+        }
+    }
 
     @OnStopped
     public void onStopped(final ProcessContext context) {


[nifi] 02/02: NIFI-6543: Added unit tests for lifecycle methods

Posted by pv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 91e9e65a5c302eac324bcd3a9a84c347238e3649
Author: Matthew Burgess <ma...@apache.org>
AuthorDate: Fri Jan 10 10:25:16 2020 -0500

    NIFI-6543: Added unit tests for lifecycle methods
    
    Signed-off-by: Pierre Villard <pi...@gmail.com>
    
    This closes #3974.
---
 .../additionalDetails.html                         |  6 +++-
 .../groovyx/ExecuteGroovyScriptTest.java           | 36 ++++++++++++++++++++
 .../resources/groovy/test_onStart_onStop.groovy    | 39 ++++++++++++++++++++++
 .../resources/groovy/test_onUnscheduled.groovy     | 22 ++++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/resources/docs/org.apache.nifi.processors.groovyx.ExecuteGroovyScript/additionalDetails.html b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/resources/docs/org.apache.nifi.processors.groovyx.ExecuteGroovyScript/additionalDetails.html
index 5239aac..5282aec 100644
--- a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/resources/docs/org.apache.nifi.processors.groovyx.ExecuteGroovyScript/additionalDetails.html
+++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/resources/docs/org.apache.nifi.processors.groovyx.ExecuteGroovyScript/additionalDetails.html
@@ -182,7 +182,7 @@ then you can access it from code <code>SQL.mydb.rows('select * from mytable')</c
 
 <h2>Handling processor start &amp; stop</h2>
 
-<p>In the extended groovy processor you can catch `start` and `stop` events by providing corresponding static methods:</p>
+<p>In the extended groovy processor you can catch `start` and `stop` and `unscheduled` events by providing corresponding static methods:</p>
 <pre>
   import org.apache.nifi.processor.ProcessContext
   import java.util.concurrent.atomic.AtomicLong
@@ -203,6 +203,10 @@ then you can access it from code <code>SQL.mydb.rows('select * from mytable')</c
     println "onStop $context executed ${ Const.triggerCount } times during ${ alive } seconds"
   }
 
+  static onUnscheduled(ProcessContext context){
+    def alive = (System.currentTimeMillis() - Const.startTime.getTime()) / 1000
+    println "onUnscheduled $context executed ${ Const.triggerCount } times during ${ alive } seconds"
+  }
 
   flowFile.'trigger.count' = Const.triggerCount.incrementAndGet()
   REL_SUCCESS << flowFile
diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScriptTest.java b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScriptTest.java
index ddba34a..81d1857 100644
--- a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScriptTest.java
+++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScriptTest.java
@@ -40,9 +40,11 @@ import org.junit.Test;
 import org.junit.FixMethodOrder;
 import org.junit.runners.MethodSorters;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 
+import java.io.PrintStream;
 import java.nio.charset.StandardCharsets;
 
 import java.util.Arrays;
@@ -53,6 +55,7 @@ import java.sql.DriverManager;
 import java.sql.Connection;
 import java.sql.Statement;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import org.apache.nifi.controller.AbstractControllerService;
@@ -471,6 +474,39 @@ public class ExecuteGroovyScriptTest {
         flowFile.assertContentEquals("5678".getBytes(StandardCharsets.UTF_16LE));
     }
 
+    @Test
+    public void test_onStart_onStop() throws Exception {
+        runner.setProperty(ExecuteGroovyScript.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "test_onStart_onStop.groovy");
+        runner.assertValid();
+        runner.enqueue("");
+        final PrintStream originalOut = System.out;
+        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+        System.setOut(new PrintStream(outContent));
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(ExecuteGroovyScript.REL_SUCCESS.getName(), 1);
+        final List<MockFlowFile> result = runner.getFlowFilesForRelationship(ExecuteGroovyScript.REL_SUCCESS.getName());
+        MockFlowFile resultFile = result.get(0);
+        resultFile.assertAttributeExists("a");
+        resultFile.assertAttributeEquals("a", "A");
+        System.setOut(originalOut);
+        assertEquals("onStop invoked successfully\n", outContent.toString());
+
+        // Inspect the output visually for onStop, no way to pass back values
+    }
+
+    @Test
+    public void test_onUnscheduled() throws Exception {
+        runner.setProperty(ExecuteGroovyScript.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "test_onUnscheduled.groovy");
+        runner.assertValid();
+        final PrintStream originalOut = System.out;
+        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+        System.setOut(new PrintStream(outContent));
+        runner.run();
+        System.setOut(originalOut);
+        assertEquals("onUnscheduled invoked successfully\n", outContent.toString());
+    }
+
 
     private HashMap<String, String> map(String key, String value) {
         HashMap<String, String> attrs = new HashMap<>();
diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onStart_onStop.groovy b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onStart_onStop.groovy
new file mode 100644
index 0000000..1a22b1f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onStart_onStop.groovy
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.nifi.processor.ProcessContext
+
+
+class OnStart {
+    static String a = null
+}
+
+static onStart(ProcessContext context){
+    OnStart.a = 'A'
+}
+
+static onStop(ProcessContext context){
+    println 'onStop invoked successfully'
+}
+
+def flowFile = session.get()
+if (!flowFile) {
+    return
+}
+
+flowFile.'a' = OnStart.a
+REL_SUCCESS << flowFile
\ No newline at end of file
diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onUnscheduled.groovy b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onUnscheduled.groovy
new file mode 100644
index 0000000..557aefa
--- /dev/null
+++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/resources/groovy/test_onUnscheduled.groovy
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.nifi.processor.ProcessContext
+
+static onUnscheduled(ProcessContext context){
+    println 'onUnscheduled invoked successfully'
+}
\ No newline at end of file