You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/07/29 12:52:21 UTC

(camel) branch main updated: Use StopWatch instead of System.currentTimeMillis() (#18756)

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

davsclaus 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 6d1d74c5433 Use StopWatch instead of System.currentTimeMillis() (#18756)
6d1d74c5433 is described below

commit 6d1d74c543306bc955f4e2061f4cafe87dfbdaba
Author: Federico Mariani <34...@users.noreply.github.com>
AuthorDate: Tue Jul 29 14:52:15 2025 +0200

    Use StopWatch instead of System.currentTimeMillis() (#18756)
---
 .../component/springrabbit/integration/RabbitMQProducerIT.java     | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java
index 8c3e8a4f49d..d016fe5cacc 100644
--- a/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java
+++ b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.springrabbit.SpringRabbitMQConstants;
+import org.apache.camel.util.StopWatch;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
@@ -110,7 +111,7 @@ public class RabbitMQProducerIT extends RabbitMQITSupport {
         AmqpTemplate rabbitConsumerTemplate = new RabbitTemplate(cf);
 
         int receivedCount = 0;
-        long lastMessageTime = System.currentTimeMillis();
+        StopWatch lastMessageStopWatch = new StopWatch();
         final long idleTimeoutMillis = 2000; // 2 seconds
         while (true) {
             Object receivedMessage = rabbitConsumerTemplate.receiveAndConvert("myqueue");
@@ -118,10 +119,10 @@ public class RabbitMQProducerIT extends RabbitMQITSupport {
             if (receivedMessage != null) {
                 // If we got a message, increment count and reset the idle timer.
                 receivedCount++;
-                lastMessageTime = System.currentTimeMillis();
+                lastMessageStopWatch.restart();
             } else {
                 // If we got no message, check if the idle timeout has been exceeded.
-                if (System.currentTimeMillis() - lastMessageTime > idleTimeoutMillis) {
+                if (lastMessageStopWatch.taken() > idleTimeoutMillis) {
                     LOG.info(
                             "No messages received for " + (idleTimeoutMillis / 1000) + " seconds. Exiting consumer loop.");
                     break; // Exit the loop