Skip to content

Commit

Permalink
fix: address quarkus upgrade issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfred committed Sep 4, 2024
1 parent 90f52ac commit f6ce686
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

/**
* During build time, this is translated into Timefold's Config classes.
*/
@ConfigRoot(name = "timefold.benchmark")
public class TimefoldBenchmarkBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.timefold.benchmark")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface TimefoldBenchmarkBuildTimeConfig {

String DEFAULT_SOLVER_BENCHMARK_CONFIG_URL = "solverBenchmarkConfig.xml";

public static final String DEFAULT_SOLVER_BENCHMARK_CONFIG_URL = "solverBenchmarkConfig.xml";
/**
* A classpath resource to read the benchmark configuration XML.
* Defaults to {@value DEFAULT_SOLVER_BENCHMARK_CONFIG_URL}.
* If this property isn't specified, that solverBenchmarkConfig.xml is optional.
*/
@ConfigItem
Optional<String> solverBenchmarkConfigXml;
Optional<String> solverBenchmarkConfigXml();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FeatureBuildItem feature() {

@BuildStep
HotDeploymentWatchedFileBuildItem watchSolverBenchmarkConfigXml() {
String solverBenchmarkConfigXML = timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml
String solverBenchmarkConfigXML = timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml()
.orElse(TimefoldBenchmarkBuildTimeConfig.DEFAULT_SOLVER_BENCHMARK_CONFIG_URL);
return new HotDeploymentWatchedFileBuildItem(solverBenchmarkConfigXML);
}
Expand All @@ -56,8 +56,8 @@ BenchmarkConfigBuildItem registerAdditionalBeans(BuildProducer<AdditionalBeanBui
}
PlannerBenchmarkConfig benchmarkConfig;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml.isPresent()) {
String solverBenchmarkConfigXML = timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml.get();
if (timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml().isPresent()) {
String solverBenchmarkConfigXML = timefoldBenchmarkBuildTimeConfig.solverBenchmarkConfigXml().get();
if (classLoader.getResource(solverBenchmarkConfigXML) == null) {
throw new ConfigurationException("Invalid quarkus.timefold.benchmark.solver-benchmark-config-xml property ("
+ solverBenchmarkConfigXML + "): that classpath resource does not exist.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 TimefoldBenchmarkProcessorBenchmarkCustomConfigTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.overrideConfigKey("quarkus.timefold.benchmark.solver.termination.best-score-limit", "0")
.overrideConfigKey("quarkus.timefold.benchmark.solver-benchmark-config-xml", "customSolverBenchmarkConfig.xml")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource("customSolverBenchmarkConfig.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,8 @@
<?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">

<solverBenchmarkBluePrint>
<solverBenchmarkBluePrintType>EVERY_LOCAL_SEARCH_TYPE</solverBenchmarkBluePrintType>
</solverBenchmarkBluePrint>
</plannerBenchmark>

0 comments on commit f6ce686

Please sign in to comment.