|
12 | 12 | import org.elasticsearch.action.admin.cluster.stats.CCSTelemetrySnapshot.PerClusterCCSTelemetry; |
13 | 13 | import org.elasticsearch.action.admin.cluster.stats.LongMetric.LongMetricValue; |
14 | 14 | import org.elasticsearch.common.bytes.BytesArray; |
| 15 | +import org.elasticsearch.common.io.stream.BytesStreamOutput; |
15 | 16 | import org.elasticsearch.common.io.stream.Writeable; |
16 | 17 | import org.elasticsearch.common.xcontent.XContentHelper; |
17 | 18 | import org.elasticsearch.core.Tuple; |
|
32 | 33 | public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<CCSTelemetrySnapshot> { |
33 | 34 |
|
34 | 35 | private LongMetricValue randomLongMetricValue() { |
| 36 | + return randomLongMetricValueBetween(0, 1_000_000); |
| 37 | + } |
| 38 | + |
| 39 | + private LongMetricValue randomLongMetricValueBetween(int low, int high) { |
35 | 40 | LongMetric v = new LongMetric(); |
36 | 41 | for (int i = 0; i < randomIntBetween(5, 10); i++) { |
37 | | - v.record(randomIntBetween(0, 1_000_000)); |
| 42 | + v.record(randomIntBetween(low, high)); |
38 | 43 | } |
39 | 44 | return v.getValue(); |
40 | 45 | } |
@@ -330,4 +335,21 @@ private String readJSONFromResource(String fileName) throws IOException { |
330 | 335 | return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); |
331 | 336 | } |
332 | 337 | } |
| 338 | + |
| 339 | + public void testRanges() throws IOException { |
| 340 | + var value1 = randomLongMetricValueBetween(1_000_000, 10_000_000); |
| 341 | + var count1 = value1.count(); |
| 342 | + var max1 = value1.max(); |
| 343 | + var output = new BytesStreamOutput(); |
| 344 | + value1.writeTo(output); |
| 345 | + var value1Read = LongMetricValue.fromStream(output.bytes().streamInput()); |
| 346 | + var value2 = randomLongMetricValueBetween(0, 100); |
| 347 | + var count2 = value2.count(); |
| 348 | + output = new BytesStreamOutput(); |
| 349 | + value2.writeTo(output); |
| 350 | + var value2Read = LongMetricValue.fromStream(output.bytes().streamInput()); |
| 351 | + value2Read.add(value1Read); |
| 352 | + assertThat(value2Read.count(), equalTo(count1 + count2)); |
| 353 | + assertThat(value2Read.max(), equalTo(max1)); |
| 354 | + } |
333 | 355 | } |
0 commit comments