Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensuring the spent termination property is read in the Quarkus environment #600

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ai.timefold.solver.benchmark.quarkus;

import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import jakarta.inject.Inject;

import ai.timefold.solver.benchmark.api.PlannerBenchmarkFactory;
import ai.timefold.solver.benchmark.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider;
import ai.timefold.solver.benchmark.quarkus.testdata.normal.domain.TestdataQuarkusEntity;
import ai.timefold.solver.benchmark.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 TimefoldBenchmarkProcessorBenchmarkEmptyTerminationConfigTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.overrideConfigKey("quarkus.timefold.benchmark.solver.termination.spent-limit", "3s")
.overrideConfigKey("quarkus.timefold.benchmark.solver-benchmark-config-xml",
"emptySolverBenchmarkConfig.xml")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource("emptySolverBenchmarkConfig.xml")
.addClasses(TestdataQuarkusEntity.class,
TestdataQuarkusSolution.class, TestdataQuarkusConstraintProvider.class));

@Inject
PlannerBenchmarkFactory benchmarkFactory;

@Test
void benchmark() throws ExecutionException, InterruptedException {
TestdataQuarkusSolution problem = new TestdataQuarkusSolution();
problem.setValueList(IntStream.range(1, 3)
.mapToObj(i -> "v" + i)
.collect(Collectors.toList()));
problem.setEntityList(IntStream.range(1, 3)
.mapToObj(i -> new TestdataQuarkusEntity())
.collect(Collectors.toList()));
benchmarkFactory.buildPlannerBenchmark(problem).benchmark();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ai.timefold.solver.benchmark.quarkus;

import static org.assertj.core.api.Assertions.assertThat;

import ai.timefold.solver.benchmark.config.PlannerBenchmarkConfig;
import ai.timefold.solver.benchmark.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider;
import ai.timefold.solver.benchmark.quarkus.testdata.normal.domain.TestdataQuarkusEntity;
import ai.timefold.solver.benchmark.quarkus.testdata.normal.domain.TestdataQuarkusSolution;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class TimefoldBenchmarkProcessorMissingSpentLimitWithXmlTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.overrideConfigKey("quarkus.timefold.benchmark.solver-benchmark-config-xml",
"emptySolverBenchmarkConfig.xml")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource("emptySolverBenchmarkConfig.xml")
.addClasses(TestdataQuarkusEntity.class,
TestdataQuarkusSolution.class, TestdataQuarkusConstraintProvider.class));

@Test
void benchmark() throws InterruptedException {
IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class,
() -> new TimefoldBenchmarkRecorder().benchmarkConfigSupplier(new PlannerBenchmarkConfig(), null).get());
assertThat(exception.getMessage()).contains("At least one of the properties",
"quarkus.timefold.benchmark.solver.termination.spent-limit",
"quarkus.timefold.benchmark.solver.termination.best-score-limit",
"quarkus.timefold.benchmark.solver.termination.unimproved-spent-limit",
"is required if termination is not configured");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<plannerBenchmark xmlns="https://timefold.ai/xsd/benchmark" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://timefold.ai/xsd/benchmark https://timefold.ai/xsd/benchmark/benchmark.xsd">
</plannerBenchmark>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public Supplier<PlannerBenchmarkConfig> benchmarkConfigSupplier(PlannerBenchmark
return () -> {
SolverConfig solverConfig =
Arc.container().instance(SolverConfig.class).get();
// If the termination configuration is set and the created benchmark configuration has no configuration item,
// we need to add at least one configuration; otherwise, we will fail to recognize the runtime termination setting.
if (benchmarkConfig != null && benchmarkConfig.getSolverBenchmarkConfigList() == null &&
timefoldRuntimeConfig != null && timefoldRuntimeConfig.termination() != null) {
benchmarkConfig.setSolverBenchmarkConfigList(Collections.singletonList(new SolverBenchmarkConfig()));
}
return updateBenchmarkConfigWithRuntimeProperties(benchmarkConfig, timefoldRuntimeConfig, solverConfig);
};
}
Expand Down