From eb86b9f284ae0f272b51218efe68f36e294dedbc Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 14 Jan 2019 21:15:35 -0500 Subject: [PATCH] Fix retention lease commit test This commit fixes an issue with testing committed retention leases when they are not any retention leases (a deliberate edge case). Closes #37420 --- .../shard/IndexShardRetentionLeaseTests.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardRetentionLeaseTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardRetentionLeaseTests.java index e15f6c45ae6..d0018a0a864 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardRetentionLeaseTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardRetentionLeaseTests.java @@ -43,6 +43,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.LongSupplier; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; @@ -134,7 +135,6 @@ public class IndexShardRetentionLeaseTests extends IndexShardTestCase { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37420") public void testCommit() throws IOException { final Settings settings = Settings.builder() .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) @@ -162,7 +162,11 @@ public class IndexShardRetentionLeaseTests extends IndexShardTestCase { final SegmentInfos segmentCommitInfos = indexShard.store().readLastCommittedSegmentsInfo(); assertTrue(segmentCommitInfos.getUserData().containsKey(Engine.RETENTION_LEASES)); final Collection retentionLeases = indexShard.getEngine().config().retentionLeasesSupplier().get(); - assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), contains(retentionLeases.toArray(new RetentionLease[0]))); + if (retentionLeases.isEmpty()) { + assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), empty()); + } else { + assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), contains(retentionLeases.toArray(new RetentionLease[0]))); + } // when we recover, we should recover the retention leases final IndexShard recoveredShard = reinitShard( @@ -170,9 +174,13 @@ public class IndexShardRetentionLeaseTests extends IndexShardTestCase { ShardRoutingHelper.initWithSameId(indexShard.routingEntry(), RecoverySource.ExistingStoreRecoverySource.INSTANCE)); try { recoverShardFromStore(recoveredShard); - assertThat( - recoveredShard.getEngine().config().retentionLeasesSupplier().get(), - contains(retentionLeases.toArray(new RetentionLease[0]))); + if (retentionLeases.isEmpty()) { + assertThat(recoveredShard.getEngine().config().retentionLeasesSupplier().get(), empty()); + } else { + assertThat( + recoveredShard.getEngine().config().retentionLeasesSupplier().get(), + contains(retentionLeases.toArray(new RetentionLease[0]))); + } } finally { closeShards(recoveredShard); }