Align @Indexed(expireAfter) with expireAfterSeconds.
This commit fixes an issue where expireAfter=0s behaves differently from expireAfterSeconds=0 where the former would not be applied. Closes #4844 Original pull request: #4848
This commit is contained in:
committed by
Mark Paluch
parent
d6fe3c0ec7
commit
ad39a43582
@@ -563,7 +563,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
|
||||
Duration timeout = computeIndexTimeout(index.expireAfter(),
|
||||
() -> getEvaluationContextForProperty(persistentProperty.getOwner()));
|
||||
if (!timeout.isZero() && !timeout.isNegative()) {
|
||||
if (!timeout.isNegative()) {
|
||||
indexDefinition.expire(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +222,15 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
||||
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 600L);
|
||||
}
|
||||
|
||||
@Test // GH-4844
|
||||
public void shouldResolveZeroTimeoutFromString() {
|
||||
|
||||
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
||||
WithExpireAfterZeroSecondsAsPlainString.class);
|
||||
|
||||
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 0L);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2112
|
||||
public void shouldResolveTimeoutFromIso8601String() {
|
||||
|
||||
@@ -383,6 +392,11 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
||||
@Indexed(expireAfter = "10m") String withTimeout;
|
||||
}
|
||||
|
||||
@Document
|
||||
class WithExpireAfterZeroSecondsAsPlainString {
|
||||
@Indexed(expireAfter = "0s") String withTimeout;
|
||||
}
|
||||
|
||||
@Document
|
||||
class WithIso8601Style {
|
||||
@Indexed(expireAfter = "P1D") String withTimeout;
|
||||
|
||||
Reference in New Issue
Block a user