24
24
import org .apache .lucene .search .Query ;
25
25
import org .elasticsearch .common .lease .Releasable ;
26
26
import org .elasticsearch .index .seqno .RetentionLease ;
27
- import org .elasticsearch .index .seqno .SequenceNumbers ;
28
27
import org .elasticsearch .test .ESTestCase ;
29
28
30
29
import java .util .ArrayList ;
31
30
import java .util .Arrays ;
32
31
import java .util .Collection ;
32
+ import java .util .Collections ;
33
33
import java .util .HashSet ;
34
34
import java .util .List ;
35
35
import java .util .Set ;
36
36
import java .util .concurrent .atomic .AtomicLong ;
37
37
import java .util .function .Supplier ;
38
38
39
+ import static org .elasticsearch .index .seqno .SequenceNumbers .NO_OPS_PERFORMED ;
40
+ import static org .hamcrest .Matchers .contains ;
41
+ import static org .hamcrest .Matchers .empty ;
39
42
import static org .hamcrest .Matchers .equalTo ;
40
43
import static org .hamcrest .Matchers .instanceOf ;
41
44
@@ -46,7 +49,7 @@ public class SoftDeletesPolicyTests extends ESTestCase {
46
49
*/
47
50
public void testSoftDeletesRetentionLock () {
48
51
long retainedOps = between (0 , 10000 );
49
- AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers . NO_OPS_PERFORMED );
52
+ AtomicLong globalCheckpoint = new AtomicLong (NO_OPS_PERFORMED );
50
53
final AtomicLong [] retainingSequenceNumbers = new AtomicLong [randomIntBetween (0 , 8 )];
51
54
for (int i = 0 ; i < retainingSequenceNumbers .length ; i ++) {
52
55
retainingSequenceNumbers [i ] = new AtomicLong ();
@@ -116,4 +119,23 @@ public void testSoftDeletesRetentionLock() {
116
119
assertThat (policy .getMinRetainedSeqNo (), equalTo (minRetainedSeqNo ));
117
120
}
118
121
122
+ public void testAlwaysFetchLatestRetentionLeases () {
123
+ final AtomicLong globalCheckpoint = new AtomicLong (NO_OPS_PERFORMED );
124
+ final Collection <RetentionLease > leases = new ArrayList <>();
125
+ final int numLeases = randomIntBetween (0 , 10 );
126
+ for (int i = 0 ; i < numLeases ; i ++) {
127
+ leases .add (new RetentionLease (Integer .toString (i ), randomLongBetween (0 , 1000 ), randomNonNegativeLong (), "test" ));
128
+ }
129
+ final Supplier <Collection <RetentionLease >> leasesSupplier = () -> Collections .unmodifiableCollection (new ArrayList <>(leases ));
130
+ final SoftDeletesPolicy policy =
131
+ new SoftDeletesPolicy (globalCheckpoint ::get , randomIntBetween (1 , 1000 ), randomIntBetween (0 , 1000 ), leasesSupplier );
132
+ if (randomBoolean ()) {
133
+ policy .acquireRetentionLock ();
134
+ }
135
+ if (numLeases == 0 ) {
136
+ assertThat (policy .getRetentionPolicy ().v2 (), empty ());
137
+ } else {
138
+ assertThat (policy .getRetentionPolicy ().v2 (), contains (leases .toArray (new RetentionLease [0 ])));
139
+ }
140
+ }
119
141
}
0 commit comments