diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/input/DruidSegmentReader.java b/indexing-service/src/main/java/org/apache/druid/indexing/input/DruidSegmentReader.java index 9b5f3a5c563..5f45eb8485d 100644 --- a/indexing-service/src/main/java/org/apache/druid/indexing/input/DruidSegmentReader.java +++ b/indexing-service/src/main/java/org/apache/druid/indexing/input/DruidSegmentReader.java @@ -19,6 +19,7 @@ package org.apache.druid.indexing.input; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import org.apache.druid.data.input.InputEntity; @@ -33,6 +34,7 @@ import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.java.util.common.guava.Yielder; import org.apache.druid.java.util.common.guava.Yielders; +import org.apache.druid.java.util.common.io.Closer; import org.apache.druid.java.util.common.parsers.CloseableIterator; import org.apache.druid.java.util.common.parsers.ParseException; import org.apache.druid.query.dimension.DefaultDimensionSpec; @@ -147,13 +149,14 @@ public class DruidSegmentReader extends IntermediateRowParsingReader> makeCloseableIteratorFromSequenceAndSegmentFile( + @VisibleForTesting + static CloseableIterator> makeCloseableIteratorFromSequenceAndSegmentFile( final Sequence> sequence, final CleanableFile segmentFile ) @@ -179,7 +182,10 @@ public class DruidSegmentReader extends IntermediateRowParsingReader> sequence = new BaseSequence<>( + new IteratorMaker, Iterator>>() + { + @Override + public Iterator> make() + { + return Collections.emptyIterator(); + } + + @Override + public void cleanup(Iterator> iterFromMake) + { + isSequenceClosed.setValue(true); + } + } + ); + CleanableFile cleanableFile = new CleanableFile() + { + @Override + public File file() + { + return null; + } + + @Override + public void close() + { + isFileClosed.setValue(true); + } + }; + try (CloseableIterator> iterator = + DruidSegmentReader.makeCloseableIteratorFromSequenceAndSegmentFile(sequence, cleanableFile)) { + while (iterator.hasNext()) { + iterator.next(); + } + } + Assert.assertTrue("File is not closed", isFileClosed.booleanValue()); + Assert.assertTrue("Sequence is not closed", isSequenceClosed.booleanValue()); + } +}