This is an automated email from the ASF dual-hosted git repository. jiriondrusek pushed a commit to branch camel-main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/camel-main by this push: new 0a09d982a7 fixes in type convertors (because of CAMEL-19897)x 0a09d982a7 is described below commit 0a09d982a76dc39f69fd42cd0985713c18ebe605 Author: JiriOndrusek <ondrusek.j...@gmail.com> AuthorDate: Mon Jul 1 10:16:23 2024 +0200 fixes in type convertors (because of CAMEL-19897)x --- .../ROOT/pages/reference/extensions/core.adoc | 6 ++ .../quarkus/core/deployment/CamelProcessor.java | 4 +- .../org/apache/camel/quarkus/core/CamelConfig.java | 16 ++++++ .../apache/camel/quarkus/core/CamelRecorder.java | 4 +- .../camel/quarkus/core/FastTypeConverter.java | 4 +- .../core/converter/it/ConverterResource.java | 11 ++-- .../quarkus/core/converter/it/ConverterTest.java | 35 ----------- .../core/converter/it/ConverterTestBase.java | 6 +- .../converter/it/ConverterWithStatisticsIT.java | 23 ++++++++ ...rTest.java => ConverterWithStatisticsTest.java} | 67 ++++++++-------------- pom.xml | 2 +- .../quarkus/k/tooling/maven/GenerateRestXML.java | 24 ++------ 12 files changed, 88 insertions(+), 114 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc b/docs/modules/ROOT/pages/reference/extensions/core.adoc index f3a3328c80..672ec106df 100644 --- a/docs/modules/ROOT/pages/reference/extensions/core.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc @@ -395,6 +395,12 @@ Filter for tracing messages. | `string` | +|icon:lock[title=Fixed at build time] [[quarkus.camel.type-converter.statistics-enabled]]`link:#quarkus.camel.type-converter.statistics-enabled[quarkus.camel.type-converter.statistics-enabled]` + +Build time configuration options for enable/disable type converter statistics. +| `boolean` +| `true` + |icon:lock[title=Fixed at build time] [[quarkus.camel.main.shutdown.timeout]]`link:#quarkus.camel.main.shutdown.timeout[quarkus.camel.main.shutdown.timeout]` A timeout (with millisecond precision) to wait for `CamelMain++#++stop()` to finish diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java index cec76d1c94..e8184cf160 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java @@ -249,6 +249,7 @@ class CamelProcessor { @BuildStep CamelTypeConverterRegistryBuildItem typeConverterRegistry( CamelRecorder recorder, + CamelConfig camelConfig, ApplicationArchivesBuildItem applicationArchives, List<CamelTypeConverterLoaderBuildItem> additionalLoaders, CombinedIndexBuildItem combinedIndex, @@ -256,7 +257,8 @@ class CamelProcessor { IndexView index = combinedIndex.getIndex(); - RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry(); + RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder + .createTypeConverterRegistry(camelConfig.typeConverter.statisticsEnabled); // // This should be simplified by searching for classes implementing TypeConverterLoader but that diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java index fb1b2a8f30..796283117a 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java @@ -91,6 +91,12 @@ public class CamelConfig { @ConfigItem public TraceConfig trace; + /** + * Build time configuration options for the Camel type converter. + */ + @ConfigItem + public TypeConverterConfig typeConverter; + @ConfigGroup public static class BootstrapConfig { /** @@ -504,4 +510,14 @@ public class CamelConfig { @ConfigItem public Optional<String> traceFilter; } + + @ConfigGroup + public static class TypeConverterConfig { + + /** + * Build time configuration options for enable/disable type converter statistics. + */ + @ConfigItem(defaultValue = "true") + public boolean statisticsEnabled; + } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java index 95b77d2c6a..3dc39f6953 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java @@ -68,8 +68,8 @@ public class CamelRecorder { return new RuntimeValue<>(new RuntimeRegistry(beanQualifierResolvers)); } - public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry() { - return new RuntimeValue<>(new FastTypeConverter()); + public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry(boolean statisticsEnabled) { + return new RuntimeValue<>(new FastTypeConverter(statisticsEnabled)); } public void addTypeConverterLoader(RuntimeValue<TypeConverterRegistry> registry, RuntimeValue<TypeConverterLoader> loader) { diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java index f4587dc151..6de2ae21d9 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java @@ -24,8 +24,8 @@ import org.slf4j.LoggerFactory; public class FastTypeConverter extends DefaultTypeConverter { private static final Logger LOG = LoggerFactory.getLogger(FastTypeConverter.class); - public FastTypeConverter() { - super(null, null, null, false); + public FastTypeConverter(boolean statisticsEnabled) { + super(null, null, null, false, statisticsEnabled); } @Override diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java index 37f2bbe96e..4e0340a624 100644 --- a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java +++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java @@ -103,14 +103,11 @@ public class ConverterResource { return context.getTypeConverter().convertTo(MyNullablePair.class, input); } - @Path("/setStatisticsEnabled") - @POST + @Path("/resetStatistics") + @GET @Produces(MediaType.TEXT_PLAIN) - public void converterSetStatisticsEnabled(boolean value) { - context.getTypeConverterRegistry().getStatistics().setStatisticsEnabled(value); - if (value) { - context.getTypeConverterRegistry().getStatistics().reset(); - } + public void resetStatistics() { + context.getTypeConverterRegistry().getStatistics().reset(); } @Path("/getStatisticsHit") diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java index 3b79b05bf5..a57e7343b1 100644 --- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java @@ -17,7 +17,6 @@ package org.apache.camel.quarkus.core.converter.it; import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.*; @@ -47,28 +46,6 @@ public class ConverterTest extends ConverterTestBase { testConverter("/converter/myTestPair/float", "2.0", "test_2.0", "3.0"); } - @Test - void testConverterToNull() { - enableStatistics(true); - - testConverterReturningNull("/converter/myNullablePair", "null"); - - RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - - enableStatistics(false); - } - - @Test - void testNotRegisteredConverter() { - enableStatistics(true); - - testConverterReturningNull("/converter/myNotRegisteredPair", "a:b"); - - RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(0), "miss", is(1)); - - enableStatistics(false); - } - @Test void testBulkConverters() { //converters generated with @Converter(generateBulkLoader = true) @@ -81,16 +58,4 @@ public class ConverterTest extends ConverterTestBase { //converters generated with @Converter(generateLoader = true) testConverter("/converter/myLoaderPair", "a:b", "loader_a", "b"); } - - @Test - void testConverterGetStatistics() { - enableStatistics(true); - - //cause 1 hit - testConverterFromAnnotationWithStaticMethods(); - - RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - - enableStatistics(false); - } } diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java index e3e18cfb41..91d96e682f 100644 --- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java @@ -25,10 +25,10 @@ import static org.hamcrest.Matchers.is; public abstract class ConverterTestBase { - void enableStatistics(boolean b) { + void resetStatistics() { RestAssured.given() - .contentType(ContentType.TEXT).body(b) - .post("/converter/setStatisticsEnabled") + .contentType(ContentType.TEXT) + .get("/converter/resetStatistics") .then() .statusCode(204); } diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsIT.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsIT.java new file mode 100644 index 0000000000..855e87ee8a --- /dev/null +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsIT.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.core.converter.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class ConverterWithStatisticsIT extends ConverterWithStatisticsTest { +} diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsTest.java similarity index 54% copy from integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java copy to integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsTest.java index 3b79b05bf5..c2cacec869 100644 --- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterWithStatisticsTest.java @@ -18,79 +18,60 @@ package org.apache.camel.quarkus.core.converter.it; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; +/** + * The test requires the `quarkus.camel.type-converter.statistics-enabled=true`. + * + * For JVM mode, such behavior is achieved by the testProfile. + * For native mode, the quarkus-maven-plugin is executed twice with both false/true options in the property. + * Test profile changes the value to `true` for this class. + * Quarkus the uses `-Dquarkus.configuration.build-time-mismatch-at-runtime=fail + * -Dquarkus.camel.type-converter.statistics-enabled=true`. + * See https://quarkus.io/guides/reaugmentation for more details. + */ @QuarkusTest -public class ConverterTest extends ConverterTestBase { +public class ConverterWithStatisticsTest extends ConverterTestBase { - @Test - void testConverterFromRegistry() { - //converter from loader which is present in registry - testConverter("/converter/myRegistryPair", "a:b", "registry_a", "b"); + @BeforeEach + void beforeEach() { + resetStatistics(); } - @Test - void testConverterFromAnnotationWithStaticMethods() { - //converter with annotation present in this module - testConverter("/converter/myTestPair/string", "a:b", "test_a", "b"); - } - - @Test - void testConverterFromAnnotationWithNonStaticMethods() { - testConverter("/converter/myTestPair/int", "1", "test_1", "2"); - } - - @Test - void testConverterFromAnnotationAsCdiBean() { - testConverter("/converter/myTestPair/float", "2.0", "test_2.0", "3.0"); + @AfterEach + void afterEach() { + resetStatistics(); } @Test void testConverterToNull() { - enableStatistics(true); - testConverterReturningNull("/converter/myNullablePair", "null"); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - enableStatistics(false); + resetStatistics(); } @Test void testNotRegisteredConverter() { - enableStatistics(true); - testConverterReturningNull("/converter/myNotRegisteredPair", "a:b"); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(0), "miss", is(1)); - enableStatistics(false); - } - - @Test - void testBulkConverters() { - //converters generated with @Converter(generateBulkLoader = true) - testConverter("/converter/myBulk1Pair", "a:b", "bulk1_a", "b"); - testConverter("/converter/myBulk2Pair", "a:b", "bulk2_a", "b"); - } - - @Test - void testLoaderConverters() { - //converters generated with @Converter(generateLoader = true) - testConverter("/converter/myLoaderPair", "a:b", "loader_a", "b"); + resetStatistics(); } @Test void testConverterGetStatistics() { - enableStatistics(true); - //cause 1 hit - testConverterFromAnnotationWithStaticMethods(); + testConverter("/converter/myTestPair/string", "a:b", "test_a", "b"); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - enableStatistics(false); + resetStatistics(); } } diff --git a/pom.xml b/pom.xml index c1d83a3999..d011764bcd 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,7 @@ <github-api.version>1.313</github-api.version><!-- Used in a Groovy script bellow --> <google-auth-library.version>1.23.0</google-auth-library.version><!-- @sync com.google.cloud:google-cloud-pubsub:${google-cloud-pubsub.version} dep:com.google.auth:google-auth-library-oauth2-http --> <google-oauth-client.version>${google-oauth-client-version}</google-oauth-client.version> - <google-cloud-bom.version>0.222.0</google-cloud-bom.version><!-- @sync com.google.cloud:libraries-bom:${google-cloud-bom-version} dep:com.google.cloud:google-cloud-bom --> + <google-cloud-bom.version>0.223.0</google-cloud-bom.version><!-- @sync com.google.cloud:libraries-bom:${google-cloud-bom-version} dep:com.google.cloud:google-cloud-bom --> <google-cloud-pubsub-bom.version>1.130.0</google-cloud-pubsub-bom.version><!-- @sync com.google.cloud:google-cloud-bom:${google-cloud-bom.version} dep:com.google.cloud:google-cloud-pubsub-bom --> <google-cloud-pubsub.version>1.130.0</google-cloud-pubsub.version><!-- @sync com.google.cloud:google-cloud-pubsub-bom:${google-cloud-pubsub-bom.version} dep:com.google.cloud:google-cloud-pubsub --> <graalvm.version>23.1.2</graalvm.version><!-- @sync io.quarkus:quarkus-bom:${quarkus.version} dep:org.graalvm.sdk:graal-sdk --> diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/quarkus/k/tooling/maven/GenerateRestXML.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/quarkus/k/tooling/maven/GenerateRestXML.java index c451167248..c3c572afe1 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/quarkus/k/tooling/maven/GenerateRestXML.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/quarkus/k/tooling/maven/GenerateRestXML.java @@ -16,20 +16,14 @@ */ package org.apache.camel.quarkus.k.tooling.maven; -import java.io.FileInputStream; import java.io.PrintWriter; import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import io.apicurio.datamodels.Library; -import io.apicurio.datamodels.models.openapi.OpenApiDocument; -import io.apicurio.datamodels.models.util.JsonUtil; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.parser.OpenAPIV3Parser; import org.apache.camel.CamelContext; import org.apache.camel.generator.openapi.RestDslXmlGenerator; import org.apache.camel.impl.DefaultCamelContext; @@ -59,18 +53,8 @@ class GenerateRestXML extends AbstractMojo { } try { - JsonFactory factory = null; - if (inputFile.endsWith(".yaml") || inputFile.endsWith(".yml")) { - factory = new YAMLFactory(); - } - - ObjectMapper mapper = new ObjectMapper(factory); - mapper.findAndRegisterModules(); - - FileInputStream fis = new FileInputStream(inputFile); - - JsonNode node = mapper.readTree(fis); - OpenApiDocument document = (OpenApiDocument) Library.readDocument(JsonUtil.toObject(node)); + OpenAPIV3Parser parser = new OpenAPIV3Parser(); + OpenAPI document = parser.read(input.toFile().getAbsolutePath()); final Writer writer;