markap14 commented on code in PR #11914:
URL: https://github.com/apache/nifi/pull/11914#discussion_r4682589566


##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAOTest.java:
##########
@@ -133,4 +139,35 @@ void testGetProcessGroupWithNonExistentIdThrows() {
             processGroupDAO.getProcessGroup(NON_EXISTENT_ID)
         );
     }
+
+    @Test
+    void testEndDrainEndsOnlyTheRequestedDrain() {
+        final ProcessGroupDrain drain = mock(ProcessGroupDrain.class);
+        when(drain.getIdentifier()).thenReturn("current-drain");

Review Comment:
   [claude-opus-5.5] Done in 6dd48e06b16 @exceptionfactory: `current-drain` is 
now a constant that the test reuses.



##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/StandardProcessGroupDAOTest.java:
##########
@@ -133,4 +139,35 @@ void testGetProcessGroupWithNonExistentIdThrows() {
             processGroupDAO.getProcessGroup(NON_EXISTENT_ID)
         );
     }
+
+    @Test
+    void testEndDrainEndsOnlyTheRequestedDrain() {
+        final ProcessGroupDrain drain = mock(ProcessGroupDrain.class);
+        when(drain.getIdentifier()).thenReturn("current-drain");
+        when(drain.getProcessGroup()).thenReturn(rootGroup);
+        when(rootGroup.getDrain()).thenReturn(Optional.of(drain));
+        when(rootGroup.endDrain()).thenReturn(Optional.of(drain));
+
+        // A request to end an earlier drain of the group does not end the 
drain that the group has now
+        assertEquals(Optional.empty(), processGroupDAO.endDrain(ROOT_GROUP_ID, 
"earlier-drain"));
+        verify(rootGroup, never()).endDrain();
+
+        assertEquals(Optional.of(drain), 
processGroupDAO.endDrain(ROOT_GROUP_ID, "current-drain"));
+        verify(rootGroup).endDrain();
+    }
+
+    @Test
+    void testVerifyBeginDrainRejectsConnectorManagedGroup() {
+        
when(owningConnector.getCurrentState()).thenReturn(ConnectorState.TROUBLESHOOTING);
+        
when(connectorManagedGroup.findOwningConnectorIdentifier()).thenReturn(Optional.of("connector-1"));

Review Comment:
   [claude-opus-5.5] Done in 6dd48e06b16 @exceptionfactory: `connector-1` is 
now a constant that the test reuses.



##########
nifi-system-tests/nifi-system-test-extensions-bundle/nifi-system-test-extensions/src/main/java/org/apache/nifi/processors/tests/system/GenerateFlowFile.java:
##########
@@ -101,6 +102,14 @@ public class GenerateFlowFile extends AbstractProcessor {
         .addValidator(NON_EMPTY_VALIDATOR)
         .expressionLanguageSupported(NONE)
         .build();
+    static final PropertyDescriptor GATE_FILE = new Builder()
+        .name("Gate File")
+        .description("An optional file path. If specified, each invocation 
waits until this file exists before generating FlowFiles, even if the Processor 
"
+            + "is stopped while it waits. This simulates a source that is 
still waiting for data from an external system when it is asked to stop.")

Review Comment:
   [claude-opus-5.5] Thanks @exceptionfactory, I renamed the property to `Wait 
For File` in 6dd48e06b16. The other test processors that use `Gate File` 
existed before this PR and behave differently (they yield rather than block), 
so I left them unchanged.



##########
nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/pg/ProcessGroupDrainIT.java:
##########
@@ -0,0 +1,266 @@
+/*
+ * 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.tests.system.pg;
+
+import jakarta.ws.rs.WebApplicationException;
+import org.apache.nifi.controller.ScheduledState;
+import org.apache.nifi.groups.StatelessGroupScheduledState;
+import org.apache.nifi.tests.system.NiFiSystemIT;
+import org.apache.nifi.toolkit.client.NiFiClientException;
+import org.apache.nifi.web.api.dto.DrainBlockingComponentDTO;
+import org.apache.nifi.web.api.dto.ProcessGroupDrainRequestDTO;
+import org.apache.nifi.web.api.dto.ProcessGroupDrainSummaryDTO;
+import org.apache.nifi.web.api.entity.ConnectionEntity;
+import org.apache.nifi.web.api.entity.ProcessGroupEntity;
+import org.apache.nifi.web.api.entity.ProcessorEntity;
+import org.apache.nifi.web.api.entity.ScheduleComponentsEntity;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class ProcessGroupDrainIT extends NiFiSystemIT {
+    private static final String WRITE_LIFECYCLE_EVENTS = 
"WriteLifecycleEvents";
+    private static final String DRAINING = "DRAINING";
+    private static final String ENDED = "ENDED";
+
+    @Override
+    protected void destroyFlow() throws NiFiClientException, IOException, 
InterruptedException {
+        getClientUtil().endProcessGroupDrains("root");
+        super.destroyFlow();
+    }
+
+    /**
+     * Drains a group that has a running source in the group itself and in a 
child group. The last Processor of the group removes FlowFiles only
+     * once a gate file exists, so the start/stop rules are checked while data 
is still queued. The source in the child group is still waiting
+     * for its own gate file when the drain begins, as a source does while it 
waits for an external system, so the drain does not end while that
+     * source can still produce data, even once nothing is queued. Once both 
gates open, the data flows out and NiFi ends the drain without any
+     * request from the client. WriteLifecycleEvents records the calls to its 
{@code @OnDrainInitiated} and {@code @OnDrainCompleted} methods.
+     * An empty Stateless child group can receive no data, so the drain does 
not start it. Ending the drain leaves every component as it is,
+     * and the run states that the drain set are kept when NiFi restarts.
+     */
+    @Test
+    public void testDrainEmptiesGroupWhileSourcesStayStoppedAndThenEnds() 
throws NiFiClientException, IOException, InterruptedException {
+        final File eventFile = new 
File(getNiFiInstance().getInstanceDirectory(), "drain-lifecycle-events.txt");
+        Files.deleteIfExists(eventFile.toPath());
+        final File gateFile = createGateFile("drain-gate.txt");
+        final File sourceGateFile = createGateFile("drain-source-gate.txt");
+        try {
+            drainGroupWithSourceStillRunning(eventFile, gateFile, 
sourceGateFile);
+        } finally {
+            // The gated source cannot stop until its gate file exists
+            sourceGateFile.createNewFile();
+        }
+    }
+
+    private void drainGroupWithSourceStillRunning(final File eventFile, final 
File gateFile, final File sourceGateFile) throws NiFiClientException, 
IOException, InterruptedException {
+        final ProcessGroupEntity group = 
getClientUtil().createProcessGroup("Drained", "root");
+        final ProcessorEntity generate = 
getClientUtil().createProcessor(GENERATE_FLOWFILE, group.getId());
+        final ProcessorEntity writeLifecycleEvents = 
getClientUtil().createProcessor(WRITE_LIFECYCLE_EVENTS, group.getId());
+        final ProcessorEntity terminate = 
getClientUtil().createProcessor(TERMINATE_FLOWFILE, group.getId());
+        final ConnectionEntity connection = 
getClientUtil().createConnection(generate, writeLifecycleEvents, SUCCESS, 
group.getId());
+        final ConnectionEntity gatedConnection = 
getClientUtil().createConnection(writeLifecycleEvents, terminate, SUCCESS, 
group.getId());
+        getClientUtil().updateProcessorProperties(writeLifecycleEvents, 
Map.of("Event File", eventFile.getAbsolutePath()));
+        getClientUtil().updateProcessorProperties(terminate, Map.of("Gate 
File", gateFile.getAbsolutePath()));

Review Comment:
   [claude-opus-5.5] Done in 6dd48e06b16 @exceptionfactory. Both drain system 
tests now declare the property names as constants and reuse them.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to