Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ public void close() {
if (this.innerIterator != null) {
this.innerIterator.close();
}
if (this.innerListIterator != null) {
while (this.innerListIterator.hasNext()) {
this.innerListIterator.next().close();
}
if (this.innerListIterator == null) {
// never iterated, so every sub-iterator is still open
this.innerListIterator = this.iterators.iterator();
}
while (this.innerListIterator.hasNext()) {
this.innerListIterator.next().close();
}
this.iterators.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,56 @@ public void testCloseFailureStillDiscardsPendingResultsAndStopsProbing() {
}
}

@Test
public void testMultiListCloseBeforeIterationClosesAllSources() {
RowIterator first = singleRow(1);
RowIterator second = singleRow(2);
MultiListIterator iterator = new MultiListIterator(List.of(first, second));

iterator.close();

assertEquals(1, first.closes);
assertEquals(1, second.closes);
assertFalse(iterator.hasNext());

iterator.close();

assertEquals(1, first.closes);
assertEquals(1, second.closes);
}

@Test
public void testLimitDedupCloseBeforeIterationClosesMultiListSources() {
RowIterator first = singleRow(1);
RowIterator second = singleRow(2);
ScanIterator iterator = new MapLimitIterator<BackendColumn>(
new MultiListIterator(List.of(first, second)));

iterator.close();

assertEquals(1, first.closes);
assertEquals(1, second.closes);
}

@Test
public void testMultiListClosesEachSourceOnceAfterPartialIteration() {
RowIterator first = singleRow(1);
RowIterator second = singleRow(2);
RowIterator third = singleRow(3);
MultiListIterator iterator = new MultiListIterator(List.of(first, second, third));

assertTrue(iterator.hasNext());
assertEquals(1, (int) iterator.<BackendColumn>next().name[0]);
assertTrue(iterator.hasNext());
assertEquals(1, first.closes);

iterator.close();

assertEquals(1, first.closes);
assertEquals(1, second.closes);
assertEquals(1, third.closes);
}

@Test(timeout = 5000)
public void testUnionUniqueStreamDoesNotLoseRecordsBetweenSingleRecordBatches() throws Exception {
assertSingleRecordBatches(FilterKind.UNION_UNIQUE);
Expand Down Expand Up @@ -268,6 +318,11 @@ AggregativeQueryObserver newObserver(StreamObserver<QueryResponse> sender) {
}
}

private static RowIterator singleRow(int key) {
return new RowIterator(List.of(BackendColumn.of(new byte[]{(byte) key},
new byte[]{(byte) (key + 10)})));
}

private static FilterFixture filter(FilterKind kind) {
BackendColumn first = BackendColumn.of(new byte[]{1}, new byte[]{11});
BackendColumn second = BackendColumn.of(new byte[]{2}, new byte[]{12});
Expand Down Expand Up @@ -317,6 +372,7 @@ private static class RowIterator implements ScanIterator {

private final Iterator<BackendColumn> rows;
private boolean closed;
private int closes;
private int probes;
private RuntimeException closeFailure;

Expand Down Expand Up @@ -347,6 +403,7 @@ public <T> T next() {
@Override
public void close() {
this.closed = true;
this.closes++;
if (this.closeFailure != null) {
throw this.closeFailure;
}
Expand Down
Loading