This is an automated email from the ASF dual-hosted git repository.

fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 06629602fe6a CAMEL-23279: fix SamplingDefinition.description() 
NumberFormatException with property placeholders
06629602fe6a is described below

commit 06629602fe6a401c7da22c9bff1440e457c16c4a
Author: Croway <[email protected]>
AuthorDate: Fri Apr 3 16:45:52 2026 +0200

    CAMEL-23279: fix SamplingDefinition.description() NumberFormatException 
with property placeholders
    
    Avoid premature parsing of samplePeriod through TimeUtils.toDuration()
    in description(), which fails when the value contains unresolved
    property placeholders like {{sample.period}}. Return the raw string
    value instead, consistent with ThrottleDefinition.description().
---
 .../org/apache/camel/model/SamplingDefinition.java  |  2 +-
 .../camel/processor/SamplingThrottlerTest.java      | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/SamplingDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/SamplingDefinition.java
index a4dbc72d49af..87d58e90c7ff 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/SamplingDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/SamplingDefinition.java
@@ -86,7 +86,7 @@ public class SamplingDefinition extends 
NoOutputDefinition<SamplingDefinition> {
         if (messageFrequency != null) {
             return "1 Exchange per " + getMessageFrequency() + " messages 
received";
         } else {
-            return "1 Exchange per " + 
TimeUtils.printDuration(TimeUtils.toDuration(samplePeriod));
+            return "1 Exchange per " + getSamplePeriod() + " millis";
         }
     }
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java
index dc5a5193c735..b98e5e9f9e68 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java
@@ -20,6 +20,7 @@ import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -100,6 +101,17 @@ public class SamplingThrottlerTest extends 
ContextTestSupport {
         executor.shutdownNow();
     }
 
+    @Test
+    public void testSamplingWithPropertyPlaceholder() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.setResultWaitTime(3000);
+
+        template.sendBody("direct:sample-placeholder", "<message>placeholder 
test</message>");
+
+        mock.assertIsSatisfied();
+    }
+
     @Test
     public void testSamplingUsingMessageFrequency() throws Exception {
         long totalMessages = 100;
@@ -156,6 +168,13 @@ public class SamplingThrottlerTest extends 
ContextTestSupport {
         assertEquals(expectedNotDroppedCount, notDropped);
     }
 
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        Properties props = new Properties();
+        props.put("sample.period", "1000");
+        return props;
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -171,6 +190,8 @@ public class SamplingThrottlerTest extends 
ContextTestSupport {
 
                 
from("direct:sample-messageFrequency-via-dsl").sample().sampleMessageFrequency(5).to("mock:result");
 
+                
from("direct:sample-placeholder").sample("{{sample.period}}").to("mock:result");
+
                 // END SNIPPET: e1
             }
         };

Reply via email to