You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/03/05 13:24:33 UTC
[18/21] git commit: added repository tests to other cache
implementations
added repository tests to other cache implementations
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d04230ab
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d04230ab
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d04230ab
Branch: refs/heads/MARMOTTA-450
Commit: d04230ab9b7fac0027743f4d1b70521d244487b7
Parents: b25a254
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 22:03:09 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 22:03:09 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching-hazelcast/pom.xml | 5 +
.../caching/HazelcastCacheManager.java | 22 +-
.../hazelcast/serializer/BNodeSerializer.java | 15 +-
.../HazelcastRepositoryConnectionTest.java | 66 +++++
.../test/cluster/HazelcastRepositoryTest.java | 64 +++++
libraries/kiwi/kiwi-caching-infinispan/pom.xml | 5 +
.../externalizer/BNodeExternalizer.java | 13 +-
.../marmotta/kiwi/test/EmbeddedClusterTest.java | 37 ---
.../marmotta/kiwi/test/ExternalizerTest.java | 241 ------------------
.../marmotta/kiwi/test/RemoteClusterTest.java | 156 ------------
.../kiwi/test/embedded/EmbeddedClusterTest.java | 37 +++
.../EmbeddedRepositoryConnectionTest.java | 66 +++++
.../test/embedded/EmbeddedRepositoryTest.java | 64 +++++
.../test/externalizer/ExternalizerTest.java | 254 +++++++++++++++++++
.../kiwi/test/remote/HotRodClusterTest.java | 57 +++++
.../kiwi/test/remote/HotRodPersistenceTest.java | 42 +++
.../remote/HotRodRepositoryConnectionTest.java | 72 ++++++
.../kiwi/test/remote/HotRodRepositoryTest.java | 70 +++++
.../kiwi/test/remote/HotRodServerRule.java | 178 +++++++++++++
.../marmotta/kiwi/test/PersistenceTest.java | 52 ++--
.../kiwi/test/cluster/BaseClusterTest.java | 43 +++-
21 files changed, 1068 insertions(+), 491 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
index b1f406a..4d82fbd 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
+++ b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
@@ -107,6 +107,11 @@
<artifactId>sesame-rio-rdfxml</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-store-testsuite</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
index b2b03a8..db4ee50 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -63,9 +63,13 @@ public class HazelcastCacheManager implements CacheManager {
this.configuration = configuration;
hcConfiguration = new Config();
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
+ if(configuration.isClustered()) {
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
+ } else {
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
+ }
hcConfiguration.getGroupConfig().setName(configuration.getClusterName());
@@ -76,12 +80,16 @@ public class HazelcastCacheManager implements CacheManager {
hazelcast = Hazelcast.newHazelcastInstance(hcConfiguration);
+ if(configuration.isClustered()) {
+ log.info("initialised Hazelcast local cache manager");
+ } else {
+ log.info("initialised Hazelcast distributed cache manager (cluster name: {})", configuration.getClusterName());
- log.info("initialised Hazelcast distributed cache manager (cluster name: {})", configuration.getClusterName());
-
- if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
- log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
+ if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
+ log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
+ }
}
+
}
private void setupSerializers() {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
index 4462537..e105b39 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
@@ -20,6 +20,7 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import java.io.IOException;
@@ -42,24 +43,18 @@ public class BNodeSerializer implements StreamSerializer<KiWiAnonResource> {
@Override
public void write(ObjectDataOutput output, KiWiAnonResource object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
+ DataIO.writeString(output, object.stringValue());
output.writeLong(object.getCreated().getTime());
}
@Override
public KiWiAnonResource read(ObjectDataInput input) throws IOException {
- long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
+ long id = input.readLong();
+ String anonId = DataIO.readString(input);
Date created = new Date(input.readLong());
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ KiWiAnonResource r = new KiWiAnonResource(anonId,created);
r.setId(id);
return r;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
new file mode 100644
index 0000000..ef75821
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.cluster;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HazelcastRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final KiWiConfiguration config;
+
+ public HazelcastRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(false);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.DISTRIBUTED);
+ config.setCacheManager(CacheManagerType.HAZELCAST);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
new file mode 100644
index 0000000..3b080ef
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.cluster;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HazelcastRepositoryTest extends RepositoryTest {
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public HazelcastRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.DISTRIBUTED);
+ config.setCacheManager(CacheManagerType.HAZELCAST);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/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 5bd3416..0a919b6 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/pom.xml
+++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
@@ -117,6 +117,11 @@
<artifactId>infinispan-server-hotrod</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-store-testsuite</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
index 4bcaf40..e9ad806 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
@@ -17,6 +17,7 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
@@ -48,24 +49,18 @@ public class BNodeExternalizer extends BaseExternalizer<KiWiAnonResource> implem
@Override
public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
+ DataIO.writeString(output, object.stringValue());
output.writeLong(object.getCreated().getTime());
}
@Override
public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
+ String anonId = DataIO.readString(input);
Date created = new Date(input.readLong());
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ KiWiAnonResource r = new KiWiAnonResource(anonId,created);
r.setId(id);
return r;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
deleted file mode 100644
index 17bc3cf..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.kiwi.config.CacheManagerType;
-import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
-import org.junit.BeforeClass;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class EmbeddedClusterTest extends BaseClusterTest {
-
-
- @BeforeClass
- public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
- s.setup();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
deleted file mode 100644
index 94121f3..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * 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.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.commons.vocabulary.XSD;
-import org.apache.marmotta.kiwi.infinispan.externalizer.*;
-import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
-import org.apache.marmotta.kiwi.model.rdf.*;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.marshall.StreamingMarshaller;
-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.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.vocabulary.OWL;
-import org.openrdf.model.vocabulary.RDFS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.Random;
-
-/**
- * Test the different externalizer implementations we provide for Infinispan
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerTest {
-
- private static ValueFactory valueFactory = new TestValueFactory();
-
- private static Random rnd = new Random();
-
- private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
-
- private static StreamingMarshaller marshaller, hotrod;
-
-
- @BeforeClass
- public static void setup() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer(),
- new TripleExternalizer()
- };
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- Configuration defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .build();
-
- EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
-
- hotrod = new CustomJBossMarshaller();
- }
-
-
- @Test
- public void testUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
- }
-
- @Test
- public void testCompressedUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriExternalizer());
- marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriExternalizer());
- marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriExternalizer());
- }
-
-
- @Test
- public void testBNode() throws Exception {
- marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
- }
-
- @Test
- public void testStringLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
- }
-
- @Test
- public void testLangLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
- }
-
- @Test
- public void testTypeLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
- }
-
-
- @Test
- public void testIntLiteral() throws Exception {
- marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
- }
-
-
- @Test
- public void testTriple() throws Exception {
- KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiNode o = (KiWiNode) randomNode();
- KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
-
- marshall(t, new TripleExternalizer());
- }
-
- @Test
- public void testPrefixCompressedTriple() throws Exception {
- KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
-
- marshall(t, new TripleExternalizer());
- }
-
-
- /**
- * Run the given object through the marshaller using an in-memory stream.
- * @param origin
- * @param <T>
- * @return
- */
- private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
- log.info("- testing Java ObjectStream ...");
- ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
- ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
-
- outOS.writeObject(origin);
-
- outOS.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
-
-
- log.info("- testing externalizer directly ...");
- ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(outBytes);
-
- externalizer.writeObject(out, origin);
- out.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
-
- ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
- ObjectInputStream in = new ObjectInputStream(inBytes);
-
- T destination1 = externalizer.readObject(in);
-
- Assert.assertEquals(origin,destination1);
-
- log.info("- testing externalizer with infinispan cluster marshaller ...");
-
- byte[] bytes = marshaller.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytes.length);
-
- Object destination2 = marshaller.objectFromByteBuffer(bytes);
-
- Assert.assertEquals(origin, destination2);
-
-
-
- log.info("- testing externalizer with infinispan hotrod marshaller ...");
-
- byte[] bytesH = hotrod.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytesH.length);
-
- Object destination3 = hotrod.objectFromByteBuffer(bytesH);
-
- Assert.assertEquals(origin, destination3);
-
- }
-
-
- /**
- * Return a random RDF value, either a reused object (10% chance) or of any other kind.
- * @return
- */
- protected Value randomNode() {
- Value object;
- switch(rnd.nextInt(6)) {
- case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
- case 1: object = valueFactory.createBNode();
- break;
- case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
- break;
- case 3: object = valueFactory.createLiteral(rnd.nextInt());
- break;
- case 4: object = valueFactory.createLiteral(rnd.nextDouble());
- break;
- case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
- break;
- default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
-
- }
- return object;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/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
deleted file mode 100644
index 4295c28..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * 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.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.commons.api.BasicCacheContainer;
-import org.infinispan.commons.equivalence.ByteArrayEquivalence;
-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.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;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-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)
- .defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
- .idleTimeout(0)
- .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)
- .sync()
- .dataContainer()
- .keyEquivalence(ByteArrayEquivalence.INSTANCE)
- .valueEquivalence(ByteArrayEquivalence.INSTANCE)
- .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("xyz", "abc");
- String n = m.get("xyz");
-
- Assert.assertNotNull(n);
-
- return hotRodServer;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
new file mode 100644
index 0000000..7405e0f
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EmbeddedClusterTest extends BaseClusterTest {
+
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
+ s.setup();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
new file mode 100644
index 0000000..676e90b
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class EmbeddedRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final KiWiConfiguration config;
+
+ public EmbeddedRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.LOCAL);
+ config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
new file mode 100644
index 0000000..7094893
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class EmbeddedRepositoryTest extends RepositoryTest {
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public EmbeddedRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.LOCAL);
+ config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
new file mode 100644
index 0000000..7b6bb85
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
@@ -0,0 +1,254 @@
+/*
+ * 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.externalizer;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.test.TestValueFactory;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.marshall.StreamingMarshaller;
+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.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.vocabulary.OWL;
+import org.openrdf.model.vocabulary.RDFS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerTest {
+
+ private static ValueFactory valueFactory = new TestValueFactory();
+
+ private static Random rnd = new Random();
+
+ private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
+
+ private static StreamingMarshaller marshaller, hotrod;
+
+
+ @BeforeClass
+ public static void setup() {
+ AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer(),
+ new TripleExternalizer()
+ };
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .transport()
+ .defaultTransport()
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+
+ hotrod = new CustomJBossMarshaller();
+ }
+
+
+ @Test
+ public void testUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
+ }
+
+ @Test
+ public void testCompressedUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriExternalizer());
+ }
+
+
+ @Test
+ public void testBNode() throws Exception {
+ marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
+ }
+
+ @Test
+ public void testStringLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testLangLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testTypeLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testIntLiteral() throws Exception {
+ marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiNode o = (KiWiNode) randomNode();
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+ @Test
+ public void testPrefixCompressedTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+
+ /**
+ * Run the given object through the marshaller using an in-memory stream.
+ * @param origin
+ * @param <T>
+ * @return
+ */
+ private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing Java ObjectStream ...");
+ ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
+ ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
+
+ outOS.writeObject(origin);
+
+ outOS.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
+
+
+ log.info("- testing externalizer directly ...");
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(outBytes);
+
+ externalizer.writeObject(out, origin);
+ out.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
+
+ ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(inBytes);
+
+ T destination1 = externalizer.readObject(in);
+
+ Assert.assertEquals(origin,destination1);
+ assertEqualsId(origin,destination1);
+
+ log.info("- testing externalizer with infinispan cluster marshaller ...");
+
+ byte[] bytes = marshaller.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytes.length);
+
+ Object destination2 = marshaller.objectFromByteBuffer(bytes);
+
+ Assert.assertEquals(origin, destination2);
+ assertEqualsId(origin, destination2);
+
+
+
+ log.info("- testing externalizer with infinispan hotrod marshaller ...");
+
+ byte[] bytesH = hotrod.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytesH.length);
+
+ Object destination3 = hotrod.objectFromByteBuffer(bytesH);
+
+ Assert.assertEquals(origin, destination3);
+ assertEqualsId(origin, destination3);
+
+ }
+
+
+ /**
+ * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+ * @return
+ */
+ protected Value randomNode() {
+ Value object;
+ switch(rnd.nextInt(6)) {
+ case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+ case 1: object = valueFactory.createBNode();
+ break;
+ case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+ break;
+ case 3: object = valueFactory.createLiteral(rnd.nextInt());
+ break;
+ case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+ break;
+ case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+ break;
+ default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+
+ }
+ return object;
+ }
+
+ private static <T> void assertEqualsId(T o1, T o2) {
+ if(o1 instanceof KiWiNode && o2 instanceof KiWiNode) {
+ Assert.assertEquals(((KiWiNode) o1).getId(), ((KiWiNode) o2).getId());
+ } else if(o1 instanceof KiWiTriple && o2 instanceof KiWiTriple) {
+ Assert.assertEquals(((KiWiTriple) o1).getId(), ((KiWiTriple) o2).getId());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
new file mode 100644
index 0000000..3f4fa2a
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodClusterTest extends BaseClusterTest {
+
+ private static Logger log = LoggerFactory.getLogger(HotRodClusterTest.class);
+
+
+ @ClassRule
+ public static HotRodServerRule hotrod1 = new HotRodServerRule(61222);
+
+ @ClassRule
+ public static HotRodServerRule hotrod2 = new HotRodServerRule(61223);
+
+ @ClassRule
+ public static HotRodServerRule hotrod3 = new HotRodServerRule(61224);
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD);
+
+ KiWiConfiguration base = s.buildBaseConfiguration();
+ base.setClusterAddress("127.0.0.1");
+ s.setup(base);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
new file mode 100644
index 0000000..406fa9c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.test.PersistenceTest;
+import org.junit.ClassRule;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodPersistenceTest extends PersistenceTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ public HotRodPersistenceTest(KiWiConfiguration kiwiConfig) {
+ super(kiwiConfig);
+
+ kiwiConfig.setClusterAddress("127.0.0.1");
+ kiwiConfig.setClusterPort(61222);
+ kiwiConfig.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
new file mode 100644
index 0000000..198c44c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HotRodRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ private final KiWiConfiguration config;
+
+ public HotRodRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClusterAddress("127.0.0.1");
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ hotrod.clearAll();
+
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
new file mode 100644
index 0000000..6d1cc2f
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HotRodRepositoryTest extends RepositoryTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public HotRodRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+
+ config.setClusterAddress("127.0.0.1");
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
new file mode 100644
index 0000000..0bef0ee
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
@@ -0,0 +1,178 @@
+/*
+ * 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.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
+import org.infinispan.Cache;
+import org.infinispan.client.hotrod.RemoteCache;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.commons.api.BasicCacheContainer;
+import org.infinispan.commons.equivalence.ByteArrayEquivalence;
+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.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.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodServerRule implements TestRule {
+
+ HotRodServer server;
+
+ int port;
+
+ public HotRodServerRule(int port) {
+ this.port = port;
+ }
+
+
+ /**
+ * Modifies the method-running {@link org.junit.runners.model.Statement} to implement this
+ * test-running rule.
+ *
+ * @param base The {@link org.junit.runners.model.Statement} to be modified
+ * @param description A {@link org.junit.runner.Description} of the test implemented in {@code base}
+ * @return a new statement, which may be the same as {@code base},
+ * a wrapper around {@code base}, or a completely new Statement.
+ */
+ @Override
+ public Statement apply(final Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ server = buildServer(port);
+
+ try {
+ base.evaluate();
+ } finally {
+ server.stop();
+ }
+ }
+ };
+ }
+
+
+ public void clearAll() {
+ for(String s : server.getCacheManager().getCacheNames()) {
+ Cache c = server.getCacheManager().getCache(s);
+ c.clear();
+ }
+ }
+
+ 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)
+ .defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
+ .idleTimeout(0)
+ .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)
+ .sync()
+ .dataContainer()
+ .keyEquivalence(ByteArrayEquivalence.INSTANCE)
+ .valueEquivalence(ByteArrayEquivalence.INSTANCE)
+ .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("xyz", "abc");
+ String n = m.get("xyz");
+
+ Assert.assertNotNull(n);
+
+ return hotRodServer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
index 9eff945..a3aa52a 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -113,7 +113,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri1);
- //Assert.assertTrue(uri == testUri1);
+ Assert.assertEquals(uri.getId(), testUri1.getId());
connection.commit();
@@ -121,14 +121,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri2);
- //Assert.assertTrue(uri == testUri2);
+ Assert.assertEquals(uri.getId(), testUri2.getId());
KiWiNode testUri3 = connection.loadUriResource(uri.stringValue());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri3);
- //Assert.assertTrue(uri == testUri3);
+ Assert.assertEquals(uri.getId(), testUri3.getId());
connection.commit();
@@ -142,13 +142,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(uri,testUri4);
- //Assert.assertTrue(uri != testUri4);
+ Assert.assertEquals(uri.getId(), testUri4.getId());
KiWiNode testUri5 = connection.loadUriResource(uri.stringValue());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(uri,testUri5);
- //Assert.assertTrue(uri != testUri5);
+ Assert.assertEquals(uri.getId(), testUri5.getId());
connection.commit();
@@ -157,7 +157,7 @@ public class PersistenceTest {
ResultSet result = checkNodeStmt.executeQuery();
Assert.assertTrue(result.next());
- Assert.assertEquals((long) uri.getId(), result.getLong("id"));
+ Assert.assertEquals(uri.getId(), result.getLong("id"));
Assert.assertEquals(uri.stringValue(),result.getString("svalue"));
Assert.assertEquals("uri",result.getString("ntype"));
@@ -190,7 +190,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode1);
- //Assert.assertTrue(bnode == testBNode1);
+ Assert.assertEquals(bnode.getId(), testBNode1.getId());
connection.commit();
@@ -198,14 +198,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode2);
- //Assert.assertTrue(bnode == testBNode2);
+ Assert.assertEquals(bnode.getId(), testBNode2.getId());
KiWiNode testBNode3 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode3);
- //Assert.assertTrue(bnode == testBNode3);
+ Assert.assertEquals(bnode.getId(), testBNode3.getId());
connection.commit();
@@ -218,13 +218,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode4);
- //Assert.assertTrue(bnode != testBNode4);
+ Assert.assertEquals(bnode.getId(), testBNode4.getId());
KiWiNode testBNode5 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode5);
- //Assert.assertTrue(bnode != testBNode5);
+ Assert.assertEquals(bnode.getId(), testBNode5.getId());
connection.commit();
@@ -269,7 +269,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -277,13 +277,13 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(), null, stype);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -294,13 +294,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,stype);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();
@@ -348,7 +348,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -356,13 +356,13 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -373,13 +373,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();
@@ -427,7 +427,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -436,14 +436,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -455,14 +455,14 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();