|
43 | 43 | import java.util.Iterator;
|
44 | 44 | import java.util.List;
|
45 | 45 | import java.util.Map;
|
| 46 | +import java.util.concurrent.CyclicBarrier; |
| 47 | +import java.util.concurrent.TimeUnit; |
46 | 48 | import java.util.concurrent.atomic.AtomicBoolean;
|
47 | 49 | import java.util.concurrent.atomic.AtomicInteger;
|
48 | 50 | import java.util.stream.LongStream;
|
@@ -270,6 +272,53 @@ protected void doClose() {
|
270 | 272 | }
|
271 | 273 | }
|
272 | 274 |
|
| 275 | + public void testIsFinished() { |
| 276 | + int iters = iterations(10, 10_000); |
| 277 | + BlockFactory blockFactory = blockFactory(); |
| 278 | + for (int i = 0; i < iters; i++) { |
| 279 | + DriverContext driverContext = new DriverContext(blockFactory.bigArrays(), blockFactory); |
| 280 | + CyclicBarrier barrier = new CyclicBarrier(2); |
| 281 | + AsyncOperator asyncOperator = new AsyncOperator(driverContext, between(1, 10)) { |
| 282 | + @Override |
| 283 | + protected void performAsync(Page inputPage, ActionListener<Page> listener) { |
| 284 | + ActionRunnable<Page> command = new ActionRunnable<>(listener) { |
| 285 | + @Override |
| 286 | + protected void doRun() { |
| 287 | + try { |
| 288 | + barrier.await(10, TimeUnit.SECONDS); |
| 289 | + } catch (Exception e) { |
| 290 | + throw new AssertionError(e); |
| 291 | + } |
| 292 | + listener.onFailure(new ElasticsearchException("simulated")); |
| 293 | + } |
| 294 | + }; |
| 295 | + threadPool.executor(ESQL_TEST_EXECUTOR).execute(command); |
| 296 | + } |
| 297 | + |
| 298 | + @Override |
| 299 | + protected void doClose() { |
| 300 | + |
| 301 | + } |
| 302 | + }; |
| 303 | + asyncOperator.addInput(new Page(blockFactory.newConstantIntBlockWith(randomInt(), between(1, 10)))); |
| 304 | + asyncOperator.finish(); |
| 305 | + try { |
| 306 | + barrier.await(10, TimeUnit.SECONDS); |
| 307 | + } catch (Exception e) { |
| 308 | + throw new AssertionError(e); |
| 309 | + } |
| 310 | + int numChecks = between(10, 100); |
| 311 | + while (--numChecks >= 0) { |
| 312 | + try { |
| 313 | + assertFalse("must not finished or failed", asyncOperator.isFinished()); |
| 314 | + } catch (ElasticsearchException e) { |
| 315 | + assertThat(e.getMessage(), equalTo("simulated")); |
| 316 | + break; |
| 317 | + } |
| 318 | + } |
| 319 | + } |
| 320 | + } |
| 321 | + |
273 | 322 | static class LookupService {
|
274 | 323 | private final ThreadPool threadPool;
|
275 | 324 | private final Map<Long, String> dict;
|
|
0 commit comments