-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Suppress Quarkus warnings generated for changing solver runtime …
…properties In order to know the names of Solver beans to generate, the SolverBuildTimeConfig must extend the SolverRuntimeConfig, since all build time properties of SolverBuildTimeConfig are optional (so a named Solver might only be defined by termination, which is a runtime property). Quarkus does not provide a mechanism for defining additional produces/instances of a bean at runtime (it goes against doing all possible work at build time), and thus, all names of Solver beans MUST be known at build time. You cannot read a RuntimeConfig object inside a processor; all its methods will be null. Thus, it is impossible to get a list of runtime properties that were defined at build time. Having SolverBuildTimeConfig extend SolverRuntimeConfig causes an issue. Namely, Quarkus, will generate a warning if a SolverRuntimeConfig property changes at runtime, since, by definition, it is also a SolverBuildTimeConfig property. Quarkus provides a handy build item for surpressing the warning (although its intended use is to hide sensitive data): SuppressNonRuntimeConfigChangedWarningBuildItem. Unfortunately, we need the EXACT name of the property to hide (there was no programmatic method available for getting the name from a method or class). Thus, we use ConfigurationBuildItem to get all build time properties (which natuarally includes the SolverBuildTimeConfig properties), filter them to check only properties that start with TimefoldBuildTimeConfig prefix, and suppress warnings for any property that match the filter and ends with a runtime property suffix.
- Loading branch information
1 parent
6271534
commit 10450fb
Showing
4 changed files
with
131 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...java/ai/timefold/solver/quarkus/TimefoldProcessorWarningBuildTimePropertyChangedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ai.timefold.solver.quarkus; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.logging.Level; | ||
|
||
import ai.timefold.solver.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider; | ||
import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusEntity; | ||
import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusSolution; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class TimefoldProcessorWarningBuildTimePropertyChangedTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.timefold.solver.daemon", "true") | ||
// We overwrite the value at runtime | ||
.overrideRuntimeConfigKey("quarkus.timefold.solver.daemon", "false") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestdataQuarkusEntity.class, TestdataQuarkusSolution.class, | ||
TestdataQuarkusConstraintProvider.class)) | ||
// Make sure Quarkus does not produce a warning for overwriting a build time value at runtime | ||
.setLogRecordPredicate(record -> record.getLoggerName().startsWith("io.quarkus") | ||
&& record.getLevel().intValue() >= Level.WARNING.intValue()) | ||
.assertLogRecords(logRecords -> { | ||
assertEquals(1, logRecords.size(), "expected warning to be generated"); | ||
}); | ||
|
||
@Test | ||
void solverProperties() { | ||
// Test is done by assertLogRecords | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...t/java/ai/timefold/solver/quarkus/TimefoldProcessorWarningRuntimePropertyChangedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ai.timefold.solver.quarkus; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.logging.Level; | ||
|
||
import ai.timefold.solver.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider; | ||
import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusEntity; | ||
import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusSolution; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class TimefoldProcessorWarningRuntimePropertyChangedTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.timefold.solver.move-thread-count", "1") | ||
.overrideConfigKey("quarkus.timefold.solver.termination.spent-limit", "1s") | ||
// We overwrite the value at runtime | ||
.overrideRuntimeConfigKey("quarkus.timefold.solver.move-thread-count", "2") | ||
.overrideRuntimeConfigKey("quarkus.timefold.solver.termination.spent-limit", "2s") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestdataQuarkusEntity.class, TestdataQuarkusSolution.class, | ||
TestdataQuarkusConstraintProvider.class)) | ||
// Make sure Quarkus does not produce a warning for overwriting a build time value at runtime | ||
.setLogRecordPredicate(record -> record.getLoggerName().startsWith("io.quarkus") | ||
&& record.getLevel().intValue() >= Level.WARNING.intValue()) | ||
.assertLogRecords(logRecords -> { | ||
assertEquals(0, logRecords.size(), "expected no warnings to be generated"); | ||
}); | ||
|
||
@Test | ||
void solverProperties() { | ||
// Test is done by assertLogRecords | ||
} | ||
} |