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
This commit is contained in:
Jason Tedor 2019-01-14 21:15:35 -05:00
parent 74640d0ba7
commit eb86b9f284
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 13 additions and 5 deletions

View File

@ -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<RetentionLease> 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);
}