This is an automated email from the ASF dual-hosted git repository. orpiske 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 8a2207e0904 * CAMEL-20113: camel itests refactoring (#12480) 8a2207e0904 is described below commit 8a2207e0904c0dcd879eb75fe66425a61356688d Author: Ivan Kulaga <kulagaivanandreev...@gmail.com> AuthorDate: Mon Dec 18 23:12:19 2023 +0300 * CAMEL-20113: camel itests refactoring (#12480) * delete tests because org.apache.camel.component.jms.JmsDurableTopicTest does the same check * module tests/camel-itest-jms2 contained only jms component tests. They are moved to jms component and tests/camel-itest-jms2 is deleted * test from tests/camel-typeconverterscan was moved to processor tests. Processor converter tests were then moved to a separate package to avoid scanning the whole org.apache.camel.processor for custom converter. tests/camel-typeconverterscan was deleted as no relevant tests remained there. * removed test as it is duplicated by org.apache.camel.management.CamelContextDisableJmxTest * there are many tests doing this check as part of their logic, including the type converter tests * async tests are duplicated by org.apache.camel.impl.DefaultProducerTemplateAsyncTest; timeout tests are duplicated by org.apache.camel.component.jetty.async.JettyAsyncContinuationTimeoutTest * FtpInitialConnectTimeoutTest is moved to ftp component tests * CustomerServicesWsAddressingTest is deleted because wsdl with empty soapAction is checked in org.apache.camel.component.cxf.CxfPayLoadSoapHeaderSpringTest --- .../component/file/remote/FtpSoTimeoutTest.java | 30 +++- .../camel/processor/converter/ConvertBodyTest.java | 4 + .../processor/converter/ConvertHeaderTest.java | 4 + .../apache/camel/itest/async/HttpAsyncDslTest.java | 136 ----------------- .../apache/camel/itest/async/HttpAsyncTest.java | 82 ---------- .../camel/itest/async/HttpAsyncTestSupport.java | 36 ----- .../camel/itest/async/HttpJmsAsyncTimeoutTest.java | 75 --------- .../org/apache/camel/itest/async/HttpSyncTest.java | 67 -------- .../apache/camel/itest/async/MyAsyncComponent.java | 34 ----- .../apache/camel/itest/async/MyAsyncEndpoint.java | 73 --------- .../apache/camel/itest/async/MyAsyncProducer.java | 73 --------- .../customerrelations/CustomerServicesTest.java | 1 - .../CustomerServicesWsAddressingTest.java | 54 ------- .../itest/ftp/FtpInitialConnectTimeoutTest.java | 168 --------------------- 14 files changed, 33 insertions(+), 804 deletions(-) diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java index 2e110f47d5e..9aa8fa9318b 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java @@ -16,13 +16,11 @@ */ package org.apache.camel.component.file.remote; -import java.net.ServerSocket; -import java.util.concurrent.TimeUnit; - import org.apache.camel.BindToRegistry; import org.apache.camel.CamelExecutionException; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.commons.net.ftp.FTPClient; import org.junit.jupiter.api.AfterEach; @@ -30,6 +28,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import java.net.ServerSocket; +import java.util.concurrent.TimeUnit; + import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -75,11 +76,19 @@ public class FtpSoTimeoutTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() { + from("direct:with").to("ftp://localhost:" + serverSocket.getLocalPort() - + "?ftpClient=#myftpclient&connectTimeout=300&soTimeout=300&reconnectDelay=100"); + + "?ftpClient=#myftpclient&connectTimeout=300&soTimeout=300&reconnectDelay=100"); from("direct:without").to("ftp://localhost:" + serverSocket.getLocalPort() - + "?connectTimeout=300&soTimeout=300&reconnectDelay=100"); + + "?connectTimeout=300&soTimeout=300&reconnectDelay=100"); + + // using soTimeout=0 could potentially cause the ftp producer to dead-lock doing endless reconnection attempts + // this is a test to ensure we have fixed that; see CAMEL-8088 + from("direct:soTimeoutZero").to("ftp://localhost:" + serverSocket.getLocalPort() + + "?connectTimeout=300&soTimeout=0") + .to("mock:done") + .errorHandler(deadLetterChannel("mock:dead")); } }; } @@ -114,4 +123,15 @@ public class FtpSoTimeoutTest extends CamelTestSupport { template.sendBody("direct:without", ""); }); } + + @Test + void testReConnectDeadlock() throws Exception { + // we should fail, but we are testing that we are not in a deadlock which could potentially happen + getMockEndpoint("mock:done").expectedMessageCount(0); + getMockEndpoint("mock:dead").expectedMessageCount(1); + + template.sendBody("direct:soTimeoutZero", "test"); + + MockEndpoint.assertIsSatisfied(context); + } } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertBodyTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertBodyTest.java index af5f8745510..c7af7ffbd0c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertBodyTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertBodyTest.java @@ -33,6 +33,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; +import java.io.ByteArrayInputStream; +import java.nio.charset.UnsupportedCharsetException; +import java.util.Date; + import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertHeaderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertHeaderTest.java index c3a5be38fcc..799547701e3 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertHeaderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/converter/ConvertHeaderTest.java @@ -31,6 +31,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; +import java.io.ByteArrayInputStream; +import java.nio.charset.UnsupportedCharsetException; +import java.util.Date; + import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncDslTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncDslTest.java deleted file mode 100644 index 44d8e8a1c19..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncDslTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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.itest.async; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class HttpAsyncDslTest extends CamelTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - private static volatile String order = ""; - - @Test - void testRequestOnly() throws Exception { - getMockEndpoint("mock:validate").expectedMessageCount(1); - // even though its request only the message is still continued being processed - getMockEndpoint("mock:order").expectedMessageCount(1); - - template.sendBody("jms:queue:order", "Order: Camel in Action"); - order += "C"; - - MockEndpoint.assertIsSatisfied(context); - - // B should be last (either ABC or BAC depending on threading) - assertEquals(3, order.length()); - assertTrue(order.endsWith("B")); - } - - @Test - void testRequestReply() throws Exception { - getMockEndpoint("mock:validate").expectedMessageCount(1); - // even though its request only the message is still continued being processed - getMockEndpoint("mock:order").expectedMessageCount(1); - - String response = template.requestBody("jms:queue:order", "Order: Camel in Action", String.class); - order += "C"; - - MockEndpoint.assertIsSatisfied(context); - - // should be in strict ABC order as we do request/reply - assertEquals("ABC", order); - assertEquals("Order OK", response); - } - - @Override - @BeforeEach - public void setUp() throws Exception { - order = ""; - super.setUp(); - } - - @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - registry.bind("validateOrder", new MyValidateOrderBean()); - registry.bind("handleOrder", new MyHandleOrderBean()); - return registry; - } - - @Override - protected void bindToRegistry(Registry registry) throws Exception { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - registry.bind("jms", amq); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - // START SNIPPET: e1 - - // list on the JMS queue for new orders - from("jms:queue:order") - // do some sanity check validation - .to("bean:validateOrder") - .to("mock:validate") - // use multi threading with a pool size of 20 - // turn the route async as some others do not expect a reply - // and a few does then we can use the threads DSL as a turning point - // if the JMS ReplyTo was set then we expect a reply, otherwise not - // use a pool of 20 threads for the point forward - .threads(20) - // do some CPU heavy processing of the message (we simulate and delay just 500 ms) - .delay(500).to("bean:handleOrder").to("mock:order"); - // END SNIPPET: e1 - } - }; - } - - public static class MyValidateOrderBean { - - public void validateOrder(byte[] payload) { - order += "A"; - // noop - } - } - - public static class MyHandleOrderBean { - - public String handleOrder(String message) { - order += "B"; - return "Order OK"; - // noop - } - } -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTest.java deleted file mode 100644 index 17ca82499bb..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.itest.async; - -import java.util.concurrent.Future; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class HttpAsyncTest extends HttpAsyncTestSupport { - - @Test - void testAsyncAndSyncAtSameTimeWithHttp() throws Exception { - // START SNIPPET: e2 - MockEndpoint mock = getMockEndpoint("mock:result"); - // We expect the name job to be faster than the async job even though the async job - // was started first - mock.expectedBodiesReceived("Claus", "Bye World"); - - // Send a async request/reply message to the http endpoint - Future<Object> future = template.asyncRequestBody("http://0.0.0.0:" + getPort() + "/myservice", "Hello World"); - - // We got the future so in the meantime we can do other stuff, as this is Camel - // so lets invoke another request/reply route but this time is synchronous - String name = template.requestBody("direct:name", "Give me a name", String.class); - assertEquals("Claus", name); - - // Okay we got a name and we have done some other work at the same time - // the async route is running, but now its about time to wait and get - // get the response from the async task - - // We use the extract future body to get the response from the future - // (waiting if needed) and then return a string body response. - // This allows us to do this in a single code line instead of using the - // JDK Future API to get hold of it, but you can also use that if you want - // Adding the (String) To make the CS happy - String response = template.extractFutureBody(future, String.class); - assertEquals("Bye World", response); - - MockEndpoint.assertIsSatisfied(context); - // END SNIPPET: e2 - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - // START SNIPPET: e1 - // The mocks are here for unit test - - // Some other service to return a name, this is invoked synchronously - from("direct:name").transform(constant("Claus")).to("mock:result"); - - // Simulate a slow http service (delaying 1 sec) we want to invoke async - fromF("jetty:http://0.0.0.0:%s/myservice", getPort()) - .delay(1000) - .transform(constant("Bye World")) - .to("mock:result"); - // END SNIPPET: e1 - } - }; - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTestSupport.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTestSupport.java deleted file mode 100644 index 89ddd43a0ed..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpAsyncTestSupport.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.itest.async; - -import org.apache.camel.test.AvailablePortFinder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeAll; - -public class HttpAsyncTestSupport extends CamelTestSupport { - - protected static int port; - - @BeforeAll - public static void initPort() { - port = AvailablePortFinder.getNextAvailable(); - } - - protected int getPort() { - return port; - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpJmsAsyncTimeoutTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpJmsAsyncTimeoutTest.java deleted file mode 100644 index 1be83a5a305..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpJmsAsyncTimeoutTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.itest.async; - -import org.apache.camel.CamelExecutionException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.http.base.HttpOperationFailedException; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -public class HttpJmsAsyncTimeoutTest extends HttpAsyncTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - @Test - void testHttpJmsAsync() { - try { - template.requestBody("http://0.0.0.0:" + getPort() + "/myservice", "Hello World", String.class); - fail("Should have thrown exception"); - } catch (CamelExecutionException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - assertEquals(504, cause.getStatusCode()); - } - } - - @Override - protected void bindToRegistry(Registry registry) { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - registry.bind("jms", amq); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - // a lot of timeouts in the play :) - - // jetty will timeout after 2 seconds - fromF("jetty:http://0.0.0.0:%s/myservice?continuationTimeout=2000", getPort()) - // jms request/reply will timeout after 5 seconds - .to("jms:queue:foo?requestTimeout=5000"); - - from("jms:queue:foo") - // and this one is slow and will reply after 10 seconds - .delayer(10000) - .transform(constant("Bye World")); - } - }; - } -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpSyncTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpSyncTest.java deleted file mode 100644 index 74a7fcd1fbb..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/HttpSyncTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.itest.async; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class HttpSyncTest extends HttpAsyncTestSupport { - - @Test - void testSyncAndSyncAtSameTimeWithHttp() throws Exception { - // START SNIPPET: e2 - MockEndpoint mock = getMockEndpoint("mock:result"); - // We expect the http job to complete before the name job - mock.expectedBodiesReceived("Bye World", "Claus"); - - // Send a sync request/reply message to the http endpoint - String response = template.requestBody("http://0.0.0.0:" + getPort() + "/myservice", "Hello World", String.class); - assertEquals("Bye World", response); - - // Send a sync request/reply message to the direct endpoint - String name = template.requestBody("direct:name", "Give me a name", String.class); - assertEquals("Claus", name); - - MockEndpoint.assertIsSatisfied(context); - // END SNIPPET: e2 - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - // START SNIPPET: e1 - // The mocks are here for unit test - - // Some other service to return a name, this is invoked synhronously - from("direct:name").transform(constant("Claus")).to("mock:result"); - - // Simulate a slow http service (delaying 1 sec) we want to invoke async - fromF("jetty:http://0.0.0.0:%s/myservice", getPort()) - .delay(1000) - .transform(constant("Bye World")) - .to("mock:result"); - // END SNIPPET: e1 - } - }; - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java deleted file mode 100644 index 1e9f1dcbe69..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.itest.async; - -import java.util.Map; - -import org.apache.camel.Endpoint; -import org.apache.camel.support.DefaultComponent; - -public class MyAsyncComponent extends DefaultComponent { - - @Override - protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - MyAsyncEndpoint answer = new MyAsyncEndpoint(uri, this); - answer.setReply(remaining); - setProperties(answer, parameters); - return answer; - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java deleted file mode 100644 index d64e1143853..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncEndpoint.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.itest.async; - -import org.apache.camel.Component; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.support.DefaultEndpoint; - -public class MyAsyncEndpoint extends DefaultEndpoint { - - private String reply; - private long delay = 1000; - private int failFirstAttempts; - - public MyAsyncEndpoint(String endpointUri, Component component) { - super(endpointUri, component); - } - - @Override - public Producer createProducer() throws Exception { - return new MyAsyncProducer(this); - } - - @Override - public Consumer createConsumer(Processor processor) throws Exception { - throw new UnsupportedOperationException("Consumer not supported"); - } - - @Override - public boolean isSingleton() { - return false; - } - - public String getReply() { - return reply; - } - - public void setReply(String reply) { - this.reply = reply; - } - - public long getDelay() { - return delay; - } - - public void setDelay(long delay) { - this.delay = delay; - } - - public int getFailFirstAttempts() { - return failFirstAttempts; - } - - public void setFailFirstAttempts(int failFirstAttempts) { - this.failFirstAttempts = failFirstAttempts; - } -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java deleted file mode 100644 index d0073964beb..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/async/MyAsyncProducer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.itest.async; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.camel.AsyncCallback; -import org.apache.camel.CamelExchangeException; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultAsyncProducer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MyAsyncProducer extends DefaultAsyncProducer { - - private static final Logger LOG = LoggerFactory.getLogger(MyAsyncProducer.class); - private final ExecutorService executor = Executors.newCachedThreadPool(); - private final AtomicInteger counter = new AtomicInteger(); - - public MyAsyncProducer(MyAsyncEndpoint endpoint) { - super(endpoint); - } - - @Override - public MyAsyncEndpoint getEndpoint() { - return (MyAsyncEndpoint) super.getEndpoint(); - } - - @Override - public boolean process(final Exchange exchange, final AsyncCallback callback) { - executor.submit(() -> { - LOG.info("Simulating a task which takes " + getEndpoint().getDelay() + " millis to reply"); - Thread.sleep(getEndpoint().getDelay()); - - int count = counter.incrementAndGet(); - if (getEndpoint().getFailFirstAttempts() >= count) { - LOG.info("Simulating a failure at attempt " + count); - exchange.setException(new CamelExchangeException("Simulated error at attempt " + count, exchange)); - } else { - String reply = getEndpoint().getReply(); - exchange.getMessage().setBody(reply); - // propagate headers - exchange.getMessage().setHeaders(exchange.getIn().getHeaders()); - LOG.info("Setting reply " + reply); - } - - LOG.info("Callback done(false)"); - callback.done(false); - return null; - }); - - // indicate from this point forward its being routed asynchronously - LOG.info("Task submitted, now tell Camel routing engine to that this Exchange is being continued asynchronously"); - return false; - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java index 5f6d9d8758d..accc49f7a1c 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesTest.java @@ -66,7 +66,6 @@ public class CustomerServicesTest { Customer customer = customerService.getCustomer("12345"); assertNotNull(customer, "We should get Customer here"); } finally { - // we're done so let's properly close the application contexts IOHelper.close(clientContext, serverContext); } } diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesWsAddressingTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesWsAddressingTest.java deleted file mode 100644 index cdadb5af328..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/customerrelations/CustomerServicesWsAddressingTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.itest.customerrelations; - -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.util.IOHelper; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class CustomerServicesWsAddressingTest { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - @Test - void testCustomerService() throws Exception { - ClassPathXmlApplicationContext serverContext = null; - ClassPathXmlApplicationContext clientContext = null; - try { - serverContext = new ClassPathXmlApplicationContext( - new String[] { "spring-config/server-WsAddressingContext.xml" }); - Object server = serverContext.getBean("org.apache.camel.itest.customerrelations.CustomerServiceV1"); - assertNotNull(server, "We should get server here"); - - clientContext = new ClassPathXmlApplicationContext( - new String[] { "spring-config/client-WsAddressingContext.xml" }); - CustomerServiceV1 customerService = clientContext - .getBean("org.apache.camel.itest.customerrelations.CustomerServiceV1", CustomerServiceV1.class); - - Customer customer = customerService.getCustomer("12345"); - assertNotNull(customer, "We should get Customer here"); - } finally { - // we're done so let's properly close the application context - IOHelper.close(clientContext, serverContext); - } - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/FtpInitialConnectTimeoutTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/FtpInitialConnectTimeoutTest.java deleted file mode 100644 index 122e284b639..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/FtpInitialConnectTimeoutTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.itest.ftp; - -import java.io.IOException; -import java.io.InputStream; -import java.net.Socket; -import java.net.SocketException; -import java.net.SocketTimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.net.SocketFactory; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.SimpleRegistry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.apache.commons.net.ftp.FTPClient; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockftpserver.fake.FakeFtpServer; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -public class FtpInitialConnectTimeoutTest extends CamelTestSupport { - - private static final int CONNECT_TIMEOUT = 11223; - - /** - * Create the answer for the socket factory that causes a SocketTimeoutException to occur in connect. - */ - private static class SocketAnswer implements Answer<Socket> { - - @Override - public Socket answer(InvocationOnMock invocation) throws Throwable { - final Socket socket = spy(new Socket()); - final AtomicBoolean timeout = new AtomicBoolean(); - - try { - doAnswer((Answer<InputStream>) invocation12 -> { - final InputStream stream = (InputStream) invocation12.callRealMethod(); - - InputStream inputStream = new InputStream() { - @Override - public int read() throws IOException { - if (timeout.get()) { - // emulate a timeout occurring in _getReply() - throw new SocketTimeoutException(); - } - return stream.read(); - } - }; - - return inputStream; - }).when(socket).getInputStream(); - } catch (IOException ignored) { - } - - try { - doAnswer((Answer<Object>) invocation1 -> { - if ((Integer) invocation1.getArguments()[0] == CONNECT_TIMEOUT) { - // setting of connect timeout - timeout.set(true); - } else { - // non-connect timeout - timeout.set(false); - } - return invocation1.callRealMethod(); - }).when(socket).setSoTimeout(anyInt()); - } catch (SocketException e) { - throw new RuntimeException(e); - } - return socket; - } - } - - private FakeFtpServer fakeFtpServer; - - @Override - @BeforeEach - public void setUp() throws Exception { - fakeFtpServer = new FakeFtpServer(); - fakeFtpServer.setServerControlPort(0); - fakeFtpServer.start(); - - super.setUp(); - } - - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - if (fakeFtpServer != null) { - fakeFtpServer.stop(); - } - } - - private FTPClient mockedClient() throws IOException { - FTPClient client = new FTPClient(); - client.setSocketFactory(createSocketFactory()); - return client; - } - - private SocketFactory createSocketFactory() throws IOException { - SocketFactory socketFactory = mock(SocketFactory.class); - when(socketFactory.createSocket()).thenAnswer(new SocketAnswer()); - return socketFactory; - } - - @Override - protected Registry createCamelRegistry() throws Exception { - Registry registry = new SimpleRegistry(); - registry.bind("mocked", mockedClient()); - return registry; - } - - @Test - void testReConnect() throws Exception { - // we should fail, but we are testing that we are not in a deadlock which could potentially happen - getMockEndpoint("mock:done").expectedMessageCount(0); - getMockEndpoint("mock:dead").expectedMessageCount(1); - - sendBody("direct:start", "test"); - - MockEndpoint.assertIsSatisfied(context); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - errorHandler(deadLetterChannel("mock:dead")); - - // using soTimeout=0 could potentially cause the ftp producer to dead-lock doing endless reconnection attempts - // this is a test to ensure we have fixed that - from("direct:start") - .to("ftp://localhost:" + fakeFtpServer.getServerControlPort() - + "?ftpClient=#mocked" - + "&soTimeout=0&" - + "connectTimeout=" + CONNECT_TIMEOUT) - .to("mock:done"); - } - }; - } -}