|
27 | 27 | import org.apache.lucene.util.BytesRef; |
28 | 28 | import org.apache.lucene.util.Constants; |
29 | 29 | import org.elasticsearch.ElasticsearchException; |
| 30 | +import org.elasticsearch.ExceptionsHelper; |
30 | 31 | import org.elasticsearch.action.ActionListener; |
31 | 32 | import org.elasticsearch.action.admin.indices.flush.FlushRequest; |
32 | 33 | import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; |
@@ -3334,6 +3335,21 @@ public void testWaitForClosedListener() throws IOException { |
3334 | 3335 | assertThat("listener should have been called", called.get(), equalTo(true)); |
3335 | 3336 | } |
3336 | 3337 |
|
| 3338 | + public void testWaitForPrimaryTermAndGenerationFailsForClosedShard() throws IOException { |
| 3339 | + Settings settings = indexSettings(IndexVersion.current(), 1, 1).build(); |
| 3340 | + IndexMetadata metadata = IndexMetadata.builder("test").putMapping(""" |
| 3341 | + { "properties": { "foo": { "type": "text"}}}""").settings(settings).primaryTerm(0, 1).build(); |
| 3342 | + IndexShard initializingShard = newShard(new ShardId(metadata.getIndex(), 0), true, "n1", metadata, null); |
| 3343 | + |
| 3344 | + var future = new PlainActionFuture<Long>(); |
| 3345 | + initializingShard.waitForPrimaryTermAndGeneration(0L, 0L, future); |
| 3346 | + |
| 3347 | + assertFalse("waitForPrimaryTermAndGeneration should be waiting", future.isDone()); |
| 3348 | + closeShards(initializingShard); |
| 3349 | + // Should bail out earlier without calling the engine |
| 3350 | + assertNotNull(ExceptionsHelper.unwrap(expectThrows(Exception.class, future::get), IndexShardClosedException.class)); |
| 3351 | + } |
| 3352 | + |
3337 | 3353 | public void testRecoverFromLocalShard() throws IOException { |
3338 | 3354 | Settings settings = indexSettings(IndexVersion.current(), 1, 1).build(); |
3339 | 3355 | IndexMetadata metadata = IndexMetadata.builder("source") |
|
0 commit comments