started working on remote cluster test
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1497768a Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1497768a Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1497768a Branch: refs/heads/develop Commit: 1497768a27506d6d5cd0aec0b0754b055a7f8e8d Parents: 89763d1 Author: Sebastian Schaffert <[email protected]> Authored: Tue Mar 4 19:13:17 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Tue Mar 4 19:13:17 2014 +0100 ---------------------------------------------------------------------- libraries/kiwi/kiwi-caching-infinispan/pom.xml | 5 + .../remote/InfinispanRemoteCacheManager.java | 61 +++++-- .../marmotta/kiwi/test/RemoteClusterTest.java | 158 +++++++++++++++++++ .../kiwi/test/cluster/BaseClusterTest.java | 29 +++- parent/pom.xml | 5 + 5 files changed, 239 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-caching-infinispan/pom.xml b/libraries/kiwi/kiwi-caching-infinispan/pom.xml index ddbbab0..5bd3416 100644 --- a/libraries/kiwi/kiwi-caching-infinispan/pom.xml +++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml @@ -112,6 +112,11 @@ <artifactId>sesame-rio-rdfxml</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.infinispan</groupId> + <artifactId>infinispan-server-hotrod</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java index 0090387..39a20b6 100644 --- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java +++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java @@ -19,10 +19,14 @@ package org.apache.marmotta.kiwi.infinispan.remote; import org.apache.marmotta.kiwi.caching.CacheManager; import org.apache.marmotta.kiwi.config.KiWiConfiguration; +import org.apache.marmotta.kiwi.infinispan.util.AsyncMap; import org.apache.marmotta.kiwi.model.rdf.*; import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.configuration.Configuration; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; +import org.infinispan.commons.CacheException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Map; @@ -33,6 +37,8 @@ import java.util.Map; */ public class InfinispanRemoteCacheManager implements CacheManager { + private static Logger log = LoggerFactory.getLogger(InfinispanRemoteCacheManager.class); + private KiWiConfiguration configuration; private RemoteCacheManager cacheManager; @@ -44,11 +50,15 @@ public class InfinispanRemoteCacheManager implements CacheManager { this.configuration = configuration; Configuration remoteCfg = new ConfigurationBuilder() - .addServers(configuration.getClusterAddress()) + .addServer() + .host(configuration.getClusterAddress()) + .port(configuration.getClusterPort()) .marshaller(new CustomJBossMarshaller()) .build(); cacheManager = new RemoteCacheManager(remoteCfg); + + log.info("initialised Infinispan remote cache manager (servers: {})", configuration.getClusterAddress()); } @@ -60,7 +70,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<Long, KiWiNode> getNodeCache() { - return null; + if(nodeCache == null) { + nodeCache = new AsyncMap(cacheManager.getCache(NODE_CACHE)); + } + return nodeCache; } /** @@ -71,7 +84,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<Long, KiWiTriple> getTripleCache() { - return null; + if(tripleCache == null) { + tripleCache = new AsyncMap(cacheManager.getCache(TRIPLE_CACHE)); + } + return tripleCache; } /** @@ -82,7 +98,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<String, KiWiUriResource> getUriCache() { - return null; + if(uriCache == null) { + uriCache = new AsyncMap(cacheManager.getCache(URI_CACHE)); + } + return uriCache; } /** @@ -93,7 +112,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<String, KiWiAnonResource> getBNodeCache() { - return null; + if(bnodeCache == null) { + bnodeCache = new AsyncMap(cacheManager.getCache(BNODE_CACHE)); + } + return bnodeCache; } /** @@ -105,7 +127,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<String, KiWiLiteral> getLiteralCache() { - return null; + if(literalCache == null) { + literalCache = new AsyncMap(cacheManager.getCache(LITERAL_CACHE)); + } + return literalCache; } /** @@ -115,7 +140,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<String, KiWiNamespace> getNamespaceUriCache() { - return null; + if(nsUriCache == null) { + nsUriCache = new AsyncMap(cacheManager.getCache(NS_URI_CACHE)); + } + return nsUriCache; } /** @@ -125,7 +153,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<String, KiWiNamespace> getNamespacePrefixCache() { - return null; + if(nsPrefixCache == null) { + nsPrefixCache = new AsyncMap(cacheManager.getCache(NS_PREFIX_CACHE)); + } + return nsPrefixCache; } /** @@ -136,7 +167,10 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map<Long, Long> getRegistryCache() { - return null; + if(registryCache == null) { + registryCache = cacheManager.getCache(REGISTRY_CACHE); + } + return registryCache; } /** @@ -148,7 +182,7 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public Map getCacheByName(String name) { - return null; + return cacheManager.getCache(name); } /** @@ -164,6 +198,11 @@ public class InfinispanRemoteCacheManager implements CacheManager { */ @Override public void shutdown() { - + try { + log.info("shutting down cache manager ..."); + cacheManager.stop(); + } catch (CacheException ex) { + log.warn("error shutting down cache: {}", ex.getMessage()); + } } } http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java new file mode 100644 index 0000000..630f64e --- /dev/null +++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java @@ -0,0 +1,158 @@ +/* + * 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.marmotta.kiwi.test; + +import org.apache.marmotta.commons.vocabulary.XSD; +import org.apache.marmotta.kiwi.caching.CacheManager; +import org.apache.marmotta.kiwi.config.CacheManagerType; +import org.apache.marmotta.kiwi.config.KiWiConfiguration; +import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager; +import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller; +import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest; +import org.infinispan.client.hotrod.RemoteCache; +import org.infinispan.client.hotrod.RemoteCacheManager; +import org.infinispan.configuration.cache.CacheMode; +import org.infinispan.configuration.cache.Configuration; +import org.infinispan.configuration.cache.ConfigurationBuilder; +import org.infinispan.configuration.global.GlobalConfiguration; +import org.infinispan.configuration.global.GlobalConfigurationBuilder; +import org.infinispan.eviction.EvictionStrategy; +import org.infinispan.manager.DefaultCacheManager; +import org.infinispan.manager.EmbeddedCacheManager; +import org.infinispan.server.hotrod.HotRodServer; +import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration; +import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +/** + * Add file description here! + * + * @author Sebastian Schaffert ([email protected]) + */ +public class RemoteClusterTest extends BaseClusterTest { + + private static Logger log = LoggerFactory.getLogger(RemoteClusterTest.class); + + private static HotRodServer hotRodServer1, hotRodServer2, hotRodServer3; + + @BeforeClass + public static void setup() { + hotRodServer1 = buildServer(61222); + hotRodServer2 = buildServer(61223); + hotRodServer3 = buildServer(61224); + + ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD); + + KiWiConfiguration base = s.buildBaseConfiguration(); + base.setClusterAddress("127.0.0.1"); + s.setup(base); + } + + + + private static HotRodServer buildServer(int port) { + HotRodServer hotRodServer = new HotRodServer() { + @Override + public ConfigurationBuilder createTopologyCacheConfig(long distSyncTimeout) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + + ConfigurationBuilder c = super.createTopologyCacheConfig(distSyncTimeout); + c.transaction().syncCommitPhase(false).syncRollbackPhase(false); + return c; + } + }; + + HotRodServerConfiguration hotrodConfig = new HotRodServerConfigurationBuilder() + .host("127.0.0.1") + .port(port) + .proxyHost("127.0.0.1") + .proxyPort(port) + .topologyStateTransfer(false) + .workerThreads(2) + .build(true); + + + GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder() + .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader()) + .globalJmxStatistics() + .jmxDomain("org.apache.marmotta.kiwi") + .allowDuplicateDomains(true) + .build(); + + Configuration defaultConfiguration = new ConfigurationBuilder() + .clustering() + .cacheMode(CacheMode.LOCAL) + .eviction() + .strategy(EvictionStrategy.LIRS) + .maxEntries(100000) + .expiration() + .lifespan(5, TimeUnit.MINUTES) + .maxIdle(1, TimeUnit.MINUTES) + .build(); + + EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true); + cacheManager.defineConfiguration(CacheManager.NODE_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.TRIPLE_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.URI_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.BNODE_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.LITERAL_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.NS_PREFIX_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.NS_URI_CACHE, defaultConfiguration); + cacheManager.defineConfiguration(CacheManager.REGISTRY_CACHE, defaultConfiguration); + cacheManager.getCache(CacheManager.NODE_CACHE, true); + cacheManager.getCache(CacheManager.TRIPLE_CACHE, true); + cacheManager.getCache(CacheManager.URI_CACHE, true); + cacheManager.getCache(CacheManager.BNODE_CACHE, true); + cacheManager.getCache(CacheManager.LITERAL_CACHE, true); + cacheManager.getCache(CacheManager.NS_PREFIX_CACHE, true); + cacheManager.getCache(CacheManager.NS_URI_CACHE, true); + cacheManager.getCache(CacheManager.REGISTRY_CACHE,true); + + hotRodServer.start(hotrodConfig, cacheManager); + + // test if cache is available + org.infinispan.client.hotrod.configuration.Configuration remoteCfg = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder() + .addServer() + .host("127.0.0.1") + .port(port) + .marshaller(new CustomJBossMarshaller()) + .pingOnStartup(true) + .build(true); + + + RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteCfg); + Assert.assertTrue(remoteCacheManager.isStarted()); + + RemoteCache<String, String> m = remoteCacheManager.getCache(); + + m.put(XSD.AnyURI.stringValue(), XSD.AnyURI.stringValue()); + String n = m.get(XSD.AnyURI.stringValue()); + + Assert.assertNotNull(n); + + return hotRodServer; + } +} http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java index 12a57b0..d2e12ef 100644 --- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java +++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java @@ -44,7 +44,7 @@ public abstract class BaseClusterTest { private static int datacenterIds = 1; - private static Repository repositorySync1, repositorySync2, repositoryAsync1, repositoryAsync2; + protected static Repository repositorySync1, repositorySync2, repositoryAsync1, repositoryAsync2; private static CacheManager cacheManagerSync1, cacheManagerSync2, cacheManagerAsync1, cacheManagerAsync2; @@ -133,11 +133,15 @@ public abstract class BaseClusterTest { } public void setup() { + setup(null); + } + + public void setup(KiWiConfiguration base) { try { - repositorySync1 = createConfiguration(61222); - repositorySync2 = createConfiguration(61222); - repositoryAsync1 = createConfiguration(61223); - repositoryAsync2 = createConfiguration(61224); + repositorySync1 = createConfiguration(base,61222); + repositorySync2 = createConfiguration(base,61222); + repositoryAsync1 = createConfiguration(base,61223); + repositoryAsync2 = createConfiguration(base,61224); cacheManagerSync1 = getCacheManager(repositorySync1); cacheManagerSync2 = getCacheManager(repositorySync2); @@ -150,13 +154,22 @@ public abstract class BaseClusterTest { } } - - private Repository createConfiguration(int port) throws RepositoryException { - KiWiConfiguration config = new KiWiConfiguration( + public KiWiConfiguration buildBaseConfiguration() { + return new KiWiConfiguration( "default-H2", "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1", "kiwi", "kiwi", new H2Dialect()); + } + + private Repository createConfiguration(KiWiConfiguration base, int port) throws RepositoryException { + KiWiConfiguration config; + + if(base != null) { + config = base; + } else { + config = buildBaseConfiguration(); + } config.setDatacenterId(datacenterIds++); config.setClustered(true); config.setCacheManager(type); http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 2190cbe..8abc2b2 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1045,6 +1045,11 @@ </dependency> <dependency> <groupId>org.infinispan</groupId> + <artifactId>infinispan-server-hotrod</artifactId> + <version>6.0.1.Final</version> + </dependency> + <dependency> + <groupId>org.infinispan</groupId> <artifactId>infinispan-cdi</artifactId> <version>6.0.1.Final</version> </dependency>
