fix(lingxing): allow bounded configurable business request pacing
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
package com.baiyue.integration.config;
|
||||
|
||||
import com.baiyue.integration.dto.lingxing.LingxingEgressDtos.CollectionMode;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class LingxingEgressPropertiesTest {
|
||||
private LingxingEgressProperties properties(CollectionMode mode, Duration interval, Duration cooldown) {
|
||||
return new LingxingEgressProperties(mode, "test", null, null, null, null, interval, cooldown);
|
||||
}
|
||||
|
||||
@Test void businessAcceptsPositiveMillisecondIntervalsIncludingProbeSteps() {
|
||||
for (long millis : new long[]{1, 1500, 2000, 3000, 5000, 300000}) {
|
||||
assertThat(properties(CollectionMode.BUSINESS, Duration.ofMillis(millis), null).minStartInterval())
|
||||
.isEqualTo(Duration.ofMillis(millis));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void businessRejectsSubMillisecondNonPositiveAndExcessiveIntervals() {
|
||||
for (Duration interval : List.of(Duration.ofMillis(-1), Duration.ZERO,
|
||||
Duration.ofNanos(999999), Duration.ofMinutes(5).plusMillis(1))) {
|
||||
assertThatThrownBy(() -> properties(CollectionMode.BUSINESS, interval, null))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test void validationRetainsFiveSecondMinimumAndAllModesDefaultToFiveSeconds() {
|
||||
for (CollectionMode mode : CollectionMode.values()) {
|
||||
assertThat(properties(mode, null, null).minStartInterval()).isEqualTo(Duration.ofSeconds(5));
|
||||
if (mode == CollectionMode.VALIDATION) {
|
||||
assertThatThrownBy(() -> properties(mode, Duration.ofMillis(4999), null))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThat(properties(mode, Duration.ofSeconds(5), null).minStartInterval())
|
||||
.isEqualTo(Duration.ofSeconds(5));
|
||||
}
|
||||
}
|
||||
assertThat(properties(null, null, null).collectionMode()).isEqualTo(CollectionMode.OFF);
|
||||
}
|
||||
|
||||
@Test void switchingBusinessOffCanRetainItsThreeSecondInterval() {
|
||||
var business = properties(CollectionMode.BUSINESS, Duration.ofSeconds(3), null);
|
||||
assertThat(properties(CollectionMode.OFF, business.minStartInterval(), null).minStartInterval())
|
||||
.isEqualTo(Duration.ofSeconds(3));
|
||||
assertThatThrownBy(() -> properties(CollectionMode.OFF, Duration.ZERO, null))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test void businessIntervalChangeDoesNotRelaxCooldownBounds() {
|
||||
for (Duration cooldown : List.of(Duration.ofMillis(4999), Duration.ofDays(1).plusMillis(1))) {
|
||||
assertThatThrownBy(() -> properties(CollectionMode.BUSINESS, Duration.ofMillis(1), cooldown))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
for (Duration cooldown : List.of(Duration.ofSeconds(5), Duration.ofDays(1))) {
|
||||
assertThat(properties(CollectionMode.BUSINESS, Duration.ofMillis(1), cooldown).cooldownFallback())
|
||||
.isEqualTo(cooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user