This is an automated email from the ASF dual-hosted git repository.
mxm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-kubernetes-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 984feada [FLINK-30593] Add tests for
ScalingTracking#removeOldRecords() (#715)
984feada is described below
commit 984feada491ad6fc32a57db33f9467ce43a59012
Author: Alexander Fedulov <[email protected]>
AuthorDate: Mon Nov 27 11:43:45 2023 +0100
[FLINK-30593] Add tests for ScalingTracking#removeOldRecords() (#715)
---
.../flink/autoscaler/ScalingTrackingTest.java | 56 ++++++++++++++++++----
1 file changed, 46 insertions(+), 10 deletions(-)
diff --git
a/flink-autoscaler/src/test/java/org/apache/flink/autoscaler/ScalingTrackingTest.java
b/flink-autoscaler/src/test/java/org/apache/flink/autoscaler/ScalingTrackingTest.java
index 28ebe561..6a5fcba6 100644
---
a/flink-autoscaler/src/test/java/org/apache/flink/autoscaler/ScalingTrackingTest.java
+++
b/flink-autoscaler/src/test/java/org/apache/flink/autoscaler/ScalingTrackingTest.java
@@ -105,16 +105,6 @@ class ScalingTrackingTest {
assertThat(result).isEqualTo(configuredMaxRestartTime);
}
- private void setUpScalingRecords(Duration secondRescaleDuration) {
- scalingTracking.addScalingRecord(
- Instant.parse("2023-11-15T16:00:00.00Z"),
- new ScalingRecord(Instant.parse("2023-11-15T16:03:00.00Z")));
- var secondRecordStart = Instant.parse("2023-11-15T16:20:00.00Z");
- scalingTracking.addScalingRecord(
- secondRecordStart,
- new
ScalingRecord(secondRecordStart.plus(secondRescaleDuration)));
- }
-
@Test
void shouldSetEndTime_WhenParallelismMatches() {
var now = Instant.now();
@@ -155,6 +145,52 @@ class ScalingTrackingTest {
.isNull();
}
+ @Test
+ public void removeOldRecordsShouldNotFail_WhenNoRecords() {
+ scalingTracking.removeOldRecords(Instant.now(), Duration.ofHours(1),
10);
+ assertThat(scalingTracking.getScalingRecords()).isEmpty();
+ }
+
+ @Test
+ public void shouldRemoveOldRecords_ByTimeSpan() {
+ Instant now = Instant.now();
+ scalingTracking.addScalingRecord(now.minus(Duration.ofHours(3)), new
ScalingRecord());
+ scalingTracking.addScalingRecord(now.minus(Duration.ofHours(2)), new
ScalingRecord());
+ scalingTracking.addScalingRecord(now.minus(Duration.ofHours(1)), new
ScalingRecord());
+ scalingTracking.removeOldRecords(now, Duration.ofHours(1), 10);
+ assertThat(scalingTracking.getScalingRecords()).hasSize(1);
+ }
+
+ @Test
+ public void shouldRemoveRecords_WhenExceedingMaxCount() {
+ Instant now = Instant.now();
+ for (int i = 0; i < 10; i++) {
+ scalingTracking.addScalingRecord(now.minus(Duration.ofMinutes(i)),
new ScalingRecord());
+ }
+ scalingTracking.removeOldRecords(now, Duration.ofHours(1), 5);
+ assertThat(scalingTracking.getScalingRecords()).hasSize(5);
+ }
+
+ @Test
+ public void shouldAlwaysKeepAtLeastOneLatestRecord_WhenOutOfTimeSpan() {
+ Instant now = Instant.now();
+ scalingTracking.addScalingRecord(
+ now.minus(Duration.ofDays(1)),
+ new ScalingRecord()); // This is the only record and is old
+ scalingTracking.removeOldRecords(now, Duration.ofHours(1), 10);
+ assertThat(scalingTracking.getScalingRecords()).hasSize(1);
+ }
+
+ private void setUpScalingRecords(Duration secondRescaleDuration) {
+ scalingTracking.addScalingRecord(
+ Instant.parse("2023-11-15T16:00:00.00Z"),
+ new ScalingRecord(Instant.parse("2023-11-15T16:03:00.00Z")));
+ var secondRecordStart = Instant.parse("2023-11-15T16:20:00.00Z");
+ scalingTracking.addScalingRecord(
+ secondRecordStart,
+ new
ScalingRecord(secondRecordStart.plus(secondRescaleDuration)));
+ }
+
private void addScalingRecordWithoutEndTime(Instant startTime) {
ScalingRecord record = new ScalingRecord();
scalingTracking.addScalingRecord(startTime, record);