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 2018/01/10 12:07:32 UTC
[camel] 02/02: address PR comments
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4f65a942465d82acea52a5012c00bec81d1183e6
Author: CodeSmell <mb...@gmail.com>
AuthorDate: Tue Jan 9 08:54:30 2018 -0500
address PR comments
---
.../camel/impl/ThrottlingExceptionRoutePolicy.java | 26 ++++++++---------
...lingExceptionRoutePolicyKeepOpenOnInitTest.java | 22 +++++++++++++--
...tlingExceptionRoutePolicyOpenViaConfigTest.java | 33 ++++++++++++++--------
3 files changed, 52 insertions(+), 29 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java b/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
index 0ee7b83..5c0eb44 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
@@ -16,6 +16,14 @@
*/
package org.apache.camel.impl;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
@@ -26,14 +34,6 @@ import org.apache.camel.support.RoutePolicySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
/**
* Modeled after the {@link CircuitBreakerLoadBalancer} and {@link ThrottlingInflightRoutePolicy}
* this {@link RoutePolicy} will stop consuming from an endpoint based on the type of exceptions that are
@@ -74,17 +74,13 @@ public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport implement
// stateful information
private final AtomicInteger failures = new AtomicInteger();
private final AtomicInteger state = new AtomicInteger(STATE_CLOSED);
- private AtomicBoolean keepOpen = new AtomicBoolean(false);
+ private final AtomicBoolean keepOpen = new AtomicBoolean(false);
private volatile Timer halfOpenTimer;
private volatile long lastFailure;
private volatile long openedAt;
public ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions) {
- this.throttledExceptions = handledExceptions;
- this.failureWindow = failureWindow;
- this.halfOpenAfter = halfOpenAfter;
- this.failureThreshold = threshold;
- this.keepOpen.set(false);
+ this(threshold, failureWindow, halfOpenAfter, handledExceptions, false);
}
public ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions, boolean keepOpen) {
@@ -333,7 +329,7 @@ public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport implement
}
public void setKeepOpen(boolean keepOpen) {
- log.debug("keep open:" + keepOpen);
+ log.debug("keep open: {}", keepOpen);
this.keepOpen.set(keepOpen);
}
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyKeepOpenOnInitTest.java b/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyKeepOpenOnInitTest.java
index 25134d5..b650dbd 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyKeepOpenOnInitTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyKeepOpenOnInitTest.java
@@ -1,3 +1,19 @@
+/**
+ * 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.apache.camel.ContextTestSupport;
@@ -29,7 +45,7 @@ public class ThrottlingExceptionRoutePolicyKeepOpenOnInitTest extends ContextTes
protected void createPolicy() {
int threshold = 2;
long failureWindow = 30;
- long halfOpenAfter = 1000;
+ long halfOpenAfter = 100;
boolean keepOpen = true;
policy = new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null, keepOpen);
}
@@ -45,7 +61,7 @@ public class ThrottlingExceptionRoutePolicyKeepOpenOnInitTest extends ContextTes
// gives time for policy half open check to run every second
// and should not close b/c keepOpen is true
- Thread.sleep(2000);
+ Thread.sleep(500);
// gives time for policy half open check to run every second
// but it should never close b/c keepOpen is true
@@ -64,7 +80,7 @@ public class ThrottlingExceptionRoutePolicyKeepOpenOnInitTest extends ContextTes
// gives time for policy half open check to run every second
// and should not close b/c keepOpen is true
- Thread.sleep(2000);
+ Thread.sleep(500);
result.expectedMessageCount(0);
result.setResultWaitTime(1500);
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java b/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
index 650d08c..c096826 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
@@ -1,3 +1,19 @@
+/**
+ * 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.apache.camel.ContextTestSupport;
@@ -29,7 +45,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
protected void createPolicy() {
int threshold = 2;
long failureWindow = 30;
- long halfOpenAfter = 1000;
+ long halfOpenAfter = 100;
boolean keepOpen = false;
policy = new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null, keepOpen);
}
@@ -44,7 +60,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
Thread.sleep(3);
}
result.expectedMessageCount(size);
- result.setResultWaitTime(2000);
+ result.setResultWaitTime(1000);
assertMockEndpointsSatisfied();
// set keepOpen to true
@@ -55,7 +71,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
template.sendBody(url, "MessageTrigger");
// give time for circuit to open
- Thread.sleep(1000);
+ Thread.sleep(500);
// send next set of messages
// should NOT go through b/c circuit is open
@@ -66,10 +82,10 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
// gives time for policy half open check to run every second
// and should not close b/c keepOpen is true
- Thread.sleep(2000);
+ Thread.sleep(500);
result.expectedMessageCount(size + 1);
- result.setResultWaitTime(2000);
+ result.setResultWaitTime(1000);
assertMockEndpointsSatisfied();
// set keepOpen to false
@@ -78,7 +94,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
// gives time for policy half open check to run every second
// and it should close b/c keepOpen is false
result.expectedMessageCount(size * 2 + 1);
- result.setResultWaitTime(2000);
+ result.setResultWaitTime(1000);
assertMockEndpointsSatisfied();
}
@@ -87,11 +103,6 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest extends ContextTest
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- int threshold = 2;
- long failureWindow = 30;
- long halfOpenAfter = 1000;
- policy = new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null);
-
from(url)
.routePolicy(policy)
.log("${body}")
--
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.