|
25 | 25 | import org.elasticsearch.compute.operator.Driver; |
26 | 26 | import org.elasticsearch.compute.operator.DriverContext; |
27 | 27 | import org.elasticsearch.compute.operator.Operator; |
| 28 | +import org.elasticsearch.compute.operator.SourceOperator; |
28 | 29 | import org.elasticsearch.compute.test.AnyOperatorTestCase; |
29 | 30 | import org.elasticsearch.compute.test.OperatorTestCase; |
30 | 31 | import org.elasticsearch.compute.test.TestResultPageSinkOperator; |
@@ -117,6 +118,27 @@ public void testShardDataPartitioning() { |
117 | 118 | testSimple(driverContext(), size, limit); |
118 | 119 | } |
119 | 120 |
|
| 121 | + public void testEarlyTermination() { |
| 122 | + int size = between(1_000, 20_000); |
| 123 | + int limit = between(10, size); |
| 124 | + LuceneSourceOperator.Factory factory = simple(randomFrom(DataPartitioning.values()), size, limit, scoring); |
| 125 | + try (SourceOperator sourceOperator = factory.get(driverContext())) { |
| 126 | + assertFalse(sourceOperator.isFinished()); |
| 127 | + int collected = 0; |
| 128 | + while (sourceOperator.isFinished() == false) { |
| 129 | + Page page = sourceOperator.getOutput(); |
| 130 | + if (page != null) { |
| 131 | + collected += page.getPositionCount(); |
| 132 | + page.releaseBlocks(); |
| 133 | + } |
| 134 | + if (collected >= limit) { |
| 135 | + assertTrue("source operator is not finished after reaching limit", sourceOperator.isFinished()); |
| 136 | + assertThat(collected, equalTo(limit)); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
120 | 142 | public void testEmpty() { |
121 | 143 | testSimple(driverContext(), 0, between(10, 10_000)); |
122 | 144 | } |
|
0 commit comments