|
71 | 71 |
|
72 | 72 | import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLengthBetween; |
73 | 73 | import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.randomPopulateAndReads; |
| 74 | +import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.PAGE_SIZE; |
74 | 75 | import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.pageAligned; |
75 | 76 |
|
76 | 77 | public abstract class AbstractSearchableSnapshotsTestCase extends ESIndexInputTestCase { |
@@ -211,25 +212,20 @@ protected static ByteSizeValue randomFrozenCacheSize() { |
211 | 212 | * @return a random {@link ByteSizeValue} that can be used to set {@link CacheService#SNAPSHOT_CACHE_RANGE_SIZE_SETTING} |
212 | 213 | */ |
213 | 214 | protected static ByteSizeValue randomCacheRangeSize() { |
214 | | - return pageAligned( |
215 | | - new ByteSizeValue( |
216 | | - randomLongBetween( |
217 | | - CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(), |
218 | | - CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes() |
219 | | - ) |
220 | | - ) |
221 | | - ); |
| 215 | + return pageAlignedBetween(CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE); |
222 | 216 | } |
223 | 217 |
|
224 | 218 | protected static ByteSizeValue randomFrozenCacheRangeSize() { |
225 | | - return pageAligned( |
226 | | - new ByteSizeValue( |
227 | | - randomLongBetween( |
228 | | - FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(), |
229 | | - FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes() |
230 | | - ) |
231 | | - ) |
232 | | - ); |
| 219 | + return pageAlignedBetween(FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE); |
| 220 | + } |
| 221 | + |
| 222 | + private static ByteSizeValue pageAlignedBetween(ByteSizeValue min, ByteSizeValue max) { |
| 223 | + ByteSizeValue aligned = pageAligned(new ByteSizeValue(randomLongBetween(min.getBytes(), max.getBytes()))); |
| 224 | + if (aligned.compareTo(max) > 0) { |
| 225 | + // minus one page in case page alignment moved us past the max setting value |
| 226 | + return new ByteSizeValue(aligned.getBytes() - PAGE_SIZE); |
| 227 | + } |
| 228 | + return aligned; |
233 | 229 | } |
234 | 230 |
|
235 | 231 | protected static SearchableSnapshotRecoveryState createRecoveryState(boolean finalizedDone) { |
|
0 commit comments