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 2022/01/14 06:41:28 UTC

[camel] branch camel-3.11.x updated (c28de73 -> 97c8c96)

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

davsclaus pushed a change to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from c28de73  Regen for commit ae2451c8bb42c9251fd7fe6654be3ad7aaab30a2
     new 29612db  CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.
     new 97c8c96  CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/camel/processor/Throttler.java |  2 +-
 .../camel/processor/ThrottlerPermitTest.java       | 69 ++++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java

[camel] 01/02: CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 29612db81dd278f048f29a7d2ff9b6c7cf46c87d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 14 07:19:49 2022 +0100

    CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.
---
 .../java/org/apache/camel/processor/Throttler.java |  2 +-
 .../camel/processor/ThrottlerPermitTest.java       | 70 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
index 2d4214e..10bce06 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
@@ -393,7 +393,7 @@ public class Throttler extends AsyncProcessorSupport implements Traceable, IdAwa
 
         @Override
         public int compareTo(final Delayed o) {
-            return (int) (getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
+            return Long.compare(getDelay(TimeUnit.MILLISECONDS), o.getDelay(TimeUnit.MILLISECONDS));
         }
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java
new file mode 100644
index 0000000..cf5da58
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.processor;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * When a Throttler has not been used for longer than {@link java.lang.Integer#MAX_VALUE},
+ * casting the result of the {@link ThrottlePermit} comparison to an int causes an overflow.
+ * Using a value comparison prevents this issue.
+ */
+public class ThrottlerPermitTest {
+
+    @Test
+    public void testThrottlerPermitWithOldScheduledTime() {
+        long timeMillis = System.currentTimeMillis();
+        // 30 days in the past
+        ThrottlePermit throttlePermitOld = new ThrottlePermit(timeMillis - 2592000000L);
+        // Now
+        ThrottlePermit throttlePermitNow = new ThrottlePermit(timeMillis);
+        ThrottlePermit throttlePermitNow2 = new ThrottlePermit(timeMillis);
+        // Future
+        ThrottlePermit throttlePermitFuture = new ThrottlePermit(timeMillis + 1000);
+
+        assertEquals(-1, throttlePermitOld.compareTo(throttlePermitNow));
+        assertEquals(0, throttlePermitNow.compareTo(throttlePermitNow2));
+        assertEquals(1, throttlePermitFuture.compareTo(throttlePermitNow));
+    }
+
+    private static final class ThrottlePermit implements Delayed {
+        private volatile long scheduledTime;
+
+        ThrottlePermit(final long delayMs) {
+            setDelayMs(delayMs);
+        }
+
+        public void setDelayMs(final long delayMs) {
+            this.scheduledTime = System.currentTimeMillis() + delayMs;
+        }
+
+        @Override
+        public long getDelay(final TimeUnit unit) {
+            return unit.convert(scheduledTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
+        }
+
+        @Override
+        public int compareTo(final Delayed o) {
+            return Long.compare(getDelay(TimeUnit.MILLISECONDS), o.getDelay(TimeUnit.MILLISECONDS));
+        }
+    }
+}

[camel] 02/02: CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 97c8c96b847fb952835505aff91a7fb5f5dbcaa6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 14 07:27:08 2022 +0100

    CAMEL-17486: camel-core - ThrottlePermit compareTo cast to int causes issues. Thanks to Marc Boulanger for the patch and unit test.
---
 .../java/org/apache/camel/processor/ThrottlerPermitTest.java     | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java
index cf5da58..74342e1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThrottlerPermitTest.java
@@ -16,17 +16,16 @@
  */
 package org.apache.camel.processor;
 
-import org.junit.jupiter.api.Test;
-
 import java.util.concurrent.Delayed;
 import java.util.concurrent.TimeUnit;
 
+import org.junit.jupiter.api.Test;
+
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
- * When a Throttler has not been used for longer than {@link java.lang.Integer#MAX_VALUE},
- * casting the result of the {@link ThrottlePermit} comparison to an int causes an overflow.
- * Using a value comparison prevents this issue.
+ * When a Throttler has not been used for longer than {@link java.lang.Integer#MAX_VALUE}, casting the result of the
+ * {@link ThrottlePermit} comparison to an int causes an overflow. Using a value comparison prevents this issue.
  */
 public class ThrottlerPermitTest {