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:
parent
74640d0ba7
commit
eb86b9f284
|
@ -43,6 +43,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.hasItem;
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
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 {
|
public void testCommit() throws IOException {
|
||||||
final Settings settings = Settings.builder()
|
final Settings settings = Settings.builder()
|
||||||
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
|
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
|
||||||
|
@ -162,7 +162,11 @@ public class IndexShardRetentionLeaseTests extends IndexShardTestCase {
|
||||||
final SegmentInfos segmentCommitInfos = indexShard.store().readLastCommittedSegmentsInfo();
|
final SegmentInfos segmentCommitInfos = indexShard.store().readLastCommittedSegmentsInfo();
|
||||||
assertTrue(segmentCommitInfos.getUserData().containsKey(Engine.RETENTION_LEASES));
|
assertTrue(segmentCommitInfos.getUserData().containsKey(Engine.RETENTION_LEASES));
|
||||||
final Collection<RetentionLease> retentionLeases = indexShard.getEngine().config().retentionLeasesSupplier().get();
|
final Collection<RetentionLease> retentionLeases = indexShard.getEngine().config().retentionLeasesSupplier().get();
|
||||||
|
if (retentionLeases.isEmpty()) {
|
||||||
|
assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), empty());
|
||||||
|
} else {
|
||||||
assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), contains(retentionLeases.toArray(new RetentionLease[0])));
|
assertThat(IndexShard.getRetentionLeases(segmentCommitInfos), contains(retentionLeases.toArray(new RetentionLease[0])));
|
||||||
|
}
|
||||||
|
|
||||||
// when we recover, we should recover the retention leases
|
// when we recover, we should recover the retention leases
|
||||||
final IndexShard recoveredShard = reinitShard(
|
final IndexShard recoveredShard = reinitShard(
|
||||||
|
@ -170,9 +174,13 @@ public class IndexShardRetentionLeaseTests extends IndexShardTestCase {
|
||||||
ShardRoutingHelper.initWithSameId(indexShard.routingEntry(), RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
ShardRoutingHelper.initWithSameId(indexShard.routingEntry(), RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
||||||
try {
|
try {
|
||||||
recoverShardFromStore(recoveredShard);
|
recoverShardFromStore(recoveredShard);
|
||||||
|
if (retentionLeases.isEmpty()) {
|
||||||
|
assertThat(recoveredShard.getEngine().config().retentionLeasesSupplier().get(), empty());
|
||||||
|
} else {
|
||||||
assertThat(
|
assertThat(
|
||||||
recoveredShard.getEngine().config().retentionLeasesSupplier().get(),
|
recoveredShard.getEngine().config().retentionLeasesSupplier().get(),
|
||||||
contains(retentionLeases.toArray(new RetentionLease[0])));
|
contains(retentionLeases.toArray(new RetentionLease[0])));
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
closeShards(recoveredShard);
|
closeShards(recoveredShard);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue