This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.7.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.7.x by this push: new 4e6bc27 CAMEL-16927 fixes spring creating multiple camel contexts resulting in deadlock (#6113) 4e6bc27 is described below commit 4e6bc27bf0e01f334682d3eadea81f8e933b3986 Author: Piotr Klimczak <nann...@gmail.com> AuthorDate: Wed Sep 22 06:03:28 2021 +0100 CAMEL-16927 fixes spring creating multiple camel contexts resulting in deadlock (#6113) * CAMEL-16927 fixing spring creating multiple camel contexts which then affects DefaultReactiveExecutor/Worker causing deadlock * CAMEL-16927 Addressing PR comment --- .../camel/spring/CamelContextFactoryBean.java | 3 +- .../spring/config/CamelProxyDeadlockTest.java | 54 ++++++++++++++++++++++ .../camel/spring/config/CamelProxyDeadlockTest.xml | 48 +++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java index 8aaa749..61acc27 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java @@ -525,13 +525,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr } protected SpringCamelContext newCamelContext() { - return new SpringCamelContext(getApplicationContext()); + return new SpringCamelContext(); } @Override public SpringCamelContext getContext(boolean create) { if (context == null && create) { context = createContext(); + context.setApplicationContext(getApplicationContext()); configure(context); context.build(); } diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyDeadlockTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyDeadlockTest.java new file mode 100644 index 0000000..56b79ea --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyDeadlockTest.java @@ -0,0 +1,54 @@ +/* + * 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.spring.config; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.engine.DefaultProducerTemplate; +import org.apache.camel.spring.SpringCamelContext; +import org.apache.camel.spring.SpringTestSupport; +import org.junit.jupiter.api.Test; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CamelProxyDeadlockTest extends SpringTestSupport { + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyDeadlockTest.xml"); + } + + @Test + public void testCamelProxy() throws Exception { + SpringCamelContext scc = context.adapt(SpringCamelContext.class); + DefaultProducerTemplate producer = new DefaultProducerTemplate(scc); + producer.start(); + + MockEndpoint result = resolveMandatoryEndpoint(scc, "mock:result", MockEndpoint.class); + result.expectedBodiesReceived("Camel"); + + String reply = (String) producer.requestBody("direct-vm:start", "Camel"); + + result.assertIsSatisfied(); + assertEquals("Camel", reply); + } + + interface TestProcessor { + String test(String body); + } +} diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyDeadlockTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyDeadlockTest.xml new file mode 100644 index 0000000..322e363 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyDeadlockTest.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- This test covers CAMEL-16927 deadlock case --> + <camelContext id="testCamel" xmlns="http://camel.apache.org/schema/spring"> + + <proxy id="a" serviceUrl="direct-vm:a" serviceInterface="org.apache.camel.spring.config.CamelProxyDeadlockTest.TestProcessor"/> + <proxy id="b" serviceUrl="direct-vm:a" serviceInterface="org.apache.camel.spring.config.CamelProxyDeadlockTest.TestProcessor"/> + <proxy id="c" serviceUrl="direct-vm:a" serviceInterface="org.apache.camel.spring.config.CamelProxyDeadlockTest.TestProcessor"/> + + <route id="test"> + <from uri="direct-vm:start"/> + + <bean ref="c"/> <!-- This must be proxy "c" to trigger CAMEL-16927 --> + </route> + + <route id="routeBehindProxy"> + <from uri="direct-vm:a"/> + + <!-- With CAMEL-16927 unfixed, this route would never be reached --> + <to uri="mock:result"/> + </route> + </camelContext> + +</beans>