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/17 11:22:54 UTC
[03/32] started working on cleaner cache API for KiWi
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
deleted file mode 100644
index 9e57267..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
+++ /dev/null
@@ -1,188 +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.externalizer;
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.kiwi.caching.*;
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-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.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;
-
-
- @BeforeClass
- public static void setup() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer()
- };
-
-
- 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();
-
- }
-
-
- @Test
- public void testUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), 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());
- }
-
-
- /**
- * 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 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 marshaller ...");
-
- byte[] bytes = marshaller.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytes.length);
-
- Object destination2 = marshaller.objectFromByteBuffer(bytes);
-
- Assert.assertEquals(origin, destination2);
-
- }
-
-
- /**
- * 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/c6d0cc13/libraries/kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/pom.xml b/libraries/kiwi/pom.xml
index 9e7aa42..c244567 100644
--- a/libraries/kiwi/pom.xml
+++ b/libraries/kiwi/pom.xml
@@ -111,6 +111,8 @@
<modules>
<module>kiwi-triplestore</module>
+ <module>kiwi-caching-infinispan</module>
+ <module>kiwi-caching-hazelcast</module>
<module>kiwi-versioning</module>
<module>kiwi-reasoner</module>
<module>kiwi-sparql</module>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 4c03406..f2c11d6 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1049,6 +1049,14 @@
<version>6.0.1.Final</version>
</dependency>
+
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+
+
<!-- use stable versions for some dependencies -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>