incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r1404941 - in /sling/whiteboard/ieb/cache/infinispan: pom.xml src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
Date Fri, 02 Nov 2012 12:12:01 GMT
Author: ieb
Date: Fri Nov  2 12:12:00 2012
New Revision: 1404941

URL: http://svn.apache.org/viewvc?rev=1404941&view=rev
Log:
SLING-2555 Fixed Infinispan bundle and tested in pax exam.

Added:
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
  (with props)
Modified:
    sling/whiteboard/ieb/cache/infinispan/pom.xml
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java

Modified: sling/whiteboard/ieb/cache/infinispan/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/pom.xml?rev=1404941&r1=1404940&r2=1404941&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/pom.xml (original)
+++ sling/whiteboard/ieb/cache/infinispan/pom.xml Fri Nov  2 12:12:00 2012
@@ -47,12 +47,17 @@
         <plugins>
             <plugin>
                 <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <version>2.3.6</version>
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
 		            <Import-Package>
+		               !bsh,
 		               !org.jboss.logmanager, 
 		               !org.jboss.modules,
 		               !net.jcip.annotations,
@@ -63,8 +68,8 @@
 		            <Private-Package>
 		            	org.apache.sling.commons.cache.infinispan.*,
 		            	org.apache.sling.commons.cache.impl.*
-		            	</Private-Package>
-		            <DynamicImport-Package>sun.misc.*</DynamicImport-Package>
+		            </Private-Package>
+		            <DynamicImport-Package>*,sun.misc,sun.reflect,javax.transaction,javax.transaction.xa</DynamicImport-Package>
 		            <Embed-Transitive>true</Embed-Transitive>
 		            <Embed-Dependency>
 		            infinispan-core,
@@ -78,6 +83,36 @@
             </plugin>
         </plugins>
     </build>
+    <profiles>
+        <profile>
+            <id>java6</id>
+            <activation>
+                <jdk>1.6</jdk>
+            </activation>
+            <build>
+                <plugins>
+                  <!-- integration tests run with pax-exam -->
+                    <plugin>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>2.12</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                        <configuration>
+                            <includes>
+                                <include>**/*IT.java</include>
+                            </includes>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 
     <dependencies>
         <dependency>
@@ -120,6 +155,11 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
-        
+        <dependency>
+	       	<groupId>org.apache.sling</groupId>
+	       	<artifactId>org.apache.sling.commons.cache.container-test</artifactId>
+	       	<version>0.1-SNAPSHOT</version>
+	       	<scope>test</scope>
+        </dependency>        
     </dependencies>
 </project>

Modified: sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java?rev=1404941&r1=1404940&r2=1404941&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java
(original)
+++ sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java
Fri Nov  2 12:12:00 2012
@@ -80,32 +80,37 @@ public class CacheManagerServiceImpl ext
 		String config = toString(properties.get(CACHE_CONFIG),
 				DEFAULT_CACHE_CONFIG);
 		File configFile = new File(config);
-		if (configFile.exists()) {
-			LOGGER.info("Configuring Cache from {} ",
-					configFile.getAbsolutePath());
-			InputStream in = null;
-			try {
-				in = processConfig(new FileInputStream(configFile), properties);
-				cacheManager  = new DefaultCacheManager(in);
-			} finally {
-				if (in != null) {
-					in.close();
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		try {
+			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+			if (configFile.exists()) {
+				LOGGER.info("Configuring Cache from {} ",
+						configFile.getAbsolutePath());
+				InputStream in = null;
+				try {
+					in = processConfig(new FileInputStream(configFile), properties);
+					cacheManager  = new DefaultCacheManager(in);
+				} finally {
+					if (in != null) {
+						in.close();
+					}
 				}
+			} else {
+				LOGGER.info("Configuring Cache from Classpath Default {} ",
+						CONFIG_PATH);
+				InputStream in = processConfig(this.getClass().getClassLoader()
+						.getResourceAsStream(CONFIG_PATH), properties);
+				if (in == null) {
+					throw new IOException(
+							"Unable to open config at classpath location "
+									+ CONFIG_PATH);
+				}
+				cacheManager  = new DefaultCacheManager(in);
+				in.close();
 			}
-		} else {
-			LOGGER.info("Configuring Cache from Classpath Default {} ",
-					CONFIG_PATH);
-			InputStream in = processConfig(this.getClass().getClassLoader()
-					.getResourceAsStream(CONFIG_PATH), properties);
-			if (in == null) {
-				throw new IOException(
-						"Unable to open config at classpath location "
-								+ CONFIG_PATH);
-			}
-			cacheManager  = new DefaultCacheManager(in);
-			in.close();
+		} finally {
+			Thread.currentThread().setContextClassLoader(cl);
 		}
-		
 
 		final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(
 				this);

Added: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java?rev=1404941&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
(added)
+++ sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
Fri Nov  2 12:12:00 2012
@@ -0,0 +1,186 @@
+/*
+ * 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.sling.commons.cache.infinispan;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+
+import javax.inject.Inject;
+
+import org.apache.sling.commons.cache.api.Cache;
+import org.apache.sling.commons.cache.api.CacheManagerService;
+import org.apache.sling.commons.cache.api.CacheScope;
+import org.apache.sling.test.AbstractOSGiRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.ExamReactorStrategy;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Spin the cache up in a container to verify we have a working system.
+ */
+@RunWith(JUnit4TestRunner.class)
+@ExamReactorStrategy(EagerSingleStagedReactorFactory.class) // we want to spin up the container
once only.
+public class CacheIT extends AbstractOSGiRunner {
+
+
+	@Inject
+	private CacheManagerService cacheManagerService;
+	
+	@Inject
+	private BundleContext bundleContext;
+		
+
+	@Override
+	protected String getImports() {
+		return "org.apache.sling.commons.cache.api,javax.transaction,javax.transaction.xa";
+	}
+	
+
+	@Override
+	public Option[] getOptions() {
+		// check();
+		return options(
+				provision(
+						// Infinispan needs a transaction API.
+			            mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
+						mavenBundle("org.apache.sling", "org.apache.sling.commons.cache.api")
+				));
+	}
+
+
+	@Override
+	protected String getArtifactName() {
+		return "org.apache.sling.commons.cache.infinispan";
+	}
+
+
+	@Test
+	public void testCacheManagerReplicated() {
+		check();
+		String cacheName = "string-cache-replicated";
+		Assert.assertNotNull(cacheManagerService);
+		Cache<String> c = cacheManagerService.getCache(cacheName,
+				CacheScope.CLUSTERREPLICATED);
+		Assert.assertNotNull(c);
+		String v = cacheName + String.valueOf(System.currentTimeMillis());
+		c.put("key", v);
+		Assert.assertEquals(v, c.get("key"));
+		cacheManagerService.unbind(CacheScope.CLUSTERREPLICATED);
+		cacheManagerService.unbind(CacheScope.CLUSTERINVALIDATED);
+		cacheManagerService.unbind(CacheScope.INSTANCE);
+		cacheManagerService.unbind(CacheScope.REQUEST);
+		cacheManagerService.unbind(CacheScope.THREAD);
+		c = cacheManagerService.getCache(cacheName,
+				CacheScope.CLUSTERREPLICATED);
+		Assert.assertNotNull(c);
+		Assert.assertEquals(v, c.get("key"));
+
+	}
+
+	@Test
+	public void testCacheManagerInvalidated() {
+		String cacheName = "string-cache-invalidated";
+		Assert.assertNotNull(cacheManagerService);
+		Cache<String> c = cacheManagerService.getCache(cacheName,
+				CacheScope.CLUSTERINVALIDATED);
+		Assert.assertNotNull(c);
+		String v = cacheName + String.valueOf(System.currentTimeMillis());
+		c.put("key", v);
+		Assert.assertEquals(v, c.get("key"));
+		cacheManagerService.unbind(CacheScope.CLUSTERREPLICATED);
+		cacheManagerService.unbind(CacheScope.CLUSTERINVALIDATED);
+		cacheManagerService.unbind(CacheScope.INSTANCE);
+		cacheManagerService.unbind(CacheScope.REQUEST);
+		cacheManagerService.unbind(CacheScope.THREAD);
+		c = cacheManagerService.getCache(cacheName,
+				CacheScope.CLUSTERINVALIDATED);
+		Assert.assertNotNull(c);
+		Assert.assertEquals(v, c.get("key"));
+	}
+
+
+
+	@Test
+	public void testCacheManagerInstance() {
+		String cacheName = "string-cache-instance";
+		Assert.assertNotNull(cacheManagerService);
+		Cache<String> c = cacheManagerService.getCache(cacheName,
+				CacheScope.INSTANCE);
+		Assert.assertNotNull(c);
+		String v = cacheName + String.valueOf(System.currentTimeMillis());
+		c.put("key", v);
+		Assert.assertEquals(v, c.get("key"));
+		cacheManagerService.unbind(CacheScope.CLUSTERREPLICATED);
+		cacheManagerService.unbind(CacheScope.CLUSTERINVALIDATED);
+		cacheManagerService.unbind(CacheScope.INSTANCE);
+		cacheManagerService.unbind(CacheScope.REQUEST);
+		cacheManagerService.unbind(CacheScope.THREAD);
+		c = cacheManagerService.getCache(cacheName, CacheScope.INSTANCE);
+		Assert.assertNotNull(c);
+		Assert.assertEquals(v, c.get("key"));
+	}
+
+	@Test
+	public void testCacheManagerRequest() {
+		String cacheName = "string-cache-request";
+		Assert.assertNotNull(cacheManagerService);
+		Cache<String> c = cacheManagerService.getCache(cacheName,
+				CacheScope.REQUEST);
+		Assert.assertNotNull(c);
+		String v = cacheName + String.valueOf(System.currentTimeMillis());
+		c.put("key", v);
+		Assert.assertEquals(v, c.get("key"));
+		cacheManagerService.unbind(CacheScope.CLUSTERREPLICATED);
+		cacheManagerService.unbind(CacheScope.CLUSTERINVALIDATED);
+		cacheManagerService.unbind(CacheScope.INSTANCE);
+		cacheManagerService.unbind(CacheScope.REQUEST);
+		cacheManagerService.unbind(CacheScope.THREAD);
+		c = cacheManagerService.getCache(cacheName, CacheScope.REQUEST);
+		Assert.assertNotNull(c);
+		Assert.assertNull(c.get("key"));
+	}
+
+	@Test
+	public void testCacheManagerThread() {
+		String cacheName = "string-cache-thread";
+		Assert.assertNotNull(cacheManagerService);
+		Cache<String> c = cacheManagerService.getCache(cacheName,
+				CacheScope.THREAD);
+		Assert.assertNotNull(c);
+		String v = cacheName + String.valueOf(System.currentTimeMillis());
+		c.put("key", v);
+		Assert.assertEquals(v, c.get("key"));
+		cacheManagerService.unbind(CacheScope.CLUSTERREPLICATED);
+		cacheManagerService.unbind(CacheScope.CLUSTERINVALIDATED);
+		cacheManagerService.unbind(CacheScope.INSTANCE);
+		cacheManagerService.unbind(CacheScope.REQUEST);
+		cacheManagerService.unbind(CacheScope.THREAD);
+		c = cacheManagerService.getCache(cacheName, CacheScope.THREAD);
+		Assert.assertNotNull(c);
+		Assert.assertNull(c.get("key"));
+	}
+
+}

Propchange: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheIT.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message