Search in sources :

Example 1 with ByteSizeUnit

use of org.opensearch.common.unit.ByteSizeUnit in project OpenSearch by opensearch-project.

the class S3BlobStoreContainerTests method testNumberOfMultiparts.

public void testNumberOfMultiparts() {
    final ByteSizeUnit unit = randomFrom(ByteSizeUnit.BYTES, ByteSizeUnit.KB, ByteSizeUnit.MB, ByteSizeUnit.GB);
    final long size = unit.toBytes(randomIntBetween(2, 1000));
    final int factor = randomIntBetween(2, 10);
    // Fits in 1 empty part
    assertNumberOfMultiparts(1, 0L, 0L, size);
    // Fits in 1 part exactly
    assertNumberOfMultiparts(1, size, size, size);
    assertNumberOfMultiparts(1, size, size, size * factor);
    // Fits in N parts exactly
    assertNumberOfMultiparts(factor, size, size * factor, size);
    // Fits in N parts plus a bit more
    final long remaining = randomIntBetween(1, (size > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) size - 1);
    assertNumberOfMultiparts(factor + 1, remaining, (size * factor) + remaining, size);
}
Also used : ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit)

Example 2 with ByteSizeUnit

use of org.opensearch.common.unit.ByteSizeUnit in project OpenSearch by opensearch-project.

the class BytesProcessorTests method modifyInput.

@Override
protected String modifyInput(String input) {
    // largest value that allows all results < Long.MAX_VALUE bytes
    long randomNumber = randomLongBetween(1, Long.MAX_VALUE / ByteSizeUnit.PB.toBytes(1));
    ByteSizeUnit randomUnit = randomFrom(ByteSizeUnit.values());
    modifiedInput = randomNumber + randomUnit.getSuffix();
    return modifiedInput;
}
Also used : ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit)

Aggregations

ByteSizeUnit (org.opensearch.common.unit.ByteSizeUnit)2