feat: validate shadow v3 snapshot settings

This commit is contained in:
zgw
2026-09-03 10:52:01 +08:00
parent 8816ffe7f4
commit 03ddf3f386
7 changed files with 83 additions and 2 deletions

View File

@@ -33,6 +33,8 @@ class ShadowConfigurationTest {
assertThat(shadow.isEnabled()).isFalse();
assertThat(shadow.getWarehouseId()).isEmpty();
assertThat(shadow.getTimeoutSeconds()).isEqualTo(3);
assertThat(shadow.getSnapshotMaxAgeSeconds()).isEqualTo(60);
assertThat(shadow.getQuietIntervalMillis()).isEqualTo(1000);
assertThat(algorithm.getMode()).isEqualTo(SchedulingMode.SHADOW);
assertThat(algorithm.isDatabaseWritesEnabled()).isTrue();
assertThat(algorithm.getWarehouseId()).isEqualTo("01");

View File

@@ -59,6 +59,23 @@ class ShadowSafetyGuardTest {
.doesNotThrowAnyException();
}
@Test
void rejectsSnapshotAndQuietIntervalOutsideValidatedRanges() {
ShadowObservationProperties shadow = enabledShadow();
AlgorithmProperties algorithm = new AlgorithmProperties();
algorithm.setMode(SchedulingMode.SHADOW);
algorithm.setDatabaseWritesEnabled(true);
shadow.setSnapshotMaxAgeSeconds(4);
assertThatThrownBy(() -> new ShadowSafetyGuard(shadow, algorithm).validate())
.hasMessageContaining("between 5 and 300");
shadow.setSnapshotMaxAgeSeconds(60);
shadow.setQuietIntervalMillis(10001);
assertThatThrownBy(() -> new ShadowSafetyGuard(shadow, algorithm).validate())
.hasMessageContaining("between 100 and 10000");
}
private ShadowObservationProperties enabledShadow() {
ShadowObservationProperties properties = new ShadowObservationProperties();
properties.setEnabled(true);

View File

@@ -0,0 +1,15 @@
package com.ruoyi.algorithm.shadow;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class WarehouseIdNormalizerTest {
@Test
void comparesNumericIdsByValueAndOtherIdsAfterTrimming() {
assertThat(WarehouseIdNormalizer.equivalent("1", "01")).isTrue();
assertThat(WarehouseIdNormalizer.equivalent(" 01 ", "1")).isTrue();
assertThat(WarehouseIdNormalizer.equivalent("W02", "01")).isFalse();
assertThat(WarehouseIdNormalizer.equivalent(" W02 ", "W02")).isTrue();
}
}