summaryrefslogtreecommitdiffstats
path: root/sandbox/endpoint-ehcache/src/test/java/org
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-12-31 07:59:29 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-12-31 07:59:29 +0000
commitcb17099e7fb5f31435e57e1ee2c60f85b06e0868 (patch)
tree3de10046686e12f52358e983e329a5cafa4f820e /sandbox/endpoint-ehcache/src/test/java/org
parentcc231b19a109f9b028f454974e8adc7494cd053e (diff)
Have a look at using ehcache in an endpoint registry impl. In sandbaox for now to avoid yet another impl that doesnt work properly in trunk.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@894790 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/endpoint-ehcache/src/test/java/org')
-rw-r--r--sandbox/endpoint-ehcache/src/test/java/org/apache/tuscany/sca/endpoint/tribes/RegistryTestCase.java193
1 files changed, 193 insertions, 0 deletions
diff --git a/sandbox/endpoint-ehcache/src/test/java/org/apache/tuscany/sca/endpoint/tribes/RegistryTestCase.java b/sandbox/endpoint-ehcache/src/test/java/org/apache/tuscany/sca/endpoint/tribes/RegistryTestCase.java
new file mode 100644
index 0000000000..4053e9fa7d
--- /dev/null
+++ b/sandbox/endpoint-ehcache/src/test/java/org/apache/tuscany/sca/endpoint/tribes/RegistryTestCase.java
@@ -0,0 +1,193 @@
+/*
+ * 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.tuscany.sca.endpoint.tribes;
+
+import java.util.Properties;
+
+import junit.framework.Assert;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationHelper;
+import net.sf.ehcache.config.FactoryConfiguration;
+import net.sf.ehcache.config.TerracottaConfiguration;
+import net.sf.ehcache.distribution.CacheManagerPeerProvider;
+import net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory;
+import net.sf.ehcache.distribution.RMICacheManagerPeerListener;
+import net.sf.ehcache.distribution.RMICacheReplicatorFactory;
+import net.sf.ehcache.event.CacheEventListener;
+import net.sf.ehcache.event.RegisteredEventListeners;
+import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
+
+import org.junit.Test;
+
+public class RegistryTestCase {
+
+
+ @Test
+ public void foo() throws InterruptedException {
+ Cache cache2 = createCache2("ehcache2.xml");
+// Thread.sleep(4000);
+ Cache cache1 = createCache2("ehcache1.xml");
+ cache1.put(new Element("key1", "bla1"));
+ Thread.sleep(400);
+
+ Assert.assertEquals("bla1", cache2.get("key1").getObjectValue());
+ cache2.put(new Element("k2", "foo2"));
+ Thread.sleep(400);
+ Assert.assertEquals("foo2", cache1.get("k2").getObjectValue());
+ }
+
+ private Cache createCache2(String file) {
+ CacheManager manager = new CacheManager("target/test-classes/" + file);
+ Cache test = manager.getCache("sampleDistributedCache1");
+
+ manager.addCache("foo");
+ Cache test2 = manager.getCache("foo");
+
+ return test;
+ }
+
+// final Ehcache createCache(CacheConfiguration cacheConfiguration) {
+// boolean terracottaClustered = false;
+// String terracottaValueMode = null;
+// boolean terracottaCoherentReads = true;
+// TerracottaConfiguration tcConfiguration = cacheConfiguration.getTerracottaConfiguration();
+// if (tcConfiguration != null) {
+// terracottaClustered = tcConfiguration.isClustered();
+// terracottaValueMode = tcConfiguration.getValueMode().name();
+// terracottaCoherentReads = tcConfiguration.getCoherentReads();
+// }
+//
+// Ehcache cache = new Cache(cacheConfiguration.name,
+// cacheConfiguration.maxElementsInMemory,
+// cacheConfiguration.memoryStoreEvictionPolicy,
+// cacheConfiguration.overflowToDisk,
+// getDiskStorePath(),
+// cacheConfiguration.eternal,
+// cacheConfiguration.timeToLiveSeconds,
+// cacheConfiguration.timeToIdleSeconds,
+// cacheConfiguration.diskPersistent,
+// cacheConfiguration.diskExpiryThreadIntervalSeconds,
+// null,
+// null,
+// cacheConfiguration.maxElementsOnDisk,
+// cacheConfiguration.diskSpoolBufferSizeMB,
+// cacheConfiguration.clearOnFlush,
+// terracottaClustered,
+// terracottaValueMode,
+// terracottaCoherentReads);
+// RegisteredEventListeners listeners = cache.getCacheEventNotificationService();
+// registerCacheListeners(cacheConfiguration, listeners);
+// registerCacheExtensions(cacheConfiguration, cache);
+// BootstrapCacheLoader bootstrapCacheLoader = createBootstrapCacheLoader(
+// cacheConfiguration.getBootstrapCacheLoaderFactoryConfiguration());
+// cache.setBootstrapCacheLoader(bootstrapCacheLoader);
+// registerCacheLoaders(cacheConfiguration, cache);
+// cache = applyCacheExceptionHandler(cacheConfiguration, cache);
+// return cache;
+// }
+
+// private Ehcache create(CacheManager manager, String name) {
+// ConfigurationHelper ch = new ConfigurationHelper(manager, null);
+// CacheConfiguration cc = new CacheConfiguration();
+// cc.
+//
+//
+// Ehcache cache = new Cache(name,
+// 10000,
+// MemoryStoreEvictionPolicy.LRU,
+// false,
+// "",
+// true,
+// 0,
+// 0,
+// false,
+// 0,
+// null,
+// null,
+// 0,
+// 0,
+// false,
+// false,
+// null,
+// false);
+// RegisteredEventListeners listeners = cache.getCacheEventNotificationService();
+// Properties properties = new Properties();
+// properties.put("asynchronousReplicationIntervalMillis", "100");
+// listeners.registerListener(new RMICacheReplicatorFactory().createCacheEventListener(properties));
+//// registerCacheListeners(cacheConfiguration, listeners);
+//// registerCacheExtensions(cacheConfiguration, cache);
+// cache.setBootstrapCacheLoader(new RMIBootstrapCacheLoaderFactory().createBootstrapCacheLoader(null));
+//// registerCacheLoaders(cacheConfiguration, cache);
+// // cache = applyCacheExceptionHandler(cacheConfiguration, cache);
+// return cache;
+// }
+
+ private Cache createCache(int port, boolean multicast, String remotes) {
+ Configuration config = new Configuration();
+
+ if (remotes != null && remotes.length() > 0) {
+ FactoryConfiguration factory = new FactoryConfiguration();
+ factory.setClass("net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory");
+ factory.setPropertySeparator(",");
+ factory.setProperties("peerDiscovery=manual,rmiUrls=//" + remotes);
+ config.addCacheManagerPeerProviderFactory(factory);
+ }
+
+// <cacheManagerPeerProviderFactory
+// class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
+// properties="peerDiscovery=automatic,
+// multicastGroupAddress=230.0.0.1,
+// multicastGroupPort=4446, timeToLive=1"/>
+//-->
+
+ if (multicast) {
+ FactoryConfiguration factory = new FactoryConfiguration();
+ factory.setClass("net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory");
+ factory.setPropertySeparator(",");
+ factory.setProperties("peerDiscovery=automatic,multicastGroupAddress=230.0.0.1,multicastGroupPort=4446,timeToLive=1");
+ config.addCacheManagerPeerProviderFactory(factory);
+ }
+ RMICacheManagerPeerListener xxx;
+ FactoryConfiguration factoryx = new FactoryConfiguration();
+ factoryx.setClass("net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory");
+ factoryx.setPropertySeparator(",");
+ factoryx.setProperties("hostname=192.168.0.101,port=" + port);
+ config.addCacheManagerPeerListenerFactory(factoryx);
+
+ CacheConfiguration defaultCacheConfiguration = new CacheConfiguration();
+ defaultCacheConfiguration.setDiskPersistent(false);
+ config.setDefaultCacheConfiguration(defaultCacheConfiguration);
+ CacheManager singletonManager = new CacheManager(config);
+ CacheManagerPeerProvider pp = singletonManager.getCacheManagerPeerProvider("RMI");
+ Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
+// CacheEventListener cacheEventListener = new CacheEventListener();
+// memoryOnlyCache.getCacheEventNotificationService().registerListener(cacheEventListener);
+ singletonManager.addCache(memoryOnlyCache);
+ Cache test = singletonManager.getCache("testCache");
+ return test;
+ }
+
+}