|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.seqno; |
| 21 | + |
| 22 | +import org.elasticsearch.test.ESTestCase; |
| 23 | + |
| 24 | +import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO; |
| 25 | +import static org.hamcrest.Matchers.containsString; |
| 26 | +import static org.hamcrest.Matchers.hasToString; |
| 27 | + |
| 28 | +public class RetentionLeaseTests extends ESTestCase { |
| 29 | + |
| 30 | + public void testRetainingSequenceNumberOutOfRange() { |
| 31 | + final long retainingSequenceNumber = randomLongBetween(Long.MIN_VALUE, UNASSIGNED_SEQ_NO - 1); |
| 32 | + final IllegalArgumentException e = expectThrows( |
| 33 | + IllegalArgumentException.class, |
| 34 | + () -> new RetentionLease("id", retainingSequenceNumber, randomNonNegativeLong(), "source")); |
| 35 | + assertThat( |
| 36 | + e, |
| 37 | + hasToString(containsString("retention lease retaining sequence number [" + retainingSequenceNumber + "] out of range"))); |
| 38 | + } |
| 39 | + |
| 40 | + public void testTimestampOutOfRange() { |
| 41 | + final long timestamp = randomLongBetween(Long.MIN_VALUE, -1); |
| 42 | + final IllegalArgumentException e = expectThrows( |
| 43 | + IllegalArgumentException.class, |
| 44 | + () -> new RetentionLease("id", randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE), timestamp, "source")); |
| 45 | + assertThat( |
| 46 | + e, |
| 47 | + hasToString(containsString("retention lease timestamp [" + timestamp + "] out of range"))); |
| 48 | + } |
| 49 | + |
| 50 | +} |
0 commit comments