Author: davsclaus Date: Sun Apr 17 07:39:34 2011 New Revision: 1094113 URL: http://svn.apache.org/viewvc?rev=1094113&view=rev Log: CAMEL-3875: Added osgi test for camel-cache with custom cache manager. Thanks to Piotr for the patch.
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java (with props) camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml (with props) Modified: camel/trunk/tests/camel-itest-osgi/pom.xml Modified: camel/trunk/tests/camel-itest-osgi/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1094113&r1=1094112&r2=1094113&view=diff ============================================================================== --- camel/trunk/tests/camel-itest-osgi/pom.xml (original) +++ camel/trunk/tests/camel-itest-osgi/pom.xml Sun Apr 17 07:39:34 2011 @@ -118,6 +118,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-cache</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-servlet</artifactId> <scope>test</scope> </dependency> Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java?rev=1094113&view=auto ============================================================================== --- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java (added) +++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java Sun Apr 17 07:39:34 2011 @@ -0,0 +1,121 @@ +/** + * 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.osgi.cache; + +import javax.naming.Context; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.cache.CacheEndpoint; +import org.apache.camel.component.cache.CacheManagerFactory; +import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport; +import org.apache.karaf.testing.Helper; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; + +import static org.ops4j.pax.exam.CoreOptions.equinox; +import static org.ops4j.pax.exam.CoreOptions.felix; +import static org.ops4j.pax.exam.OptionUtils.combine; +import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures; +import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory; + +@RunWith(JUnit4TestRunner.class) +public class CacheManagerFactoryRefTest extends OSGiIntegrationTestSupport { + private static final String CACHE_URI = "cache:foo?cacheManagerFactory=#cacheManagerFactory"; + private TestingCacheManagerFactory cmfRef = new TestingCacheManagerFactory("ehcache_test.xml"); + + @Override + protected Context createJndiContext() throws Exception { + Context ctx = super.createJndiContext(); + ctx.bind("cacheManagerFactory", cmfRef); + return ctx; + } + + @Test + public void testCache() throws Exception { + CacheEndpoint endpoint = (CacheEndpoint) context.getEndpoint(CACHE_URI); + + // Is CacheManagerFactory really referenced? + CacheManagerFactory cmf = endpoint.getCacheManagerFactory(); + assertEquals("Cache Manager Factory Referenced", cmfRef, cmf); + + // Is the right ehcache_test.xml config. loaded? + Cache cache = cmfRef.getCacheManager().getCache("testingOne"); + assertNotNull("Is ehcache_test.xml loaded", cache); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct:test").to(CACHE_URI); + } + }; + } + + @Configuration + public static Option[] configure() throws Exception { + Option[] options = combine( + // Default karaf environment + Helper.getDefaultOptions( + // this is how you set the default log level when using pax + // logging (logProfile) + Helper.setLogLevel("WARN")), + + // using the features to install the camel components + scanFeatures( + getCamelKarafFeatureUrl(), + "camel-core", "camel-spring", "camel-test", "camel-cache"), + + workingDirectory("target/paxrunner/"), + + felix(), equinox()); + + return options; + } + + public class TestingCacheManagerFactory extends CacheManagerFactory { + private String xmlName; + + //Only for testing purpose, normally not needed + private CacheManager cacheManager; + + public TestingCacheManagerFactory(String xmlName) { + this.xmlName = xmlName; + } + + @Override + protected synchronized CacheManager createCacheManagerInstance() { + //Singleton- only for testing purpose, normally not needed + if (cacheManager == null) { + cacheManager = CacheManager.create(getClass().getResourceAsStream(xmlName)); + } + + return cacheManager; + } + + public CacheManager getCacheManager() { + return cacheManager; + } + } + +} \ No newline at end of file Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheManagerFactoryRefTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml?rev=1094113&view=auto ============================================================================== --- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml (added) +++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml Sun Apr 17 07:39:34 2011 @@ -0,0 +1,69 @@ +<?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. +--> +<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="ehcache.xsd" > + + <diskStore path="java.io.tmpdir"/> + + <cacheManagerEventListenerFactory class="" properties=""/> + + <cacheManagerPeerProviderFactory + class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" + properties="peerDiscovery=automatic, + multicastGroupAddress=230.0.0.1, + multicastGroupPort=4446, timeToLive=1" + propertySeparator="," + /> + + + <cacheManagerPeerListenerFactory + class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/> + + <!-- + Mandatory Default Cache configuration. These settings will be applied to caches + created programmtically using CacheManager.add(String cacheName). + + The defaultCache has an implicit name "default" which is a reserved cache name. + --> + <defaultCache + maxElementsInMemory="10000" + eternal="false" + timeToIdleSeconds="120" + timeToLiveSeconds="120" + overflowToDisk="true" + diskSpoolBufferSizeMB="30" + maxElementsOnDisk="10000000" + diskPersistent="false" + diskExpiryThreadIntervalSeconds="120" + memoryStoreEvictionPolicy="LRU" + /> + + <cache name="testingOne" + maxElementsInMemory="10000" + eternal="false" + timeToIdleSeconds="120" + timeToLiveSeconds="120" + overflowToDisk="true" + diskSpoolBufferSizeMB="30" + maxElementsOnDisk="10000000" + diskPersistent="false" + diskExpiryThreadIntervalSeconds="120" + memoryStoreEvictionPolicy="LRU" + /> + +</ehcache> Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cache/ehcache_test.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml