|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.cluster; |
| 11 | + |
| 12 | +import org.elasticsearch.test.ESTestCase; |
| 13 | + |
| 14 | +import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 15 | +import static org.hamcrest.Matchers.lessThanOrEqualTo; |
| 16 | + |
| 17 | +public class ShardHeapUsageTests extends ESTestCase { |
| 18 | + |
| 19 | + public void testEstimatedUsageAsPercentage() { |
| 20 | + final long totalBytes = randomNonNegativeLong(); |
| 21 | + final long estimatedUsageBytes = randomLongBetween(0, totalBytes); |
| 22 | + final ShardHeapUsage shardHeapUsage = new ShardHeapUsage(randomUUID(), randomIdentifier(), totalBytes, estimatedUsageBytes); |
| 23 | + assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); |
| 24 | + assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); |
| 25 | + assertEquals(shardHeapUsage.estimatedUsageAsPercentage(), 100.0 * estimatedUsageBytes / totalBytes, 0.0001); |
| 26 | + } |
| 27 | + |
| 28 | + public void testEstimatedFreeBytesAsPercentage() { |
| 29 | + final long totalBytes = randomNonNegativeLong(); |
| 30 | + final long estimatedUsageBytes = randomLongBetween(0, totalBytes); |
| 31 | + final long estimatedFreeBytes = totalBytes - estimatedUsageBytes; |
| 32 | + final ShardHeapUsage shardHeapUsage = new ShardHeapUsage(randomUUID(), randomIdentifier(), totalBytes, estimatedUsageBytes); |
| 33 | + assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); |
| 34 | + assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); |
| 35 | + assertEquals(shardHeapUsage.estimatedFreeBytesAsPercentage(), 100.0 * estimatedFreeBytes / totalBytes, 0.0001); |
| 36 | + } |
| 37 | +} |
0 commit comments