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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2610c5cacb NIFI-15523 Fixed Provenance EventIterator factory not 
returning items (#10837)
2610c5cacb is described below

commit 2610c5cacbd154e06f3cab6130e5ad52c53d480e
Author: David Young <[email protected]>
AuthorDate: Sat Jan 31 22:07:48 2026 -0500

    NIFI-15523 Fixed Provenance EventIterator factory not returning items 
(#10837)
    
    - EventIterator created using the `of` factory would return 
Optional.empty() when there are actually items in the internal iterator
    - Flipping the ternary result expressions fixed this issue
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../provenance/store/iterator/EventIterator.java   |  9 ++-
 .../store/iterator/EventIteratorTest.java          | 67 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 5 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/iterator/EventIterator.java
 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/iterator/EventIterator.java
index e3255db3d7..f3a555f5fe 100644
--- 
a/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/iterator/EventIterator.java
+++ 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/iterator/EventIterator.java
@@ -33,7 +33,7 @@ public interface EventIterator extends Closeable {
 
     EventIterator EMPTY = new EventIterator() {
         @Override
-        public void close() throws IOException {
+        public void close() {
         }
 
         @Override
@@ -46,17 +46,16 @@ public interface EventIterator extends Closeable {
         final Iterator<ProvenanceEventRecord> itr = 
Arrays.asList(events).iterator();
         return new EventIterator() {
             @Override
-            public void close() throws IOException {
+            public void close() {
             }
 
             @Override
             public Optional<ProvenanceEventRecord> nextEvent() {
-                return itr.hasNext() ? Optional.empty() : 
Optional.of(itr.next());
+                return itr.hasNext() ? Optional.of(itr.next()) : 
Optional.empty();
             }
         };
     }
 
-
     default EventIterator filter(Predicate<ProvenanceEventRecord> predicate) {
         final EventIterator self = this;
 
@@ -70,7 +69,7 @@ public interface EventIterator extends Closeable {
             public Optional<ProvenanceEventRecord> nextEvent() throws 
IOException {
                 while (true) {
                     Optional<ProvenanceEventRecord> next = self.nextEvent();
-                    if (!next.isPresent()) {
+                    if (next.isEmpty()) {
                         return next;
                     }
 
diff --git 
a/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/store/iterator/EventIteratorTest.java
 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/store/iterator/EventIteratorTest.java
new file mode 100644
index 0000000000..5ee3756f84
--- /dev/null
+++ 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/store/iterator/EventIteratorTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.provenance.store.iterator;
+
+import org.apache.nifi.provenance.ProvenanceEventRecord;
+import org.apache.nifi.provenance.TestUtil;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class EventIteratorTest {
+
+    @Test
+    void testCanCreateAndRetrieveUsingOfFactory() throws IOException {
+        ProvenanceEventRecord event = TestUtil.createEvent();
+        EventIterator eventIterator = EventIterator.of(event);
+        Optional<ProvenanceEventRecord> foundEvent = eventIterator.nextEvent();
+        assertTrue(foundEvent.isPresent());
+        assertEquals(foundEvent.get().getAttribute("uuid"), 
event.getAttribute("uuid"));
+    }
+
+    @Test
+    void testEmptyReturnedWhenExhausted() throws IOException {
+        EventIterator eventIterator = EventIterator.of(TestUtil.createEvent());
+        assertTrue(eventIterator.nextEvent().isPresent());
+        assertTrue(eventIterator.nextEvent().isEmpty());
+    }
+
+    @Test
+    void testCanFilterEvents() throws IOException {
+        ProvenanceEventRecord eventOne = TestUtil.createEvent();
+        ProvenanceEventRecord eventTwo = TestUtil.createEvent();
+
+        EventIterator eventIterator = EventIterator.of(eventOne, eventTwo);
+        // Filter out the first event
+        EventIterator filteredIterator  = eventIterator.filter((e) -> 
!Objects.equals(e.getAttribute("uuid"), eventOne.getAttribute("uuid")));
+
+        ProvenanceEventRecord foundEvent = 
filteredIterator.nextEvent().orElseThrow();
+        assertEquals(foundEvent.getAttribute("uuid"), 
eventTwo.getAttribute("uuid"));
+    }
+
+    @Test
+    void testEmptyFactoryIsEmpty() throws IOException {
+        EventIterator eventIterator = EventIterator.EMPTY;
+        assertTrue(eventIterator.nextEvent().isEmpty());
+    }
+}

Reply via email to