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 790f0b4cc198493cba281d2bd1f1f0f2486fb9fd Author: Claus Ibsen <[email protected]> AuthorDate: Thu Oct 15 11:57:03 2020 +0200 CAMEL-15176: Optimize component to do as much in init phase vs start phase. --- .../camel/component/direct/DirectEndpoint.java | 31 ++------- .../camel/component/direct/DirectEndpointTest.java | 73 ---------------------- .../camel/component/ref/RefComponentTest.java | 2 - 3 files changed, 6 insertions(+), 100 deletions(-) diff --git a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java index 4b4e1fd..7d5ac76 100644 --- a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java +++ b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java @@ -16,7 +16,6 @@ */ package org.apache.camel.component.direct; -import java.util.HashMap; import java.util.Map; import org.apache.camel.Category; @@ -42,7 +41,7 @@ import org.apache.camel.util.StringHelper; public class DirectEndpoint extends DefaultEndpoint { private final Map<String, DirectConsumer> consumers; - private String key; + private final String key; @UriPath(description = "Name of direct endpoint") @Metadata(required = true) @@ -55,22 +54,14 @@ public class DirectEndpoint extends DefaultEndpoint { @UriParam(label = "producer", defaultValue = "true") private boolean failIfNoConsumers = true; - public DirectEndpoint() { - this.consumers = new HashMap<>(); - } - - public DirectEndpoint(String endpointUri, Component component) { - this(endpointUri, component, new HashMap<>()); - } - public DirectEndpoint(String uri, Component component, Map<String, DirectConsumer> consumers) { super(uri, component); this.consumers = consumers; - } - - @Override - protected void doInit() throws Exception { - key = initKey(); + if (uri.indexOf('?') != -1) { + this.key = StringHelper.before(uri, "?"); + } else { + this.key = uri; + } } @Override @@ -141,8 +132,6 @@ public class DirectEndpoint extends DefaultEndpoint { /** * The timeout value to use if block is enabled. - * - * @param timeout the timeout value */ public void setTimeout(long timeout) { this.timeout = timeout; @@ -160,12 +149,4 @@ public class DirectEndpoint extends DefaultEndpoint { this.failIfNoConsumers = failIfNoConsumers; } - protected String initKey() { - String uri = getEndpointUri(); - if (uri.indexOf('?') != -1) { - return StringHelper.before(uri, "?"); - } else { - return uri; - } - } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java deleted file mode 100644 index 6020ca0..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.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.component.direct; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -public class DirectEndpointTest extends ContextTestSupport { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testDirectEndpoint() throws Exception { - final DirectEndpoint de = new DirectEndpoint(); - de.setCamelContext(context); - de.setEndpointUriIfNotSpecified("direct://foo"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from(de).to("mock:result"); - } - }); - context.start(); - - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - template.sendBody(de, "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testDirectEndpointAgain() throws Exception { - final DirectEndpoint de = new DirectEndpoint("direct://foo", context.getComponent("direct")); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from(de).to("mock:result"); - } - }); - context.start(); - - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - template.sendBody(de, "Hello World"); - - assertMockEndpointsSatisfied(); - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/component/ref/RefComponentTest.java b/core/camel-core/src/test/java/org/apache/camel/component/ref/RefComponentTest.java index 45a80e6..b9df214 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/ref/RefComponentTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/ref/RefComponentTest.java @@ -31,10 +31,8 @@ public class RefComponentTest extends ContextTestSupport { private void setupComponent() throws Exception { Component comp = new DirectComponent(); comp.setCamelContext(context); - comp.start(); Endpoint slow = comp.createEndpoint("direct:somename"); - slow.start(); Consumer consumer = slow.createConsumer(new Processor() { public void process(Exchange exchange) throws Exception { template.send("mock:result", exchange);
