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 2021/03/29 08:26:50 UTC
[camel] 01/04: CAMEL-16418: Added unit test
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 997b869666abe8213446ebc6887f173a4d0ac3cc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 29 09:57:46 2021 +0200
CAMEL-16418: Added unit test
---
components/camel-netty-http/pom.xml | 5 ++
.../http/rest/RestNettyCircuitBreakerLeakTest.java | 68 ++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git a/components/camel-netty-http/pom.xml b/components/camel-netty-http/pom.xml
index 5609f7c..1124d1d 100644
--- a/components/camel-netty-http/pom.xml
+++ b/components/camel-netty-http/pom.xml
@@ -91,6 +91,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-resilience4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-mock</artifactId>
<scope>test</scope>
</dependency>
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyCircuitBreakerLeakTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyCircuitBreakerLeakTest.java
new file mode 100644
index 0000000..49db422
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyCircuitBreakerLeakTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.component.netty.http.rest;
+
+import io.netty.util.ResourceLeakDetector;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.component.netty.http.RestNettyHttpBinding;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class RestNettyCircuitBreakerLeakTest extends BaseNettyTest {
+
+ @BindToRegistry("mybinding")
+ private RestNettyHttpBinding binding = new RestNettyHttpBinding();
+
+ @Test
+ public void testCircuitBreaker() throws Exception {
+ ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
+
+ String out = template.requestBody("netty-http:http://localhost:{{port}}/demo/get", null, String.class);
+ assertEquals("demo page", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
+
+ // configure to use netty-http on localhost with the given port
+ restConfiguration().component("netty-http").host("localhost").port(getPort())
+ .endpointProperty("nettyHttpBinding", "#mybinding");
+
+ rest().get("/demo").produces("text/plain")
+ .route()
+ .transform().constant("demo page");
+
+ rest().get("/demo/get").route()
+ .circuitBreaker()
+ .resilience4jConfiguration().timeoutEnabled(true).timeoutDuration(10000).end()
+ .log("incoming request")
+ .to("rest:get:demo?host=localhost:" + getPort())
+ .onFallback()
+ .transform().constant("timeout")
+ .end();
+ }
+ };
+ }
+
+}