Author: iocanel
Date: Tue Jun 19 15:04:14 2012
New Revision: 1351735

URL: http://svn.apache.org/viewvc?rev=1351735&view=rev
Log:
[DIRECTMEMORY-90] Added OSGi support to directmemory-ehcache integration.

Added:
    
incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/
    
incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java
    incubator/directmemory/trunk/itests/osgi/src/test/resources/
    incubator/directmemory/trunk/itests/osgi/src/test/resources/ehcache.xml
Modified:
    incubator/directmemory/trunk/integrations/ehcache/pom.xml
    incubator/directmemory/trunk/itests/osgi/pom.xml
    incubator/directmemory/trunk/platforms/karaf/src/main/resources/features.xml
    incubator/directmemory/trunk/pom.xml

Modified: incubator/directmemory/trunk/integrations/ehcache/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/integrations/ehcache/pom.xml?rev=1351735&r1=1351734&r2=1351735&view=diff
==============================================================================
--- incubator/directmemory/trunk/integrations/ehcache/pom.xml (original)
+++ incubator/directmemory/trunk/integrations/ehcache/pom.xml Tue Jun 19 
15:04:14 2012
@@ -1,71 +1,81 @@
-<?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.directmemory</groupId>
-    <artifactId>directmemory-integrations</artifactId>
-    <version>0.1-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>directmemory-ehcache</artifactId>
-  <name>Apache DirectMemory :: Integrations :: EHCache</name>
-  <description>EHCache CacheStore Implementation to integrate DirectMemory 
Cache as OffHeapStore.
-  </description>
-
-  <build>
-    <plugins>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <argLine>-Xmx512m -Xms512m -XX:MaxDirectMemorySize=512m</argLine>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-  <dependencies>
-    <!-- DirectMemory Dependency -->
-    <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>directmemory-cache</artifactId>
-    </dependency>
-
-    <!-- EHCache Dependency -->
-    <dependency>
-      <groupId>net.sf.ehcache</groupId>
-      <artifactId>ehcache-core</artifactId>
-      <version>2.5.0</version>
-    </dependency>
-
-    <!-- Testing Dependencies -->
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-</project>
+<?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.directmemory</groupId>
+        <artifactId>directmemory-integrations</artifactId>
+        <version>0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>directmemory-ehcache</artifactId>
+    <name>Apache DirectMemory :: Integrations :: EHCache</name>
+    <packaging>bundle</packaging>
+    <description>EHCache CacheStore Implementation to integrate DirectMemory 
Cache as OffHeapStore.</description>
+
+    <properties>
+        <osgi.import>
+            org.apache.directmemory*;version="${project.version}",
+            org.slf4j*,
+            *
+        </osgi.import>
+        <osgi.export>
+            
org.apache.directmemory.ehcache;version="${project.version}";-noimport:=true,
+            net.sf.ehcache.store.offheap;version="2.5.0";-noimport:=true
+        </osgi.export>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <argLine>-Xmx512m -Xms512m 
-XX:MaxDirectMemorySize=512m</argLine>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <!-- DirectMemory Dependency -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>directmemory-cache</artifactId>
+        </dependency>
+
+        <!-- EHCache Dependency -->
+        <dependency>
+            <groupId>net.sf.ehcache</groupId>
+            <artifactId>ehcache-core</artifactId>
+        </dependency>
+
+        <!-- Testing Dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

Modified: incubator/directmemory/trunk/itests/osgi/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/itests/osgi/pom.xml?rev=1351735&r1=1351734&r2=1351735&view=diff
==============================================================================
--- incubator/directmemory/trunk/itests/osgi/pom.xml (original)
+++ incubator/directmemory/trunk/itests/osgi/pom.xml Tue Jun 19 15:04:14 2012
@@ -51,6 +51,12 @@ under the License.
     </dependency>
 
     <dependency>
+      <groupId>org.apache.directmemory</groupId>
+      <artifactId>directmemory-ehcache</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>

Added: 
incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java?rev=1351735&view=auto
==============================================================================
--- 
incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java
 (added)
+++ 
incubator/directmemory/trunk/itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java
 Tue Jun 19 15:04:14 2012
@@ -0,0 +1,143 @@
+/**
+ *  Copyright 2003-2010 Terracotta, Inc.
+ *
+ *  Licensed 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.directmemory.tests.osgi.ehcache;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.ehcache.CacheException;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+import org.apache.directmemory.tests.osgi.DirectMemoryOsgiTestSupport;
+import org.apache.directmemory.tests.osgi.cache.SimpleObject;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.osgi.framework.Constants;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+
+@RunWith(JUnit4TestRunner.class)
+public class EhCacheTest extends DirectMemoryOsgiTestSupport {
+
+  @Test
+  public void testPutRetreive() {
+    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+    CacheManager cacheManager = CacheManager.getInstance();
+    Ehcache ehcache = cacheManager.getEhcache("testCache");
+
+    ehcache.put(new Element("testKey", "testValue"));
+    stats(ehcache);
+    Assert.assertEquals("testValue", ehcache.get("testKey").getObjectValue());
+  }
+
+  @Test
+  public void testSizing() {
+    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+    CacheManager cacheManager = CacheManager.getInstance();
+    Ehcache ehcache = cacheManager.getEhcache("testCache");
+    for (int i = 0; i < 30000; i++) {
+      if ((i % 1000) == 0) {
+        System.out.println("heatbeat " + i);
+        stats(ehcache);
+      }
+      ehcache.put(new Element(i, new byte[1024]));
+    }
+    stats(ehcache);
+    Assert.assertTrue(true);
+  }
+
+  @Test
+  public void testOffHeapExceedMemory()
+          throws IOException {
+    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+    CacheManager cacheManager = CacheManager.getInstance();
+    Ehcache ehcache = cacheManager.getEhcache("testCache");
+    Element element = null;
+    try {
+      for (int i = 0; i < 3000000; i++) {
+        if ((i % 1000) == 0) {
+          System.out.println("heatbeat 2 " + i);
+          stats(ehcache);
+        }
+        element = new Element(i, new byte[1024]);
+        ehcache.put(element);
+      }
+      Assert.fail("CacheException expected for DirectMemory OffHeap Memory 
Exceeded");
+    } catch (CacheException e) {
+      stats(ehcache);
+      Assert.assertTrue("CacheException expected for DirectMemory OffHeap 
Memory Exceeded", true);
+    }
+
+  }
+
+  private void stats(Ehcache ehcache) {
+    System.out.println("OnHeapSize=" + ehcache.calculateInMemorySize() + ", 
OnHeapElements="
+            + ehcache.getMemoryStoreSize());
+    System.out.println("OffHeapSize=" + ehcache.calculateOffHeapSize() + ", 
OffHeapElements="
+            + ehcache.getOffHeapStoreSize());
+    System.out.println("DiskStoreSize=" + ehcache.calculateOnDiskSize() + ", 
DiskStoreElements="
+            + ehcache.getDiskStoreSize());
+  }
+
+  public static Option[] getDynamicMemoryEhCacheOptions() {
+    List<MavenArtifactProvisionOption> mavenOptions = Arrays.asList(
+            
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.ehcache").version(
+                    "2.5.0_2"),
+            
mavenBundle().groupId("org.apache.directmemory").artifactId("directmemory-ehcache").version(
+                    System.getProperty("direct.memory.version")));
+
+    List<Option> options = new ArrayList<Option>();
+    
options.addAll(Arrays.asList(DirectMemoryOsgiTestSupport.getDynamicMemoryOptions()));
+    options.addAll(mavenOptions);
+
+    if (Boolean.getBoolean("osgi.debug")) {
+      options.add(enabledDebuggingOnPort(Integer.getInteger("osgi.debug.port"),
+              Boolean.getBoolean("osgi.debug.suspend")));
+    }
+
+    return options.toArray(new Option[options.size()]);
+  }
+
+  @Configuration
+  public Option[] configure() {
+    return combine(getDynamicMemoryEhCacheOptions(), new Customizer() {
+      @Override
+      public InputStream customizeTestProbe(InputStream testProbe) {
+        return modifyBundle(testProbe)
+                .add(SimpleObject.class)
+                .add("/ehcache.xml", 
EhCacheTest.class.getResource("/ehcache.xml"))
+                .set(Constants.DYNAMICIMPORT_PACKAGE, "*").build();
+      }
+    },
+            //Uncomment the line below to debug test
+            //enabledDebuggingOnPort(5005,true),
+            felix(), equinox());
+  }
+}

Added: incubator/directmemory/trunk/itests/osgi/src/test/resources/ehcache.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/itests/osgi/src/test/resources/ehcache.xml?rev=1351735&view=auto
==============================================================================
--- incubator/directmemory/trunk/itests/osgi/src/test/resources/ehcache.xml 
(added)
+++ incubator/directmemory/trunk/itests/osgi/src/test/resources/ehcache.xml Tue 
Jun 19 15:04:14 2012
@@ -0,0 +1,31 @@
+<!--
+  ~ 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>
+
+    <defaultCache />
+
+    <cache name="testCache"
+      eternal="false"
+      diskPersistent="false"
+      overflowToOffHeap="true"
+      maxElementsInMemory="30"
+      maxBytesLocalOffHeap="100M"
+    />
+
+</ehcache>
\ No newline at end of file

Modified: 
incubator/directmemory/trunk/platforms/karaf/src/main/resources/features.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/platforms/karaf/src/main/resources/features.xml?rev=1351735&r1=1351734&r2=1351735&view=diff
==============================================================================
--- 
incubator/directmemory/trunk/platforms/karaf/src/main/resources/features.xml 
(original)
+++ 
incubator/directmemory/trunk/platforms/karaf/src/main/resources/features.xml 
Tue Jun 19 15:04:14 2012
@@ -17,9 +17,9 @@
   ~ under the License.
   -->
 
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0";>
+<features name="direct-memory-${project.version}" 
xmlns="http://karaf.apache.org/xmlns/features/v1.0.0";>
 
-  <feature name='directmemory' description='Apache DirectMememory' 
version='${project.version}' resolver='(obr)'>
+  <feature name='directmemory' description='Apache DirectMemory' 
version='${project.version}' resolver='(obr)'>
     <bundle dependency='true'>
       
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.guava/${guava.bundle.version}
     </bundle>
@@ -35,5 +35,14 @@
     <bundle 
dependency='true'>mvn:com.dyuproject.protostuff/protostuff-uberjar/${protostuff.version}</bundle>
     
<bundle>mvn:org.apache.directmemory/directmemory-cache/${project.version}</bundle>
   </feature>
+
+  <feature name='directmemory-ehcace' description='Apache DirectMemory - 
EhCache' version='${project.version}' resolver='(obr)'>
+      <feature version="${project.version}">directmemory</feature>
+      <bundle dependency='true'>
+          
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache/${ehcache.bundle.version}
+      </bundle>
+      
<bundle>mvn:org.apache.directmemory/directmemory-ehcache/${project.version}</bundle>
+  </feature>
+
 </features>
 

Modified: incubator/directmemory/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/pom.xml?rev=1351735&r1=1351734&r2=1351735&view=diff
==============================================================================
--- incubator/directmemory/trunk/pom.xml (original)
+++ incubator/directmemory/trunk/pom.xml Tue Jun 19 15:04:14 2012
@@ -237,6 +237,8 @@ under the License.
     <aspectj.bundle.version>1.6.8_2</aspectj.bundle.version>
     <aspectj.version>1.6.12</aspectj.version>
     <doclava.version>1.0.5</doclava.version>
+    <ehcache.version>2.5.0</ehcache.version>
+    <ehcache.bundle.version>2.5.0_2</ehcache.bundle.version>
     <guava.bundle.version>09_1</guava.bundle.version>
     <guava.version>r09</guava.version>
     <h2.version>1.3.158</h2.version>
@@ -513,7 +515,11 @@ under the License.
         <artifactId>directmemory-server</artifactId>
         <version>${project.version}</version>
       </dependency>
-
+      <dependency>
+        <groupId>org.apache.directmemory</groupId>
+        <artifactId>directmemory-ehcache</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.aspectj</groupId>
         <artifactId>aspectjrt</artifactId>
@@ -620,6 +626,12 @@ under the License.
       </dependency>
 
       <dependency>
+        <groupId>net.sf.ehcache</groupId>
+        <artifactId>ehcache-core</artifactId>
+        <version>${ehcache.version}</version>
+      </dependency>
+
+      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4j.version}</version>


Reply via email to