You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ji...@apache.org on 2023/10/05 14:00:27 UTC

[camel-quarkus] 32/45: Fixed enablement of typeConverter statisctics because of CAMEL-19398

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

commit d64a873c3fb975f5345285f76d744f7c0105d4c8
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Thu Sep 21 16:50:09 2023 +0200

    Fixed enablement of typeConverter statisctics because of CAMEL-19398
---
 .../ROOT/pages/reference/extensions/core.adoc      | 12 +++++++
 .../quarkus/core/deployment/CamelProcessor.java    |  4 ++-
 ...lContextDefaultTypeConverterStatisticsTest.java | 39 ++++++++++++++++++++++
 .../core/runtime/src/main/doc/configuration.adoc   | 11 ++++++
 .../apache/camel/quarkus/core/CamelRecorder.java   |  4 +--
 .../camel/quarkus/core/FastTypeConverter.java      |  4 +--
 .../core/converter/it/ConverterResource.java       |  9 ++---
 .../src/main/resources/application.properties      |  2 ++
 .../quarkus/core/converter/it/ConverterTest.java   | 29 +++++++---------
 9 files changed, 86 insertions(+), 28 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc b/docs/modules/ROOT/pages/reference/extensions/core.adoc
index 08a263e7f8..626220fcfe 100644
--- a/docs/modules/ROOT/pages/reference/extensions/core.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc
@@ -123,6 +123,18 @@ camel.beans.customBeanWithSetterInjection.counter = 123
 
 As such, the class `PropertiesCustomBeanWithSetterInjection` needs to be link:https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection[registered for reflection], note that field access could be omitted in this case.
 
+[id="extensions-core-configuration-enabling-type-converter-statistics"]
+==== Enabling type converter statistics
+
+Set configuration property `camel.main.typeConverterStatisticsEnabled` to `true` in order to enable type converter statistics.
+[source,properties]
+---
+camel.main.typeConverterStatisticsEnabled = true
+---
+
+Suggested configuration from Camel `org.apache.camel.CamelContext#setTypeConverterStatisticsEnabled(Boolean)` does not have any effect on camel-quarkus.
+
+
 
 [width="100%",cols="80,5,15",options="header"]
 |===
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 e354d2a428..19f0dc66e4 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
@@ -235,7 +235,9 @@ class CamelProcessor {
 
         IndexView index = combinedIndex.getIndex();
 
-        RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry();
+        Boolean val = CamelSupport.getOptionalConfigValue("camel.main.typeConverterStatisticsEnabled", Boolean.class, false);
+
+        RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry(val);
 
         //
         // This should be simplified by searching for classes implementing TypeConverterLoader but that
diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelContextDefaultTypeConverterStatisticsTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelContextDefaultTypeConverterStatisticsTest.java
new file mode 100644
index 0000000000..b691e816d3
--- /dev/null
+++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelContextDefaultTypeConverterStatisticsTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deployment;
+
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CamelContextDefaultTypeConverterStatisticsTest {
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest();
+
+    @Inject
+    CamelContext camelContext;
+
+    @Test
+    public void testDefaultTypeConverterStatistics() {
+        assertThat(camelContext.getTypeConverterRegistry().getStatistics().getClass().getSimpleName())
+                .isEqualTo("NoopTypeConverterStatistics");
+    }
+}
diff --git a/extensions-core/core/runtime/src/main/doc/configuration.adoc b/extensions-core/core/runtime/src/main/doc/configuration.adoc
index 68827731fd..beba713a4a 100644
--- a/extensions-core/core/runtime/src/main/doc/configuration.adoc
+++ b/extensions-core/core/runtime/src/main/doc/configuration.adoc
@@ -61,3 +61,14 @@ camel.beans.customBeanWithSetterInjection.counter = 123
 ---
 
 As such, the class `PropertiesCustomBeanWithSetterInjection` needs to be link:https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection[registered for reflection], note that field access could be omitted in this case.
+
+==== Enabling type converter statistics
+
+Set configuration property `camel.main.typeConverterStatisticsEnabled` to `true` in order to enable type converter statistics.
+[source,properties]
+---
+camel.main.typeConverterStatisticsEnabled = true
+---
+
+Suggested configuration from Camel `org.apache.camel.CamelContext#setTypeConverterStatisticsEnabled(Boolean)` does not have any effect on camel-quarkus.
+
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 20f51df4af..d20bf5aeae 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
@@ -66,8 +66,8 @@ public class CamelRecorder {
         return new RuntimeValue<>(new RuntimeRegistry(beanQualifierResolvers));
     }
 
-    public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry() {
-        return new RuntimeValue<>(new FastTypeConverter());
+    public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry(boolean typeConvertersatisticsEnabled) {
+        return new RuntimeValue<>(new FastTypeConverter(typeConvertersatisticsEnabled));
     }
 
     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 ba77525189..41aee346eb 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, false);
+    public FastTypeConverter(boolean typeConvertersatisticsEnabled) {
+        super(null, null, null, true, typeConvertersatisticsEnabled);
     }
 
     @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 295d47a34b..7bbd00a44f 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
@@ -90,14 +90,11 @@ public class ConverterResource {
         return context.getTypeConverter().convertTo(MyNullablePair.class, input);
     }
 
-    @Path("/setStatisticsEnabled")
+    @Path("/resetStatistics")
     @POST
     @Produces(MediaType.TEXT_PLAIN)
-    public void cnverterSetStatisticsEnabled(boolean value) {
-        context.setTypeConverterStatisticsEnabled(value);
-        if (value) {
-            context.getTypeConverterRegistry().getStatistics().reset();
-        }
+    public void converterResetStatistics() {
+        context.getTypeConverterRegistry().getStatistics().reset();
     }
 
     @Path("/getStatisticsHit")
diff --git a/integration-test-groups/foundation/type-converter/src/main/resources/application.properties b/integration-test-groups/foundation/type-converter/src/main/resources/application.properties
index b6ff2229d0..871983a1f6 100644
--- a/integration-test-groups/foundation/type-converter/src/main/resources/application.properties
+++ b/integration-test-groups/foundation/type-converter/src/main/resources/application.properties
@@ -16,3 +16,5 @@
 ## ---------------------------------------------------------------------------
 quarkus.log.file.enable = true
 quarkus.log.file.path = target/quarkus.log
+
+camel.main.typeConverterStatisticsEnabled = true
\ No newline at end of file
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 d7d3c3edf1..30083cf0e5 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
@@ -42,24 +42,20 @@ public class ConverterTest {
 
     @Test
     void testConverterToNull() {
-        enableStatistics(true);
+        resetStatistics();
 
         testConverterReturningNull("/converter/myNullablePair", "null");
 
         RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0));
-
-        enableStatistics(false);
     }
 
     @Test
     void testNotRegisteredConverter() {
-        enableStatistics(true);
+        resetStatistics();
 
         testConverterReturningNull("/converter/myNotRegisteredPair", "a:b");
 
         RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(0), "miss", is(1));
-
-        enableStatistics(false);
     }
 
     @Test
@@ -87,22 +83,12 @@ public class ConverterTest {
 
     @Test
     void testConverterGetStatistics() {
-        enableStatistics(true);
+        resetStatistics();
 
         //cause 1 hit
         testConverterFromAnnotation();
 
         RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0));
-
-        enableStatistics(false);
-    }
-
-    private void enableStatistics(boolean b) {
-        RestAssured.given()
-                .contentType(ContentType.TEXT).body(b)
-                .post("/converter/setStatisticsEnabled")
-                .then()
-                .statusCode(204);
     }
 
     private void testConverterReturningNull(String url, String body) {
@@ -125,4 +111,13 @@ public class ConverterTest {
             response.body("key", is(expectedKey), "val", is(expectedValue));
         }
     }
+
+    private void resetStatistics() {
+        //reset statistics
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .post("/converter/resetStatistics")
+                .then()
+                .statusCode(204);
+    }
 }