Index: test/java/org/castor/cache/distributed/TestAll.java
===================================================================
--- test/java/org/castor/cache/distributed/TestAll.java (Revision 5955)
+++ test/java/org/castor/cache/distributed/TestAll.java (Arbeitskopie)
@@ -34,8 +34,12 @@
suite.addTest(TestCoherenceCacheFactory.suite());
suite.addTest(TestCoherenceCache.suite());
+ suite.addTest(TestEHCacheFactory.suite());
+ suite.addTest(TestEHCache.suite());
suite.addTest(TestFKCacheFactory.suite());
suite.addTest(TestFKCache.suite());
+ suite.addTest(TestGigaspacesCacheFactory.suite());
+ suite.addTestSuite(TestGigaspacesCache.class);
suite.addTest(TestJCacheFactory.suite());
suite.addTest(TestJCache.suite());
suite.addTest(TestJcsCacheFactory.suite());
Index: test/java/org/castor/cache/distributed/TestGigaspacesCacheFactory.java
===================================================================
--- test/java/org/castor/cache/distributed/TestGigaspacesCacheFactory.java (Revision 0)
+++ test/java/org/castor/cache/distributed/TestGigaspacesCacheFactory.java (Revision 0)
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2005 Ralf Joachim
+ *
+ * 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.castor.cache.distributed;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.castor.cache.Cache;
+import org.castor.cache.CacheAcquireException;
+import org.castor.cache.CacheFactory;
+
+/**
+ * @author Ralf Joachim
+ * @version $Revision: 5951 $ $Date: 2006-04-29 04:11:14 -0600 (Sat, 29 Apr 2006) $
+ * @since 1.0
+ */
+public final class TestGigaspacesCacheFactory extends TestCase {
+ private static final boolean DISABLE_LOGGING = true;
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("CoherenceCacheFactory Tests");
+
+ suite.addTest(new TestGigaspacesCacheFactory("testConstructor"));
+ suite.addTest(new TestGigaspacesCacheFactory("testGetCacheType"));
+ suite.addTest(new TestGigaspacesCacheFactory("testGetCacheClassName"));
+ suite.addTest(new TestGigaspacesCacheFactory("testGetCache"));
+ suite.addTest(new TestGigaspacesCacheFactory("testShutdown"));
+
+ return suite;
+ }
+
+ public TestGigaspacesCacheFactory(final String name) { super(name); }
+
+ public void testConstructor() {
+ CacheFactory cf = new GigaspacesCacheFactory();
+ assertTrue(cf instanceof GigaspacesCacheFactory);
+ }
+
+ public void testGetCacheType() {
+ CacheFactory cf = new GigaspacesCacheFactory();
+ assertEquals("gigaspaces", cf.getCacheType());
+ }
+
+ public void testGetCacheClassName() {
+ CacheFactory cf = new GigaspacesCacheFactory();
+ String classname = "org.castor.cache.distributed.GigaspacesCache";
+ assertEquals(classname, cf.getCacheClassName());
+ }
+
+ public void testGetCache() {
+ CacheFactory cf = new GigaspacesCacheFactory();
+ try {
+ Cache c = cf.getCache(null);
+ assertTrue(c instanceof GigaspacesCache);
+ } catch (CacheAcquireException ex) {
+ fail("Failed to get instance of GigaspacesCache from factroy");
+ }
+ }
+
+ public void testShutdown() {
+ Logger logger = Logger.getLogger(GigaspacesCacheFactory.class);
+ Level level = logger.getLevel();
+
+ GigaspacesCacheFactory cf = new GigaspacesCacheFactory();
+ int counter = DistributedCacheFactoryMock.getCounter();
+
+ if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }
+
+ DistributedCacheFactoryMock.setException(null);
+ cf.shutdown(Object.class.getName());
+ assertEquals(counter, DistributedCacheFactoryMock.getCounter());
+
+ DistributedCacheFactoryMock.setException(new Exception("dummy"));
+ cf.shutdown(DistributedCacheFactoryMock.class.getName());
+ assertEquals(counter, DistributedCacheFactoryMock.getCounter());
+
+ logger.setLevel(level);
+
+ DistributedCacheFactoryMock.setException(null);
+ cf.shutdown(DistributedCacheFactoryMock.class.getName());
+ assertEquals(counter + 1, DistributedCacheFactoryMock.getCounter());
+ }
+}
Index: test/java/org/castor/cache/distributed/TestGigaspacesCache.java
===================================================================
--- test/java/org/castor/cache/distributed/TestGigaspacesCache.java (Revision 0)
+++ test/java/org/castor/cache/distributed/TestGigaspacesCache.java (Revision 0)
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2005 Ralf Joachim
+ *
+ * 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.castor.cache.distributed;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.castor.cache.Cache;
+import org.castor.cache.CacheAcquireException;
+
+/**
+ * JUnit test case for Gigaspaces cache
+ * @author Werner Guttmann
+ * @version $Revision: 5951 $ $Date: 2006-04-29 04:11:14 -0600 (Sat, 29 Apr 2006) $
+ * @since 1.0.1
+ */
+public final class TestGigaspacesCache extends TestCase {
+ private static final boolean DISABLE_LOGGING = true;
+
+ public TestGigaspacesCache(final String name) {
+ super(name);
+ }
+
+ public void testStaticProperties() {
+ assertEquals("gigaspaces", GigaspacesCache.TYPE);
+ assertEquals("com.j_spaces.map.CacheFinder", GigaspacesCache.IMPLEMENTATION);
+ }
+
+ public void testConstructor() {
+ Cache c = new GigaspacesCache();
+ assertTrue(c instanceof GigaspacesCache);
+ }
+
+ public void testGetType() {
+ Cache c = new GigaspacesCache();
+ assertEquals("gigaspaces", c.getType());
+ }
+
+ public void testInitialize() {
+ Logger logger = Logger.getLogger(GigaspacesCache.class);
+ Level level = logger.getLevel();
+
+ GigaspacesCache c = new GigaspacesCache();
+ int counter = DistributedCacheFactoryMock.getCounter();
+
+ Properties params = new Properties();
+ params.put(Cache.PARAM_NAME, "dummy coherence cache");
+
+ if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }
+
+ try {
+ DistributedCacheFactoryMock.setException(new Exception("dummy"));
+ c.initialize(DistributedCacheFactoryMock.class.getName(), params);
+ fail("Failed to trow exception at initialize of CoherenceCache instance");
+ } catch (CacheAcquireException ex) {
+ assertEquals(counter, DistributedCacheFactoryMock.getCounter());
+ }
+
+ logger.setLevel(level);
+
+// try {
+// DistributedCacheFactoryMock.setException(null);
+// c.initialize(DistributedCacheFactoryMock.class.getName(), params);
+// assertEquals(counter + 1, DistributedCacheFactoryMock.getCounter());
+// assertEquals("dummy gigaspaces cache", DistributedCacheFactoryMock.getName());
+// assertEquals("dummy gigaspacescache", c.getName());
+// } catch (CacheAcquireException ex) {
+// fail("Failed to initialize GigaspacesCache instance");
+// }
+ }
+
+// public void testClose() {
+// Logger logger = Logger.getLogger(GigaspacesCache.class);
+// Level level = logger.getLevel();
+//
+// GigaspacesCache c = new GigaspacesCache();
+// int counter = DistributedCacheMock.getCounter();
+//
+// c.close();
+// assertEquals(counter, DistributedCacheMock.getCounter());
+//
+// Properties params = new Properties();
+// params.put(Cache.PARAM_NAME, "dummy coherence cache");
+//
+// try {
+// DistributedCacheFactoryMock.setException(null);
+// c.initialize(DistributedCacheFactoryMock.class.getName(), params);
+// assertEquals(counter, DistributedCacheMock.getCounter());
+// } catch (CacheAcquireException ex) {
+// fail("Failed to initialize CoherenceCache instance");
+// }
+//
+// if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }
+//
+// DistributedCacheMock.setException(new Exception("dummy"));
+// c.close();
+// assertEquals(counter, DistributedCacheMock.getCounter());
+//
+// logger.setLevel(level);
+//
+// DistributedCacheMock.setException(null);
+// c.close();
+// assertEquals(counter + 1, DistributedCacheMock.getCounter());
+// }
+//
+// private Cache initialize() throws CacheAcquireException {
+//
+// GigaspacesCacheFactory factory = new GigaspacesCacheFactory();
+// Cache c = factory.getCache(getClass().getClassLoader());
+//
+// Properties params = new Properties();
+// params.put(Cache.PARAM_NAME, "dummy gigaspaces cache");
+//
+// c.initialize(params);
+//
+// return c;
+// }
+//
+// public void testGetOnEmptyCache() throws CacheAcquireException {
+//
+// Cache c = initialize();
+//
+// Object value = c.get("first key");
+// assertNull(value);
+// }
+//
+// public void testPutAndGet() throws CacheAcquireException {
+//
+// Cache c = initialize();
+//
+// c.put("first key", "first value");
+// Object value = c.get("first key");
+// assertNotNull(value);
+// }
+//
+// public void testPutAndGetAndRemove() throws CacheAcquireException {
+//
+// Cache c = initialize();
+//
+// c.put("first key", "first value");
+//
+// Object value = c.get("first key");
+// assertNotNull(value);
+//
+// c.remove("first key");
+// value = c.get("first key");
+// assertNull(value);
+//
+// }
+
+}
Index: main/java/org/castor/cache/distributed/GigaspacesCacheFactory.java
===================================================================
--- main/java/org/castor/cache/distributed/GigaspacesCacheFactory.java (Revision 0)
+++ main/java/org/castor/cache/distributed/GigaspacesCacheFactory.java (Revision 0)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2005 Werner Guttmann
+ *
+ * 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.castor.cache.distributed;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.castor.cache.AbstractCacheFactory;
+
+/**
+ * Implements {@link CacheFactory} for the {@link GigaspacesCache} implementation
+ * of {@link Cache}.
+ *
+ * @author Werner Guttmann
+ * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
+ * @since 1.0
+ */
+public final class GigaspacesCacheFactory extends AbstractCacheFactory {
+
+ /** The Jakarta Commons
+ * Logging instance used for all logging. */
+ private static final Log LOG = LogFactory.getLog(GigaspacesCacheFactory.class);
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.CacheFactory#getCacheType()
+ */
+ public String getCacheType() { return GigaspacesCache.TYPE; }
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.CacheFactory#getCacheClassName()
+ */
+ public String getCacheClassName() { return GigaspacesCache.class.getName(); }
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.CacheFactory#shutdown()
+ */
+ public void shutdown() { shutdown(GigaspacesCache.IMPLEMENTATION); }
+
+ /**
+ * Normally called to shutdown GigaspacesCache. To be able to test the method
+ * without having com.tangosol.net.CacheFactory implementation,
+ * it can also be called with a test implementations classname.
+ *
+ * @param implementation Cache implementation classname to shutdown.
+ */
+ public void shutdown(final String implementation) {
+ try {
+ ClassLoader ldr = this.getClass().getClassLoader();
+ Class cls = ldr.loadClass(implementation);
+ if (cls != null) {
+ Method method = cls.getMethod("shutdown", null);
+ method.invoke(null, null);
+ }
+ } catch (Exception e) {
+ LOG.error("Problem shutting down Gigaspaces cluster member", e);
+ }
+ }
+}
Index: main/java/org/castor/cache/distributed/GigaspacesCache.java
===================================================================
--- main/java/org/castor/cache/distributed/GigaspacesCache.java (Revision 0)
+++ main/java/org/castor/cache/distributed/GigaspacesCache.java (Revision 0)
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2005 Werner Guttmann
+ *
+ * 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.castor.cache.distributed;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.castor.cache.Cache;
+import org.castor.cache.CacheAcquireException;
+
+/**
+ * Gigaspaces implementation of Castor JDO Cache.
+ *
+ * For more details of Coherence, see http://www.gigaspaces.com/
+ *
+ * @see http://www.gigaspaces.com/
+ * @author Werner Guttmann
+ * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
+ * @since 1.0
+ */
+public final class GigaspacesCache extends AbstractDistributedCache {
+ //--------------------------------------------------------------------------
+
+ /** The Jakarta Commons
+ * Logging instance used for all logging. */
+ private static final Log LOG = LogFactory.getLog(GigaspacesCache.class);
+
+ /** The type of the cache. */
+ public static final String TYPE = "gigaspaces";
+
+ /** The classname of the implementations factory class. */
+ public static final String IMPLEMENTATION = "com.j_spaces.map.CacheFinder";
+
+ /** Parameter types for calling getCache() method on IMPLEMENTATION. */
+ private static final Class[] TYPES_FIND_CACHE = new Class[] {String.class};
+
+ //--------------------------------------------------------------------------
+ // operations for life-cycle management of cache
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.Cache#initialize(java.util.Map)
+ */
+ public void initialize(final Properties params) throws CacheAcquireException {
+ initialize(IMPLEMENTATION, params);
+ }
+
+ /**
+ * Normally called to initialize CoherenceCache. To be able to test the method
+ * without having com.tangosol.net.CacheFactory implementation,
+ * it can also be called with a test implementations classname.
+ *
+ * @param implementation Cache implementation classname to initialize.
+ * @param params Parameters to initialize the cache (e.g. name, capacity).
+ * @throws CacheAcquireException If cache can not be initialized.
+ */
+ public void initialize(final String implementation, final Properties params)
+ throws CacheAcquireException {
+ super.initialize(params);
+
+ try {
+ ClassLoader ldr = this.getClass().getClassLoader();
+ Class cls = ldr.loadClass(implementation);
+ setCache((Map) invokeStaticMethod(
+ cls, "find", TYPES_FIND_CACHE, new Object[] {getExtendedName()}));
+ } catch (Exception e) {
+ String msg = "Error creating Gigaspaces cache: " + e.getMessage();
+ LOG.error(msg, e);
+ throw new CacheAcquireException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see Cache#getName()
+ */
+ public String getExtendedName() {
+ return "/./" + getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.Cache#close()
+ */
+ public void close() {
+ super.close();
+
+ if (getCache() != null) {
+ try {
+ invokeMethod(getCache(), "release", null, null);
+ } catch (Exception e) {
+ String msg = "Error closing Gigaspaces cache: " + e.getMessage();
+ LOG.error(msg, e);
+ }
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ // getters/setters for cache configuration
+
+ /**
+ * {@inheritDoc}
+ * @see org.castor.cache.Cache#getType()
+ */
+ public String getType() { return TYPE; }
+
+ //--------------------------------------------------------------------------
+}