|
41 | 41 |
|
42 | 42 | import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
43 | 43 | import static org.hamcrest.Matchers.contains;
|
| 44 | +import static org.hamcrest.Matchers.containsString; |
44 | 45 | import static org.hamcrest.Matchers.empty;
|
45 | 46 | import static org.hamcrest.Matchers.equalTo;
|
46 | 47 | import static org.hamcrest.Matchers.hasItem;
|
47 | 48 | import static org.hamcrest.Matchers.hasSize;
|
| 49 | +import static org.hamcrest.Matchers.hasToString; |
48 | 50 |
|
49 | 51 | public class ReplicationTrackerRetentionLeaseTests extends ReplicationTrackerTestCase {
|
50 | 52 |
|
@@ -90,6 +92,60 @@ public void testAddOrRenewRetentionLease() {
|
90 | 92 | }
|
91 | 93 | }
|
92 | 94 |
|
| 95 | + public void testAddDuplicateRetentionLease() { |
| 96 | + final AllocationId allocationId = AllocationId.newInitializing(); |
| 97 | + long primaryTerm = randomLongBetween(1, Long.MAX_VALUE); |
| 98 | + final ReplicationTracker replicationTracker = new ReplicationTracker( |
| 99 | + new ShardId("test", "_na", 0), |
| 100 | + allocationId.getId(), |
| 101 | + IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), |
| 102 | + primaryTerm, |
| 103 | + UNASSIGNED_SEQ_NO, |
| 104 | + value -> {}, |
| 105 | + () -> 0L, |
| 106 | + (leases, listener) -> {}); |
| 107 | + replicationTracker.updateFromMaster( |
| 108 | + randomNonNegativeLong(), |
| 109 | + Collections.singleton(allocationId.getId()), |
| 110 | + routingTable(Collections.emptySet(), allocationId), |
| 111 | + Collections.emptySet()); |
| 112 | + replicationTracker.activatePrimaryMode(SequenceNumbers.NO_OPS_PERFORMED); |
| 113 | + final String id = randomAlphaOfLength(8); |
| 114 | + final long retainingSequenceNumber = randomNonNegativeLong(); |
| 115 | + final String source = randomAlphaOfLength(8); |
| 116 | + replicationTracker.addRetentionLease(id, retainingSequenceNumber, source, ActionListener.wrap(() -> {})); |
| 117 | + final long nextRetaininSequenceNumber = randomLongBetween(retainingSequenceNumber, Long.MAX_VALUE); |
| 118 | + final RetentionLeaseAlreadyExistsException e = expectThrows( |
| 119 | + RetentionLeaseAlreadyExistsException.class, |
| 120 | + () -> replicationTracker.addRetentionLease(id, nextRetaininSequenceNumber, source, ActionListener.wrap(() -> {}))); |
| 121 | + assertThat(e, hasToString(containsString("retention lease with ID [" + id + "] already exists"))); |
| 122 | + } |
| 123 | + |
| 124 | + public void testRenewNotFoundRetentionLease() { |
| 125 | + final AllocationId allocationId = AllocationId.newInitializing(); |
| 126 | + long primaryTerm = randomLongBetween(1, Long.MAX_VALUE); |
| 127 | + final ReplicationTracker replicationTracker = new ReplicationTracker( |
| 128 | + new ShardId("test", "_na", 0), |
| 129 | + allocationId.getId(), |
| 130 | + IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), |
| 131 | + primaryTerm, |
| 132 | + UNASSIGNED_SEQ_NO, |
| 133 | + value -> {}, |
| 134 | + () -> 0L, |
| 135 | + (leases, listener) -> {}); |
| 136 | + replicationTracker.updateFromMaster( |
| 137 | + randomNonNegativeLong(), |
| 138 | + Collections.singleton(allocationId.getId()), |
| 139 | + routingTable(Collections.emptySet(), allocationId), |
| 140 | + Collections.emptySet()); |
| 141 | + replicationTracker.activatePrimaryMode(SequenceNumbers.NO_OPS_PERFORMED); |
| 142 | + final String id = randomAlphaOfLength(8); |
| 143 | + final RetentionLeaseNotFoundException e = expectThrows( |
| 144 | + RetentionLeaseNotFoundException.class, |
| 145 | + () -> replicationTracker.renewRetentionLease(id, randomNonNegativeLong(), randomAlphaOfLength(8))); |
| 146 | + assertThat(e, hasToString(containsString("retention lease with [" + id + "] not found"))); |
| 147 | + } |
| 148 | + |
93 | 149 | public void testAddRetentionLeaseCausesRetentionLeaseSync() {
|
94 | 150 | final AllocationId allocationId = AllocationId.newInitializing();
|
95 | 151 | final Map<String, Long> retainingSequenceNumbers = new HashMap<>();
|
|
0 commit comments