Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLengthBetween;
import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.randomPopulateAndReads;
import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.PAGE_SIZE;
import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.pageAligned;

public abstract class AbstractSearchableSnapshotsTestCase extends ESIndexInputTestCase {
Expand Down Expand Up @@ -211,25 +212,20 @@ protected static ByteSizeValue randomFrozenCacheSize() {
* @return a random {@link ByteSizeValue} that can be used to set {@link CacheService#SNAPSHOT_CACHE_RANGE_SIZE_SETTING}
*/
protected static ByteSizeValue randomCacheRangeSize() {
return pageAligned(
new ByteSizeValue(
randomLongBetween(
CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(),
CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes()
)
)
);
return pageAlignedBetween(CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE);
}

protected static ByteSizeValue randomFrozenCacheRangeSize() {
return pageAligned(
new ByteSizeValue(
randomLongBetween(
FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(),
FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes()
)
)
);
return pageAlignedBetween(FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE);
}

private static ByteSizeValue pageAlignedBetween(ByteSizeValue min, ByteSizeValue max) {
ByteSizeValue aligned = pageAligned(new ByteSizeValue(randomLongBetween(min.getBytes(), max.getBytes())));
if (aligned.compareTo(max) > 0) {
// minus one page in case page alignment moved us past the max setting value
return new ByteSizeValue(aligned.getBytes() - PAGE_SIZE);
}
return aligned;
}

protected static SearchableSnapshotRecoveryState createRecoveryState(boolean finalizedDone) {
Expand Down