You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/11/13 21:09:12 UTC

svn commit: r1769547 - in /sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/commons/ src...

Author: olli
Date: Sun Nov 13 21:09:12 2016
New Revision: 1769547

URL: http://svn.apache.org/viewvc?rev=1769547&view=rev
Log:
SLING-6282 Provide Commons Caching Ehcache

Added:
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/pom.xml
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/EhcacheCacheManagerService.java
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheManagerServiceIT.java
    sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheTestSupport.java

Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/pom.xml?rev=1769547&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/pom.xml (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/pom.xml Sun Nov 13 21:09:12 2016
@@ -0,0 +1,211 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>29</version>
+    <relativePath/>
+  </parent>
+
+  <artifactId>org.apache.sling.commons.caching.ehcache</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Sling Commons Caching Ehcache</name>
+  <description>Apache Sling Commons Caching Ehcache</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <sling.java.version>8</sling.java.version>
+    <org.ops4j.pax.exam.version>4.9.2</org.ops4j.pax.exam.version>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <_dsannotations>*</_dsannotations>
+            <_metatypeannotations>*</_metatypeannotations>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>it</id>
+      <activation>
+        <jdk>[1.8,)</jdk>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-failsafe-plugin</artifactId>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>integration-test</goal>
+                  <goal>verify</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <systemProperties>
+                <property>
+                  <name>bundle.filename</name>
+                  <value>${basedir}/target/${project.build.finalName}.jar</value>
+                </property>
+              </systemProperties>
+            </configuration>
+          </plugin>
+          <plugin>
+            <groupId>org.apache.servicemix.tooling</groupId>
+            <artifactId>depends-maven-plugin</artifactId>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>generate-depends-file</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
+  <dependencies>
+    <!-- javax -->
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.cache</groupId>
+      <artifactId>cache-api</artifactId>
+      <version>1.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- OSGi -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- Apache Felix -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>5.4.0</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- Apache Sling -->
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.commons.caching</artifactId>
+      <scope>provided</scope>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.paxexam</artifactId>
+      <version>0.0.3-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- Ehcache -->
+    <dependency>
+      <groupId>org.ehcache</groupId>
+      <artifactId>ehcache</artifactId>
+      <version>3.2.0.beta1</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- jsr305 -->
+    <dependency>
+      <groupId>com.google.code.findbugs</groupId>
+      <artifactId>jsr305</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-cm</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-forked</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/EhcacheCacheManagerService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/EhcacheCacheManagerService.java?rev=1769547&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/EhcacheCacheManagerService.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/main/java/org/apache/sling/commons/caching/ehcache/internal/EhcacheCacheManagerService.java Sun Nov 13 21:09:12 2016
@@ -0,0 +1,95 @@
+/*
+ * 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.caching.ehcache.internal;
+
+import javax.annotation.Nonnull;
+import javax.cache.Cache;
+import javax.cache.CacheManager;
+import javax.cache.configuration.Configuration;
+
+import org.apache.sling.commons.caching.CacheManagerService;
+import org.apache.sling.commons.caching.base.AbstractCacheManagerService;
+import org.ehcache.jsr107.EhcacheCachingProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+
+@Component(
+    service = CacheManagerService.class,
+    immediate = true,
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Service managing Ehcache caches",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+    }
+)
+public class EhcacheCacheManagerService extends AbstractCacheManagerService {
+
+    private BundleContext bundleContext;
+
+    private EhcacheCachingProvider cachingProvider;
+
+    private CacheManager cacheManager;
+
+    public EhcacheCacheManagerService() {
+    }
+
+    @Activate
+    protected void activate(final BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+        cachingProvider = new EhcacheCachingProvider();
+        cacheManager = cachingProvider.getCacheManager();
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        bundleContext = null;
+        for (final String cacheName : cacheManager.getCacheNames()) {
+            destroyCache(cacheName);
+        }
+        cachingProvider.close();
+        cacheManager = null;
+        cachingProvider = null;
+    }
+
+    @Override
+    protected BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    @Override
+    protected CacheManager getCacheManager() {
+        return cacheManager;
+    }
+
+    @Override
+    public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(final @Nonnull String cacheName, final @Nonnull C configuration) throws IllegalArgumentException {
+        final Cache<K, V> cache = super.createCache(cacheName, configuration);
+        registerCache(cache, configuration);
+        return cache;
+    }
+
+    @Override
+    public void destroyCache(final @Nonnull String cacheName) {
+        unregisterCache(cacheName);
+        super.destroyCache(cacheName);
+    }
+
+}

Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheManagerServiceIT.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheManagerServiceIT.java?rev=1769547&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheManagerServiceIT.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheManagerServiceIT.java Sun Nov 13 21:09:12 2016
@@ -0,0 +1,58 @@
+/*
+ * 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.caching.ehcache.it;
+
+import javax.cache.Cache;
+import javax.cache.configuration.Configuration;
+import javax.cache.configuration.MutableConfiguration;
+import javax.inject.Inject;
+
+import org.apache.sling.commons.caching.CacheManagerService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class EhcacheCacheManagerServiceIT extends EhcacheCacheTestSupport {
+
+    @Inject
+    protected CacheManagerService cacheManagerService;
+
+    @Test
+    public void testCacheManagerService() {
+        assertNotNull(cacheManagerService);
+    }
+
+    @Test
+    public void testCreateAndGetCache() {
+        final Configuration<String, String> configuration = new MutableConfiguration<>();
+        final Cache c1 = cacheManagerService.createCache("foo", configuration);
+        assertNotNull(c1);
+        final Cache c2 = cacheManagerService.getCache("foo");
+        assertNotNull(c2);
+        assertEquals(c1, c2);
+    }
+
+}

Added: sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheTestSupport.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheTestSupport.java?rev=1769547&view=auto
==============================================================================
--- sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheTestSupport.java (added)
+++ sling/whiteboard/olli/caching/org.apache.sling.commons.caching.ehcache/src/test/java/org/apache/sling/commons/caching/ehcache/it/EhcacheCacheTestSupport.java Sun Nov 13 21:09:12 2016
@@ -0,0 +1,48 @@
+/*
+ * 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.caching.ehcache.it;
+
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+
+import static org.apache.sling.testing.paxexam.SlingOptions.config;
+import static org.apache.sling.testing.paxexam.SlingOptions.scr;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+public class EhcacheCacheTestSupport extends TestSupport {
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            config(),
+            scr(),
+            // Commons Cache Ehcache
+            testBundle("bundle.filename"),
+            mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.caching").versionAsInProject(),
+            mavenBundle().groupId("org.ehcache").artifactId("ehcache").versionAsInProject(),
+            mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.javax-cache-api").version("1.0.0_1"),
+            // testing
+            junitBundles()
+        };
+    }
+
+}