Description
HedgeConfig.ofDefaults() currently creates a config whose duration supplier type is PRECONFIGURED, but the configured cutoff duration is null.
This means HedgeDurationSupplier.fromConfig(HedgeConfig.ofDefaults()) creates a PreconfiguredDurationSupplier with a null cutoff. The supplier can then return null, and the default Hedge execution path may fail later when HedgeImpl calls durationSupplier.get().toNanos().
There is a related copy-builder issue in HedgeConfig.from(...): HedgeConfig.Builder(HedgeConfig baseConfig) does not copy durationSupplierType from the source config. As a result, a config using AVERAGE_PLUS can silently become PRECONFIGURED after being copied.
Tests
The issue can be reproduced by adding the following tests to HedgeConfigTest. When executed, shouldCreateUsableDefaultDurationSupplier fails because the default duration supplier returns null, and shouldInitializeDurationSupplierTypeFromOtherConfig fails because the copied config's supplier type is PRECONFIGURED instead of the expected AVERAGE_PLUS.
@Test
public void shouldCreateUsableDefaultDurationSupplier() {
HedgeDurationSupplier supplier = HedgeDurationSupplier.fromConfig(HedgeConfig.ofDefaults());
then(supplier.get()).isNotNull();
}
@Test
public void shouldInitializeDurationSupplierTypeFromOtherConfig() {
HedgeConfig config = HedgeConfig.custom()
.averagePlusAmountDuration(200, false, 100).build();
HedgeConfig copiedConfig = HedgeConfig.from(config).build();
then(copiedConfig.getDurationSupplier())
.isEqualTo(HedgeConfig.HedgeDurationSupplierType.AVERAGE_PLUS);
}
Failure result:
HedgeConfigTest > shouldInitializeDurationSupplierTypeFromOtherConfig FAILED
org.opentest4j.AssertionFailedError at HedgeConfigTest.java:70
HedgeConfigTest > shouldCreateUsableDefaultDurationSupplier FAILED
java.lang.AssertionError at HedgeConfigTest.java:59
Expected behavior
HedgeConfig.ofDefaults() should create a usable default duration supplier.
HedgeConfig.from(existingConfig).build() should preserve the source config's duration supplier type.
Description
HedgeConfig.ofDefaults()currently creates a config whose duration supplier type isPRECONFIGURED, but the configured cutoff duration isnull.This means
HedgeDurationSupplier.fromConfig(HedgeConfig.ofDefaults())creates aPreconfiguredDurationSupplierwith anullcutoff. The supplier can then returnnull, and the defaultHedgeexecution path may fail later whenHedgeImplcallsdurationSupplier.get().toNanos().There is a related copy-builder issue in
HedgeConfig.from(...):HedgeConfig.Builder(HedgeConfig baseConfig)does not copydurationSupplierTypefrom the source config. As a result, a config usingAVERAGE_PLUScan silently becomePRECONFIGUREDafter being copied.Tests
The issue can be reproduced by adding the following tests to
HedgeConfigTest. When executed,shouldCreateUsableDefaultDurationSupplierfails because the default duration supplier returnsnull, andshouldInitializeDurationSupplierTypeFromOtherConfigfails because the copied config's supplier type isPRECONFIGUREDinstead of the expectedAVERAGE_PLUS.Failure result:
Expected behavior
HedgeConfig.ofDefaults()should create a usable default duration supplier.HedgeConfig.from(existingConfig).build()should preserve the source config's duration supplier type.