You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "markap14 (via GitHub)" <gi...@apache.org> on 2025/06/12 19:19:10 UTC

[PR] NIFI-14654: Ensure when a Stateless Process Group is stopped that we … [nifi]

markap14 opened a new pull request, #10014:
URL: https://github.com/apache/nifi/pull/10014

   …properly call all success and/or failure session callbacks before stopping the Processor. In order to make system tests to verify this more straight-forward, also exposed the CounterRepository such that system tests can obtain counter values to ensure that methods are called appropriately.
   
   <!-- 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. -->
   
   # Summary
   
   [NIFI-00000](https://issues.apache.org/jira/browse/NIFI-00000)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [ ] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [ ] JDK 21
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14654: Ensure when a Stateless Process Group is stopped that we … [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #10014:
URL: https://github.com/apache/nifi/pull/10014


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14654: Ensure when a Stateless Process Group is stopped that we … [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #10014:
URL: https://github.com/apache/nifi/pull/10014#discussion_r2145872918


##########
nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/processors/tests/system/GenerateAndCountCallbacks.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package org.apache.nifi.processors.tests.system;
+
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+
+import java.time.Duration;
+import java.util.Set;
+
+@CapabilityDescription("Generates an empty FlowFile and counts how many times the session commit callback is called " +
+                       "for both success and failure before and after Processor is stopped")
+public class GenerateAndCountCallbacks extends AbstractProcessor {
+
+    public static final String STOPPED_AND_SUCCESS = "Stopped and Success";
+    public static final String STOPPED_AND_FAILURE = "Stopped and Failure";
+    public static final String RUNNING_AND_SUCCESS = "Running and Success";
+    public static final String RUNNING_AND_FAILURE = "Running and Failure";
+
+    static final Relationship REL_SUCCESS = new Relationship.Builder()
+        .name("success")
+        .description("All FlowFiles are routed to this relationship")
+        .build();
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return Set.of(REL_SUCCESS);
+    }
+
+    private volatile boolean stopped = false;
+
+    @OnScheduled
+    public void onScheduled() {
+        stopped = false;
+        getLogger().info("Processor started");
+    }
+
+    @OnStopped
+    public void onStopped() {
+        stopped = true;
+        getLogger().info("Processor stopped");
+    }
+
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+        FlowFile flowFile = session.create();
+        session.transfer(flowFile, REL_SUCCESS);
+
+        session.commitAsync(() -> {
+            sleepUninterruptibly(Duration.ofSeconds(3));
+
+            if (stopped) {
+                session.adjustCounter(STOPPED_AND_SUCCESS, 1, true);
+                getLogger().error("Success callback called after Processor Stopped");
+            } else {
+                session.adjustCounter(RUNNING_AND_SUCCESS, 1, true);
+                getLogger().info("Success callback called while Processor Running");
+            }
+        },
+        failureCause -> {
+            sleepUninterruptibly(Duration.ofSeconds(3));
+
+            if (stopped) {
+                session.adjustCounter(STOPPED_AND_FAILURE, 1, true);
+                getLogger().error("Failure callback called after Processor Stopped; Failure cause: {}", failureCause.toString());
+            } else {
+                session.adjustCounter(RUNNING_AND_FAILURE, 1, true);
+                getLogger().warn("Failure callback called while Processor Running; Failure cause: {}", failureCause.toString());
+            }
+        });
+    }
+
+    private void sleepUninterruptibly(final Duration duration) {
+        long endTime = System.currentTimeMillis() + duration.toMillis();
+        while (System.currentTimeMillis() < endTime) {
+            try {
+                Thread.sleep(endTime - System.currentTimeMillis());
+            } catch (final InterruptedException e) {

Review Comment:
   PMD flags empty catch blocks, but changing the variable to `ignored` resolves the warning and indicates expected behavior.
   ```suggestion
               } catch (final InterruptedException ignored) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org