|
@@ -12,6 +12,7 @@ package org.elasticsearch.action.admin.cluster.stats;
|
|
|
import org.elasticsearch.action.admin.cluster.stats.CCSTelemetrySnapshot.PerClusterCCSTelemetry;
|
|
|
import org.elasticsearch.action.admin.cluster.stats.LongMetric.LongMetricValue;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
import org.elasticsearch.core.Tuple;
|
|
@@ -32,9 +33,13 @@ import static org.hamcrest.Matchers.equalTo;
|
|
|
public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<CCSTelemetrySnapshot> {
|
|
|
|
|
|
private LongMetricValue randomLongMetricValue() {
|
|
|
+ return randomLongMetricValueBetween(0, 1_000_000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LongMetricValue randomLongMetricValueBetween(int low, int high) {
|
|
|
LongMetric v = new LongMetric();
|
|
|
for (int i = 0; i < randomIntBetween(5, 10); i++) {
|
|
|
- v.record(randomIntBetween(0, 1_000_000));
|
|
|
+ v.record(randomIntBetween(low, high));
|
|
|
}
|
|
|
return v.getValue();
|
|
|
}
|
|
@@ -330,4 +335,21 @@ public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<C
|
|
|
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testRanges() throws IOException {
|
|
|
+ var value1 = randomLongMetricValueBetween(1_000_000, 10_000_000);
|
|
|
+ var count1 = value1.count();
|
|
|
+ var max1 = value1.max();
|
|
|
+ var output = new BytesStreamOutput();
|
|
|
+ value1.writeTo(output);
|
|
|
+ var value1Read = LongMetricValue.fromStream(output.bytes().streamInput());
|
|
|
+ var value2 = randomLongMetricValueBetween(0, 100);
|
|
|
+ var count2 = value2.count();
|
|
|
+ output = new BytesStreamOutput();
|
|
|
+ value2.writeTo(output);
|
|
|
+ var value2Read = LongMetricValue.fromStream(output.bytes().streamInput());
|
|
|
+ value2Read.add(value1Read);
|
|
|
+ assertThat(value2Read.count(), equalTo(count1 + count2));
|
|
|
+ assertThat(value2Read.max(), equalTo(max1));
|
|
|
+ }
|
|
|
}
|