This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch properties in repository https://gitbox.apache.org/repos/asf/camel.git
commit cb3b3a1c0dfccfefe36795e574543e734b958d1d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jul 4 10:23:58 2019 +0200 CAMEL-13721: Properties component - Remove cache option as the properties source have built-in cache when it makes sence, and others are on-demand which makes a good default behaviour. --- .../apache/camel/blueprint/BlueprintJaxbTest.java | 1 - .../src/main/docs/properties-component.adoc | 3 +- .../component/properties/PropertiesComponent.java | 37 ---------------- ...SpringPropertiesComponentCacheDisabledTest.java | 38 ---------------- .../SpringPropertiesComponentCacheDisabledTest.xml | 51 ---------------------- .../core/xml/AbstractCamelContextFactoryBean.java | 4 -- .../xml/CamelPropertyPlaceholderDefinition.java | 13 ------ .../properties/PropertiesComponentTest.java | 27 +----------- .../PropertiesEnvironmentVariableOverrideTest.java | 4 -- .../PropertiesComponentConfiguration.java | 12 ----- 10 files changed, 3 insertions(+), 187 deletions(-) diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java index 1347a42..02d9e68 100644 --- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java +++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java @@ -60,7 +60,6 @@ public class BlueprintJaxbTest extends TestSupport { assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getInput()); assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs()); assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs().size()); - assertTrue(((CamelContextFactoryBean) object).getCamelPropertyPlaceholder().isCache()); assertTrue(((CamelContextFactoryBean) object).getCamelPropertyPlaceholder().isIgnoreMissingLocation()); } } diff --git a/components/camel-properties/src/main/docs/properties-component.adoc b/components/camel-properties/src/main/docs/properties-component.adoc index 734abf4..a6711b1 100644 --- a/components/camel-properties/src/main/docs/properties-component.adoc +++ b/components/camel-properties/src/main/docs/properties-component.adoc @@ -15,7 +15,7 @@ Where *key* is the key for the property to lookup === Options // component options: START -The Properties component supports 15 options, which are listed below. +The Properties component supports 14 options, which are listed below. @@ -26,7 +26,6 @@ The Properties component supports 15 options, which are listed below. | *location* (common) | A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option. | | String | *encoding* (common) | Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented by java.util.Properties#load(java.io.InputStream) | | String | *propertiesParser* (common) | To use a custom PropertiesParser | | PropertiesParser -| *cache* (common) | Whether or not to cache loaded properties. The default value is true. | true | boolean | *defaultFallbackEnabled* (common) | If false, the component does not attempt to find a default for the key by looking after the colon separator. | true | boolean | *ignoreMissingLocation* (common) | Whether to silently ignore if a location cannot be located, such as a properties file not found. | false | boolean | *prefixToken* (advanced) | Sets the value of the prefix token used to identify properties to replace. Setting a value of null restores the default token (link DEFAULT_PREFIX_TOKEN). | {{ | String diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java index a3e298d..8695c6f 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java @@ -30,7 +30,6 @@ import org.apache.camel.ExtendedCamelContext; import org.apache.camel.NoFactoryAvailableException; import org.apache.camel.StaticService; import org.apache.camel.api.management.ManagedAttribute; -import org.apache.camel.api.management.ManagedOperation; import org.apache.camel.api.management.ManagedResource; import org.apache.camel.spi.FactoryFinder; import org.apache.camel.spi.Metadata; @@ -54,7 +53,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. // TODO: PropertySource / LoadablePropertySource to camel-api // TODO: Remove LocationPropertiesSource - // TODO: cache to DefaultPropertiesLookup // TODO: API on PropertiesComponent in SPI to Optional<String> lookupProperty(String name); // TODO: Add docs about `PropertiesSource` @@ -111,15 +109,12 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private final List<LocationPropertiesSource> locationSources = new ArrayList<>(); private List<PropertiesLocation> locations = Collections.emptyList(); - private transient Properties cachedLoadedProperties; @Metadata private boolean ignoreMissingLocation; @Metadata private String encoding; @Metadata(defaultValue = "true") - private boolean cache = true; - @Metadata(defaultValue = "true") private boolean defaultFallbackEnabled = true; @Metadata(label = "advanced", defaultValue = DEFAULT_PREFIX_TOKEN) private String prefixToken = DEFAULT_PREFIX_TOKEN; @@ -179,17 +174,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } public Properties loadProperties() { - if (cache) { - if (cachedLoadedProperties == null) { - cachedLoadedProperties = doLoadProperties(); - } - return cachedLoadedProperties; - } else { - return doLoadProperties(); - } - } - - protected Properties doLoadProperties() { Properties prop = new OrderedProperties(); // use initial properties @@ -344,18 +328,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. this.propertiesParser = propertiesParser; } - @ManagedAttribute(description = "Whether to cache loaded properties") - public boolean isCache() { - return cache; - } - - /** - * Whether or not to cache loaded properties. The default value is true. - */ - public void setCache(boolean cache) { - this.cache = cache; - } - @ManagedAttribute(description = "Whether to support using fallback values if a property cannot be found") public boolean isDefaultFallbackEnabled() { return defaultFallbackEnabled; @@ -497,14 +469,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } /** - * Clears the cache - */ - @ManagedOperation(description = "Clears the cache") - public void clearCache() { - this.cachedLoadedProperties = null; - } - - /** * Adds a custom {@link PropertiesSource} */ public void addPropertiesSource(PropertiesSource propertiesSource) { @@ -584,7 +548,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. @Override protected void doStop() throws Exception { - cachedLoadedProperties = null; ServiceHelper.stopAndShutdownServices(locationSources, sources); } diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.java deleted file mode 100644 index 5478eb2..0000000 --- a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.java +++ /dev/null @@ -1,38 +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.properties; -import org.junit.After; -import org.springframework.context.support.AbstractXmlApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class SpringPropertiesComponentCacheDisabledTest extends BaseSpringPropertiesComponentTest { - - @Override - protected AbstractXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.xml"); - } - - @Override - @After - public void tearDown() throws Exception { - PropertiesComponent component = context.getComponent("properties", PropertiesComponent.class); - assertFalse("Cache should be disabled", component.isCache()); - - super.tearDown(); - } - -} \ No newline at end of file diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.xml deleted file mode 100644 index 2759551..0000000 --- a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentCacheDisabledTest.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?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"> - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - - <propertyPlaceholder id="properties" location="classpath:org/apache/camel/component/properties/cheese.properties" - cache="false" prefixToken="[[" suffixToken="]]" xmlns="http://camel.apache.org/schema/spring" /> - - <route> - <from uri="direct:start" /> - <to uri="properties:[[cool.end]]" /> - </route> - - <route> - <from uri="direct:bar" /> - <to uri="properties:mock:[[cool.bar]]" /> - </route> - - <route> - <from uri="direct:start2" /> - <to uri="[[cool.end]]" /> - </route> - - <route> - <from uri="direct:bar2" /> - <to uri="mock:[[cool.bar]]" /> - </route> - </camelContext> - -</beans> diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java index c3503db..8f7c223 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java @@ -633,10 +633,6 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex pc.setLocations(locations); pc.setEncoding(def.getEncoding()); - if (def.isCache() != null) { - pc.setCache(def.isCache()); - } - if (def.isIgnoreMissingLocation() != null) { pc.setIgnoreMissingLocation(def.isIgnoreMissingLocation()); } diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java index c7cdcd5..801b1e6 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java @@ -38,8 +38,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { private String location; @XmlAttribute private String encoding; - @XmlAttribute @Metadata(defaultValue = "true") - private Boolean cache; @XmlAttribute @Metadata(defaultValue = "false") private Boolean ignoreMissingLocation; @XmlAttribute @@ -81,17 +79,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { this.encoding = encoding; } - public Boolean isCache() { - return cache; - } - - /** - * Whether or not to cache loaded properties. The default value is true. - */ - public void setCache(Boolean cache) { - this.cache = cache; - } - public String getPropertiesParserRef() { return propertiesParserRef; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java index 3d50c08..3dbfef8 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java @@ -220,31 +220,8 @@ public class PropertiesComponentTest extends ContextTestSupport { } @Test - public void testPropertiesComponentCacheDisabled() throws Exception { + public void testManyParseUri() throws Exception { PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setCache(false); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.end"); - from("direct:foo").to("properties:mock:{{cool.result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testCache() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - assertTrue(pc.isCache()); assertNotNull(pc); for (int i = 0; i < 2000; i++) { @@ -254,7 +231,7 @@ public class PropertiesComponentTest extends ContextTestSupport { } @Test - public void testCacheRoute() throws Exception { + public void testManySendMessages() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java index 823114e..0edefcf 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java @@ -22,7 +22,6 @@ import org.apache.camel.builder.RouteBuilder; import org.junit.Test; public class PropertiesEnvironmentVariableOverrideTest extends ContextTestSupport { - @Override public boolean isUseRouteBuilder() { @@ -31,9 +30,6 @@ public class PropertiesEnvironmentVariableOverrideTest extends ContextTestSuppor @Test public void testPropertiesComponentCacheDisabled() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setCache(false); - System.setProperty("cool.end", "mock:override"); System.setProperty("cool.result", "override"); diff --git a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java index e43057c..3951b3a 100644 --- a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java @@ -63,10 +63,6 @@ public class PropertiesComponentConfiguration */ private String propertiesParser; /** - * Whether or not to cache loaded properties. The default value is true. - */ - private Boolean cache = true; - /** * If false, the component does not attempt to find a default for the key by * looking after the colon separator. */ @@ -154,14 +150,6 @@ public class PropertiesComponentConfiguration this.propertiesParser = propertiesParser; } - public Boolean getCache() { - return cache; - } - - public void setCache(Boolean cache) { - this.cache = cache; - } - public Boolean getDefaultFallbackEnabled() { return defaultFallbackEnabled; }