http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java new file mode 100644 index 0000000..abc23e9 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java @@ -0,0 +1,135 @@ +//package mvm.rya.api.query.strategy.wholerow; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +// +//import junit.framework.TestCase; +//import mvm.rya.api.RdfCloudTripleStoreConstants; +//import mvm.rya.api.domain.*; +//import mvm.rya.api.resolver.RyaContext; +//import mvm.rya.api.resolver.triple.TripleRow; +//import org.apache.accumulo.core.data.Key; +//import org.apache.accumulo.core.data.Range; +//import org.apache.hadoop.io.Text; +//import org.openrdf.model.impl.URIImpl; +// +//import java.util.Map; +// +///** +// * Date: 7/14/12 +// * Time: 11:46 AM +// */ +//public class OspWholeRowTriplePatternStrategyTest extends TestCase { +// RyaURI uri = new RyaURI("urn:test#1234"); +// RyaURI uri2 = new RyaURI("urn:test#1235"); +// RyaURIRange rangeURI = new RyaURIRange(uri, uri2); +// RyaURIRange rangeURI2 = new RyaURIRange(new RyaURI("urn:test#1235"), new RyaURI("urn:test#1236")); +// +// RyaType customType1 = new RyaType(new URIImpl("urn:custom#type"), "1234"); +// RyaType customType2 = new RyaType(new URIImpl("urn:custom#type"), "1235"); +// RyaType customType3 = new RyaType(new URIImpl("urn:custom#type"), "1236"); +// RyaTypeRange customTypeRange1 = new RyaTypeRange(customType1, customType2); +// RyaTypeRange customTypeRange2 = new RyaTypeRange(customType2, customType3); +// +// OspWholeRowTriplePatternStrategy strategy = new OspWholeRowTriplePatternStrategy(); +// RyaContext ryaContext = RyaContext.getInstance(); +// +// public void testO() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP); +// Key key = new Key(new Text(tripleRow.getRow())); +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, null, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, null, uri2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testORange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, null, rangeURI, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, null, rangeURI2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testOs() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, null, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri2, null, uri, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testOsRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(rangeURI, null, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(rangeURI2, null, uri, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testOsRangeCustomType() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, customType1, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(rangeURI, null, customType1, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(rangeURI2, null, customType2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testHandles() throws Exception { +// //os(ng) +// assertTrue(strategy.handles(uri, null, uri, null)); +// assertTrue(strategy.handles(uri, null, uri, uri)); +// //o_r(s)(ng) +// assertTrue(strategy.handles(rangeURI, null, uri, null)); +// assertTrue(strategy.handles(rangeURI, null, uri, uri)); +// //o(ng) +// assertTrue(strategy.handles(null, null, uri, null)); +// assertTrue(strategy.handles(null, null, uri, uri)); +// //r(o) +// assertTrue(strategy.handles(null, null, rangeURI, null)); +// assertTrue(strategy.handles(null, null, rangeURI, uri)); +// +// //false +// assertFalse(strategy.handles(uri, null, rangeURI, null)); +// } +//}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategyTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategyTest.java new file mode 100644 index 0000000..50546e4 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/PoWholeRowTriplePatternStrategyTest.java @@ -0,0 +1,159 @@ +//package mvm.rya.api.query.strategy.wholerow; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +// +//import junit.framework.TestCase; +//import mvm.rya.api.RdfCloudTripleStoreConstants; +//import mvm.rya.api.domain.*; +//import mvm.rya.api.resolver.RyaContext; +//import mvm.rya.api.resolver.triple.TripleRow; +//import org.apache.accumulo.core.data.Key; +//import org.apache.accumulo.core.data.Range; +//import org.apache.hadoop.io.Text; +//import org.openrdf.model.impl.URIImpl; +// +//import java.util.Map; +// +///** +// * Date: 7/14/12 +// * Time: 11:46 AM +// */ +//public class PoWholeRowTriplePatternStrategyTest extends TestCase { +// +// RyaURI uri = new RyaURI("urn:test#1234"); +// RyaURI uri2 = new RyaURI("urn:test#1235"); +// RyaURIRange rangeURI = new RyaURIRange(uri, uri2); +// RyaURIRange rangeURI2 = new RyaURIRange(new RyaURI("urn:test#1235"), new RyaURI("urn:test#1236")); +// PoWholeRowTriplePatternStrategy strategy = new PoWholeRowTriplePatternStrategy(); +// RyaContext ryaContext = RyaContext.getInstance(); +// +// RyaType customType1 = new RyaType(new URIImpl("urn:custom#type"), "1234"); +// RyaType customType2 = new RyaType(new URIImpl("urn:custom#type"), "1235"); +// RyaType customType3 = new RyaType(new URIImpl("urn:custom#type"), "1236"); +// RyaTypeRange customTypeRange1 = new RyaTypeRange(customType1, customType2); +// RyaTypeRange customTypeRange2 = new RyaTypeRange(customType2, customType3); +// +// public void testPoRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, uri, rangeURI, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, uri, rangeURI2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testPoRangeCustomType() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, customType1, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, uri, customTypeRange1, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, uri, customTypeRange2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testPo() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, uri, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, uri, uri2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testPoCustomType() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, customType1, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, uri, customType1, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(null, uri, customType2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testPosRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(rangeURI, uri, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(rangeURI2, uri, uri, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testPRange() throws Exception { +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, rangeURI, null, null, null); +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple(new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// assertTrue(entry.getValue().contains(key)); +// } +// +// public void testP() throws Exception { +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(null, uri, null, null, null); +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO); +// Key key = new Key(new Text(tripleRow.getRow())); +// assertTrue(entry.getValue().contains(key)); +// } +// +// public void testHandles() throws Exception { +// //po(ng) +// assertTrue(strategy.handles(null, uri, uri, null)); +// assertTrue(strategy.handles(null, uri, uri, uri)); +// //po_r(s)(ng) +// assertTrue(strategy.handles(rangeURI, uri, uri, null)); +// assertTrue(strategy.handles(rangeURI, uri, uri, uri)); +// //p(ng) +// assertTrue(strategy.handles(null, uri, null, null)); +// assertTrue(strategy.handles(null, uri, null, uri)); +// //p_r(o)(ng) +// assertTrue(strategy.handles(null, uri, rangeURI, null)); +// assertTrue(strategy.handles(null, uri, rangeURI, uri)); +// //r(p)(ng) +// assertTrue(strategy.handles(null, rangeURI, null, null)); +// assertTrue(strategy.handles(null, rangeURI, null, uri)); +// +// //false cases +// //sp.. +// assertFalse(strategy.handles(uri, uri, null, null)); +// //r(s)_p +// assertFalse(strategy.handles(rangeURI, uri, null, null)); +// } +//} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategyTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategyTest.java new file mode 100644 index 0000000..280b532 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/query/strategy/wholerow/SpoWholeRowTriplePatternStrategyTest.java @@ -0,0 +1,185 @@ +//package mvm.rya.api.query.strategy.wholerow; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +// +//import junit.framework.TestCase; +//import mvm.rya.api.RdfCloudTripleStoreConstants; +//import mvm.rya.api.domain.*; +//import mvm.rya.api.resolver.RyaContext; +//import mvm.rya.api.resolver.triple.TripleRow; +//import org.apache.accumulo.core.data.Key; +//import org.apache.accumulo.core.data.Range; +//import org.apache.hadoop.io.Text; +//import org.openrdf.model.impl.URIImpl; +// +//import java.util.Map; +// +///** +// * Date: 7/14/12 +// * Time: 7:47 AM +// */ +//public class SpoWholeRowTriplePatternStrategyTest extends TestCase { +// +// RyaURI uri = new RyaURI("urn:test#1234"); +// RyaURI uri2 = new RyaURI("urn:test#1235"); +// RyaURIRange rangeURI = new RyaURIRange(uri, uri2); +// RyaURIRange rangeURI2 = new RyaURIRange(new RyaURI("urn:test#1235"), new RyaURI("urn:test#1236")); +// SpoWholeRowTriplePatternStrategy strategy = new SpoWholeRowTriplePatternStrategy(); +// RyaContext ryaContext = RyaContext.getInstance(); +// +// RyaType customType1 = new RyaType(new URIImpl("urn:custom#type"), "1234"); +// RyaType customType2 = new RyaType(new URIImpl("urn:custom#type"), "1235"); +// RyaType customType3 = new RyaType(new URIImpl("urn:custom#type"), "1236"); +// RyaTypeRange customTypeRange1 = new RyaTypeRange(customType1, customType2); +// RyaTypeRange customTypeRange2 = new RyaTypeRange(customType2, customType3); +// +// public void testSpo() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, uri, uri, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri, uri, uri2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSpoCustomType() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, customType1, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, uri, customType1, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri, uri, customType2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSpoRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, uri, rangeURI, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri, uri, rangeURI2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSpoRangeCustomType() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, customType1, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, uri, customTypeRange1, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri, uri, customTypeRange2, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSp() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, uri, null, null, null); +// assertTrue(entry.getValue().contains(key)); +// entry = strategy.defineRange(uri, uri2, null, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSpRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, rangeURI, null, null, null); +// assertTrue(entry.getValue().contains(key)); +// entry = strategy.defineRange(uri, rangeURI2, null, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testS() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(uri, null, null, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(uri2, null, null, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testSRange() throws Exception { +// Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaContext.serializeTriple( +// new RyaStatement(uri, uri, uri, null)); +// TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); +// Key key = new Key(new Text(tripleRow.getRow())); +// +// Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range> entry = strategy.defineRange(rangeURI, null, null, null, null); +// assertTrue(entry.getValue().contains(key)); +// +// entry = strategy.defineRange(rangeURI2, null, null, null, null); +// assertFalse(entry.getValue().contains(key)); +// } +// +// public void testHandles() throws Exception { +// //spo(ng) +// assertTrue(strategy.handles(uri, uri, uri, null)); +// assertTrue(strategy.handles(uri, uri, uri, uri)); +// //sp(ng) +// assertTrue(strategy.handles(uri, uri, null, null)); +// assertTrue(strategy.handles(uri, uri, null, uri)); +// //s(ng) +// assertTrue(strategy.handles(uri, null, null, null)); +// assertTrue(strategy.handles(uri, null, null, uri)); +// //sp_r(o)(ng) +// assertTrue(strategy.handles(uri, uri, rangeURI, null)); +// assertTrue(strategy.handles(uri, uri, rangeURI, uri)); +// //s_r(p)(ng) +// assertTrue(strategy.handles(uri, rangeURI, null, null)); +// assertTrue(strategy.handles(uri, rangeURI, null, uri)); +// //r(s) +// assertTrue(strategy.handles(rangeURI, null, null, null)); +// +// //fail +// //s_r(p)_r(o) +// assertFalse(strategy.handles(uri, rangeURI, rangeURI, null)); +// +// //s==null +// assertFalse(strategy.handles(null, uri, uri, null)); +// +// //s_r(o) +// assertFalse(strategy.handles(uri, null, rangeURI, null)); +// } +//} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/RyaContextTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/RyaContextTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/RyaContextTest.java new file mode 100644 index 0000000..1d92499 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/RyaContextTest.java @@ -0,0 +1,85 @@ +package mvm.rya.api.resolver; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import java.util.Map; + +import junit.framework.TestCase; +import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.api.domain.RyaType; +import mvm.rya.api.domain.RyaURI; +import mvm.rya.api.query.strategy.AbstractTriplePatternStrategyTest.MockRdfConfiguration; +import mvm.rya.api.query.strategy.wholerow.MockRdfCloudConfiguration; +import mvm.rya.api.resolver.triple.TripleRow; + +import org.openrdf.model.impl.URIImpl; + +/** + */ +public class RyaContextTest extends TestCase { + + public void testDefaultSerialization() throws Exception { + RyaContext instance = RyaContext.getInstance(); + //plain string + RyaType ryaType = new RyaType("mydata"); + byte[] serialize = instance.serialize(ryaType); + assertEquals(ryaType, instance.deserialize(serialize)); + + //uri + RyaURI ryaURI = new RyaURI("urn:test#1234"); + serialize = instance.serialize(ryaURI); + RyaType deserialize = instance.deserialize(serialize); + assertEquals(ryaURI, deserialize); + + //custom type + ryaType = new RyaType(new URIImpl("urn:test#customDataType"), "mydata"); + serialize = instance.serialize(ryaType); + assertEquals(ryaType, instance.deserialize(serialize)); + } + + public void testTripleRowSerialization() throws Exception { + RyaURI subj = new RyaURI("urn:test#subj"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaType obj = new RyaType("mydata"); + RyaStatement statement = new RyaStatement(subj, pred, obj); + RyaTripleContext instance = RyaTripleContext.getInstance(new MockRdfCloudConfiguration()); + + Map<TABLE_LAYOUT, TripleRow> map = instance.serializeTriple(statement); + TripleRow tripleRow = map.get(TABLE_LAYOUT.SPO); + assertEquals(statement, instance.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow)); + } + + public void testHashedTripleRowSerialization() throws Exception { + RyaURI subj = new RyaURI("urn:test#subj"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaType obj = new RyaType("mydata"); + RyaStatement statement = new RyaStatement(subj, pred, obj); + MockRdfCloudConfiguration config = new MockRdfCloudConfiguration(); + config.set(MockRdfCloudConfiguration.CONF_PREFIX_ROW_WITH_HASH, Boolean.TRUE.toString()); + RyaTripleContext instance = RyaTripleContext.getInstance(config); + + Map<TABLE_LAYOUT, TripleRow> map = instance.serializeTriple(statement); + TripleRow tripleRow = map.get(TABLE_LAYOUT.SPO); + assertEquals(statement, instance.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/CustomDatatypeResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/CustomDatatypeResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/CustomDatatypeResolverTest.java new file mode 100644 index 0000000..814eb58 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/CustomDatatypeResolverTest.java @@ -0,0 +1,39 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import junit.framework.TestCase; +import mvm.rya.api.domain.RyaType; +import org.openrdf.model.impl.URIImpl; + +/** + * Date: 7/16/12 + * Time: 2:47 PM + */ +public class CustomDatatypeResolverTest extends TestCase { + + public void testCustomDataTypeSerialization() throws Exception { + RyaType ryaType = new RyaType(new URIImpl("urn:test#datatype"), "testdata"); + byte[] serialize = new CustomDatatypeResolver().serialize(ryaType); + RyaType deserialize = new CustomDatatypeResolver().deserialize(serialize); + assertEquals(ryaType, deserialize); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolverTest.java new file mode 100644 index 0000000..bce0a46 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DateTimeRyaTypeResolverTest.java @@ -0,0 +1,176 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import static org.junit.Assert.*; + +import java.util.Date; +import java.util.GregorianCalendar; + +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import mvm.rya.api.domain.RyaType; +import mvm.rya.api.resolver.RdfToRyaConversions; +import mvm.rya.api.resolver.RyaTypeResolverException; + +import org.junit.Ignore; +import org.junit.Test; +import org.openrdf.model.impl.CalendarLiteralImpl; +import org.openrdf.model.vocabulary.XMLSchema; + +/** + * Test serializing and deserializing. + * Notes: + * The serialization, deserialization fills in some information: + * If preserving uncertainty, or preserving the source timezone, then don't use XML type tag. + * - uncertainty: missing time hh:mm:ss becomes 00:00:00 + * - uncertainty: missing milliseconds (.123) become .000. + * - uncertainty: missing timezone becomes the system local timezone. + * - timezone: converted to the equivalent Z timezone. + * - a type XMLSchema.DATE become XMLSchema.DATETIME after deserialized + * + * ex: run in timezone eastern time (GMT-5:00): + * before= 2000-02-02 type = XMLSchema.DATE + * deserialized= 2000-02-02T05:00:00.000Z type = XMLSchema.DATETIME + */ +public class DateTimeRyaTypeResolverTest { + @Test + public void testDateTime() throws Exception { + long currentTime = 1342182689285l; + Date date = new Date(currentTime); + GregorianCalendar gc = new GregorianCalendar(); + gc.setTimeInMillis(date.getTime()); + XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); + CalendarLiteralImpl literal = new CalendarLiteralImpl(xmlGregorianCalendar); + byte[] serialize = new DateTimeRyaTypeResolver().serialize(RdfToRyaConversions.convertLiteral(literal)); + RyaType deserialize = new DateTimeRyaTypeResolver().deserialize(serialize); + assertEquals("2012-07-13T12:31:29.285Z", deserialize.getData()); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + } + @Test + public void testFull() throws Exception { + String currentTime = "2000-01-01T00:00:01.111Z"; + assertSerializeAndDesDateTime("2000-01-01T00:00:01.111Z"); + + } + @Test + public void testNoMilliSeconds() throws Exception { + assertSerializeAndDesDateTime("2000-01-01T00:00:01Z","2000-01-01T00:00:01.000Z"); + + } + @Test + public void testDateNoTimeNoZone() throws Exception { + String beforeDate = "2000-02-02"; + String afterDate="2000-02-0(1|2|3)T\\d\\d:\\d\\d:00\\.000Z"; + RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); + final String afterActual = deserialize.getData(); + assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + } + @Test + public void testDateZoneNoTime() throws Exception { + // if you see this: + //java.lang.IllegalArgumentException: Invalid format: "2000-02-02Z" is malformed at "Z" + // use this: "2000-02-02TZ"; + String currentTime = "2000-02-02TZ"; + RyaType deserialize = serializeAndDeserialize(currentTime, XMLSchema.DATE); + assertEquals("Before expected should match after actual deserialized:","2000-02-02T00:00:00.000Z", deserialize.getData()); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + } + @Test + public void testNoZone() throws Exception { + String beforeDate = "2000-01-02T00:00:01"; + String afterDate="2000-01-0(1|2|3)T\\d\\d:\\d\\d:01\\.000Z"; + RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); + final String afterActual = deserialize.getData(); + assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + + } + @Test + public void testMilliSecondsNoZone() throws Exception { + String beforeDate="2002-02-02T02:02:02.222"; + String afterDate="2002-02-02T\\d\\d:\\d\\d:02\\.222.*"; + RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATETIME); + final String afterActual = deserialize.getData(); + assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + + } + @Test + public void testHistoryAndFuture() throws Exception { + assertSerializeAndDesDateTime("-2000-01-01T00:00:01Z","-2000-01-01T00:00:01.000Z"); + assertSerializeAndDesDateTime("111-01-01T00:00:01Z","0111-01-01T00:00:01.000Z"); + assertSerializeAndDesDateTime("12345-01-01T00:00:01Z","12345-01-01T00:00:01.000Z"); + } + + @Test + public void testTimeZone() throws Exception { + assertSerializeAndDesDateTime( "2000-01-01T00:00:01+01:00", "1999-12-31T23:00:01.000Z"); + assertSerializeAndDesDateTime( "2000-01-01T00:00:01+02:30", "1999-12-31T21:30:01.000Z"); + assertSerializeAndDesDateTime("2000-01-01T00:00:01.123-02:00", "2000-01-01T02:00:01.123Z"); + assertSerializeAndDesDateTime( "111-01-01T00:00:01+14:00", "0110-12-31T10:00:01.000Z" ); + assertSerializeAndDesDateTime( "12345-01-01T00:00:01-14:00","12345-01-01T14:00:01.000Z"); + assertSerializeAndDesDateTime( "1-01-01T00:00:01+14:00", "0000-12-31T10:00:01.000Z" ); + } + + @Test + public void testGarbageIn() throws Exception { + String currentTime = "Blablabla"; + RyaType ryaType = new RyaType(XMLSchema.DATETIME, currentTime ); + Throwable threw=null; + try { + new DateTimeRyaTypeResolver().serialize(ryaType); + } catch (java.lang.IllegalArgumentException exception) { + threw = exception; + } + assertNotNull("Expected to catch bad format message.",threw); + assertEquals("Caught bad format message.","Invalid format: \"Blablabla\"", threw.getMessage()); + } + /** + * Do the test on the DateTime + * @param dateTimeString + * @throws RyaTypeResolverException + */ + private void assertSerializeAndDesDateTime(String dateTimeString) throws RyaTypeResolverException { + assertSerializeAndDesDateTime(dateTimeString, dateTimeString); + } + private void assertSerializeAndDesDateTime(String beforeDate, String afterDate ) throws RyaTypeResolverException { + RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATETIME); + assertEquals("Before='"+beforeDate+"'; Expected should match actual after deserialized:",afterDate, deserialize.getData()); + assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); + } + /** + * Serialize a datetime string, then deserialize as a ryaType. + * @param dateTimeString + * @param type if null , use default: XMLSchema.DATETIME + * @return + * @throws RyaTypeResolverException + */ + private RyaType serializeAndDeserialize(String dateTimeString, org.openrdf.model.URI type ) throws RyaTypeResolverException { + if (type == null) + type = XMLSchema.DATETIME; + RyaType ryaType = new RyaType(type, dateTimeString ); + byte[] serialize = new DateTimeRyaTypeResolver().serialize(ryaType); + return new DateTimeRyaTypeResolver().deserialize(serialize); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolverTest.java new file mode 100644 index 0000000..9c53664 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/DoubleRyaTypeResolverTest.java @@ -0,0 +1,45 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import junit.framework.TestCase; +import mvm.rya.api.domain.RyaType; +import org.openrdf.model.vocabulary.XMLSchema; + +import java.util.Random; + +/** + * Date: 7/20/12 + * Time: 9:43 AM + */ +public class DoubleRyaTypeResolverTest extends TestCase { + + public void testDoubleSerialization() throws Exception { + Double d = randomDouble(); + RyaType ryaType = new RyaType(XMLSchema.DOUBLE, d.toString()); + byte[] serialize = new DoubleRyaTypeResolver().serialize(ryaType); + assertEquals(d, Double.parseDouble(new DoubleRyaTypeResolver().deserialize(serialize).getData())); + } + + private double randomDouble() { + return new Random(System.currentTimeMillis()).nextDouble(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/IntegerRyaTypeResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/IntegerRyaTypeResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/IntegerRyaTypeResolverTest.java new file mode 100644 index 0000000..c8a739a --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/IntegerRyaTypeResolverTest.java @@ -0,0 +1,43 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import junit.framework.TestCase; +import mvm.rya.api.domain.RyaType; +import org.openrdf.model.vocabulary.XMLSchema; + +import java.util.Random; + +/** + * Date: 7/20/12 + * Time: 10:17 AM + */ +public class IntegerRyaTypeResolverTest extends TestCase { + public void testIntegerSerialization() throws Exception { + Integer i = randomInt(); + byte[] serialize = new IntegerRyaTypeResolver().serialize(new RyaType(XMLSchema.INTEGER, i.toString())); + assertEquals(i, new Integer(new IntegerRyaTypeResolver().deserialize(serialize).getData())); + } + + private int randomInt() { + return new Random(System.currentTimeMillis()).nextInt(Integer.MAX_VALUE); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/LongRyaTypeResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/LongRyaTypeResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/LongRyaTypeResolverTest.java new file mode 100644 index 0000000..c09ccc7 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/LongRyaTypeResolverTest.java @@ -0,0 +1,48 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.api.domain.RyaType; +import org.junit.Test; +import org.openrdf.model.vocabulary.XMLSchema; + +import java.util.Random; + +import static junit.framework.Assert.assertEquals; + +/** + * Date: 9/7/12 + * Time: 2:53 PM + */ +public class LongRyaTypeResolverTest { + + @Test + public void testSerialization() throws Exception { + Long i = randomLong(); + byte[] serialize = new LongRyaTypeResolver().serialize(new RyaType(XMLSchema.LONG, i.toString())); + assertEquals(i, new Long(new LongRyaTypeResolver().deserialize(serialize).getData())); + } + + private long randomLong() { + return new Random(System.currentTimeMillis()).nextLong(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/RyaURIResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/RyaURIResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/RyaURIResolverTest.java new file mode 100644 index 0000000..225ceda --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/impl/RyaURIResolverTest.java @@ -0,0 +1,39 @@ +package mvm.rya.api.resolver.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import junit.framework.TestCase; +import mvm.rya.api.domain.RyaType; +import mvm.rya.api.domain.RyaURI; + +/** + * Date: 7/16/12 + * Time: 2:51 PM + */ +public class RyaURIResolverTest extends TestCase { + + public void testSerialization() throws Exception { + RyaURI ryaURI = new RyaURI("urn:testdata#data"); + byte[] serialize = new RyaURIResolver().serialize(ryaURI); + RyaType deserialize = new RyaURIResolver().deserialize(serialize); + assertEquals(ryaURI, deserialize); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java new file mode 100644 index 0000000..014dceb --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java @@ -0,0 +1,123 @@ +package mvm.rya.api.resolver.triple.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import java.util.Map; + +import junit.framework.TestCase; +import mvm.rya.api.RdfCloudTripleStoreConstants; +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.api.domain.RyaURI; +import mvm.rya.api.resolver.triple.TripleRow; + +/** + * Date: 7/25/12 + * Time: 10:52 AM + */ +public class HashedWholeRowTripleResolverTest extends TestCase { + + WholeRowHashedTripleResolver tripleResolver = new WholeRowHashedTripleResolver(); + + public void testSerialize() throws Exception { + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); + RyaStatement deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); + deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializePO() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializeOSP() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializeOSPCustomType() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java b/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java new file mode 100644 index 0000000..b313a25 --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java @@ -0,0 +1,126 @@ +package mvm.rya.api.resolver.triple.impl; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import junit.framework.TestCase; +import mvm.rya.api.RdfCloudTripleStoreConstants; +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.api.domain.RyaURI; +import mvm.rya.api.resolver.triple.TripleRow; +import mvm.rya.api.resolver.triple.TripleRowRegex; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Date: 7/25/12 + * Time: 10:52 AM + */ +public class WholeRowTripleResolverTest extends TestCase { + + WholeRowTripleResolver tripleResolver = new WholeRowTripleResolver(); + + public void testSerialize() throws Exception { + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); + RyaStatement deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO); + deserialize = tripleResolver.deserialize(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializePO() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializeOSP() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + + public void testSerializeOSPCustomType() throws Exception { + RdfCloudTripleStoreConstants.TABLE_LAYOUT po = RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP; + //no context + RyaURI subj = new RyaURI("urn:test#1234"); + RyaURI pred = new RyaURI("urn:test#pred"); + RyaURI obj = new RyaURI("urn:test#obj"); + RyaURI cntxt = new RyaURI("urn:test#cntxt"); + final RyaStatement stmt = new RyaStatement(subj, pred, obj, null, null, null, null, 100l); + final RyaStatement stmtContext = new RyaStatement(subj, pred, obj, cntxt, null, null, null, 100l); + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = tripleResolver.serialize(stmt); + TripleRow tripleRow = serialize.get(po); + RyaStatement deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmt, deserialize); + + //context + serialize = tripleResolver.serialize(stmtContext); + tripleRow = serialize.get(po); + deserialize = tripleResolver.deserialize(po, tripleRow); + assertEquals(stmtContext, deserialize); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/test/java/mvm/rya/api/utils/RdfIOTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/mvm/rya/api/utils/RdfIOTest.java b/common/rya.api/src/test/java/mvm/rya/api/utils/RdfIOTest.java new file mode 100644 index 0000000..26ca01c --- /dev/null +++ b/common/rya.api/src/test/java/mvm/rya/api/utils/RdfIOTest.java @@ -0,0 +1,67 @@ +//package mvm.rya.api.utils; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +// +//import junit.framework.TestCase; +//import mvm.rya.api.RdfCloudTripleStoreUtils; +//import org.openrdf.model.Statement; +//import org.openrdf.model.impl.StatementImpl; +// +//import static mvm.rya.api.RdfCloudTripleStoreConstants.*; +// +///** +// * Class RdfIOTest +// * Date: Mar 8, 2012 +// * Time: 10:12:00 PM +// */ +//public class RdfIOTest extends TestCase { +// +// Statement st = new StatementImpl(RTS_SUBJECT, RTS_VERSION_PREDICATE, VERSION); +// int num = 100000; +// +// public void testPerf() throws Exception { +// +// long start = System.currentTimeMillis(); +// for(int i = 0; i < num; i++) { +// byte[] bytes = RdfCloudTripleStoreUtils.writeValue(st.getSubject()); +//// byte[] bytes = RdfIO.writeStatement(st); +//// Statement retSt = RdfIO.readStatement(ByteStreams.newDataInput(bytes), VALUE_FACTORY); +// } +// long dur = System.currentTimeMillis() - start; +// System.out.println("RdfCloudTripleStoreUtils: " + dur); +// +// +// } +// +// public void testPerf2() throws Exception { +// long start = System.currentTimeMillis(); +// for(int i = 0; i < num; i++) { +// byte[] bytes = RdfIO.writeValue(st.getSubject()); +// +//// byte[] bytes = RdfCloudTripleStoreUtils.buildRowWith(RdfCloudTripleStoreUtils.writeValue(st.getSubject()), +//// RdfCloudTripleStoreUtils.writeValue(st.getPredicate()), +//// RdfCloudTripleStoreUtils.writeValue(st.getObject())); +//// Statement retSt = RdfCloudTripleStoreUtils.translateStatementFromRow(ByteStreams.newDataInput(bytes), TABLE_LAYOUT.SPO, VALUE_FACTORY); +// } +// long dur = System.currentTimeMillis() - start; +// System.out.println("RdfIO: " + dur); +// } +//} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/pom.xml ---------------------------------------------------------------------- diff --git a/common/rya.provenance/pom.xml b/common/rya.provenance/pom.xml new file mode 100644 index 0000000..cf26d4d --- /dev/null +++ b/common/rya.provenance/pom.xml @@ -0,0 +1,39 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.common</artifactId> + <version>3.2.9</version> + </parent> + <artifactId>rya.provenance</artifactId> + <name>${project.groupId}.${project.artifactId}</name> + <properties> + </properties> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${slf4j.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-runtime</artifactId> + </dependency> + + </dependencies> + + +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/LoggingProvenanceCollector.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/LoggingProvenanceCollector.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/LoggingProvenanceCollector.java new file mode 100644 index 0000000..09111cf --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/LoggingProvenanceCollector.java @@ -0,0 +1,40 @@ +package mvm.rya.rdftriplestore.provenance; + +/* + * #%L + * mvm.rya.rya.sail.impl + * %% + * Copyright (C) 2014 - 2015 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.log4j.Logger; + +/** + * Provenance collector that logs queries + */ +public class LoggingProvenanceCollector implements ProvenanceCollector { + + private static final Logger log = Logger.getLogger(LoggingProvenanceCollector.class); + + /* (non-Javadoc) + * @see mvm.rya.rdftriplestore.provenance.ProvenanceCollector#recordQuery(java.lang.String) + */ + public void recordQuery(String query) { + log.debug("User entered query: " + query); + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollectionException.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollectionException.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollectionException.java new file mode 100644 index 0000000..136c100 --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollectionException.java @@ -0,0 +1,19 @@ +package mvm.rya.rdftriplestore.provenance; + +import org.openrdf.repository.RepositoryException; + +/** + * Exception for errors in collecting provenance data + */ +public class ProvenanceCollectionException extends Exception { + + public ProvenanceCollectionException(RepositoryException e) { + super(e); + } + + /** + * + */ + private static final long serialVersionUID = 1L; + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollector.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollector.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollector.java new file mode 100644 index 0000000..efb974e --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/ProvenanceCollector.java @@ -0,0 +1,14 @@ +package mvm.rya.rdftriplestore.provenance; + +/** + * Collects/records provenance data + */ +public interface ProvenanceCollector { + + /** + * Records appropriate metadata about a query + * @param query the query being recorded. cannot be null + * @throws ProvenanceCollectionException + */ + public void recordQuery(String query) throws ProvenanceCollectionException; +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollector.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollector.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollector.java new file mode 100644 index 0000000..38f026b --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollector.java @@ -0,0 +1,48 @@ +package mvm.rya.rdftriplestore.provenance; + +import java.util.List; + +import mvm.rya.rdftriplestore.provenance.rdf.BaseProvenanceModel; +import mvm.rya.rdftriplestore.provenance.rdf.RDFProvenanceModel; + +import org.openrdf.model.Statement; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.sail.SailRepository; + +/** + * Records provenance data to an external rdf triplestore + */ +public class TriplestoreProvenanceCollector implements ProvenanceCollector { + + private RDFProvenanceModel provenanceModel; + private SailRepository provenanceRepo; + private String user; + private String queryType; + + /** + * @param repo the repository to record to + * @param user the user issuing the query + * @param queryType the type of query (SPARQL, etc.) + */ + public TriplestoreProvenanceCollector(SailRepository repo, String user, String queryType){ + provenanceRepo = repo; + provenanceModel = new BaseProvenanceModel(); + this.user = user; + this.queryType = queryType; + } + + /* (non-Javadoc) + * @see mvm.rya.rdftriplestore.provenance.ProvenanceCollector#recordQuery(java.lang.String) + */ + public void recordQuery(String query) throws ProvenanceCollectionException { + List<Statement> provenanceTriples = provenanceModel.getStatementsForQuery(query, user, queryType); + try { + provenanceRepo.getConnection().add(provenanceTriples); + } catch (RepositoryException e) { + throw new ProvenanceCollectionException(e); + } + + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModel.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModel.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModel.java new file mode 100644 index 0000000..bced532 --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModel.java @@ -0,0 +1,48 @@ +package mvm.rya.rdftriplestore.provenance.rdf; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; +import org.openrdf.model.vocabulary.RDF; + +/** + * Basic representation of Provenance data capture in RDF. + */ +public class BaseProvenanceModel implements RDFProvenanceModel { + + private static final ValueFactory vf = ValueFactoryImpl.getInstance(); + private static final Resource queryEventType = vf.createURI("http://rya.com/provenance#QueryEvent"); + private static final URI atTimeProperty = vf.createURI("http://www.w3.org/ns/prov#atTime"); + private static final URI associatedWithUser = vf.createURI("http://rya.com/provenance#associatedWithUser"); + private static final URI queryTypeProp = vf.createURI("http://rya.com/provenance#queryType"); + private static final URI executedQueryProperty = vf.createURI("http://rya.com/provenance#executedQuery"); + private static final String queryNameSpace = "http://rya.com/provenance#queryEvent"; + + /* (non-Javadoc) + * @see mvm.rya.rdftriplestore.provenance.rdf.RDFProvenanceModel#getStatementsForQuery(java.lang.String, java.lang.String, java.lang.String) + */ + public List<Statement> getStatementsForQuery(String query, String user, String queryType) { + List<Statement> statements = new ArrayList<Statement>(); + // create some statements for the query + Resource queryEventResource = vf.createURI(queryNameSpace + UUID.randomUUID().toString()); + Statement queryEventDecl = vf.createStatement(queryEventResource, RDF.TYPE, queryEventType); + statements.add(queryEventDecl); + Statement queryEventTime = vf.createStatement(queryEventResource, atTimeProperty, vf.createLiteral(new Date())); + statements.add(queryEventTime); + Statement queryUser = vf.createStatement(queryEventResource, associatedWithUser, vf.createLiteral(user)); + statements.add(queryUser); + Statement executedQuery = vf.createStatement(queryEventResource, executedQueryProperty, vf.createLiteral(query)); + statements.add(executedQuery); + Statement queryTypeStatement = vf.createStatement(queryEventResource, queryTypeProp, vf.createLiteral(queryType)); + statements.add(queryTypeStatement); + return statements; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/RDFProvenanceModel.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/RDFProvenanceModel.java b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/RDFProvenanceModel.java new file mode 100644 index 0000000..189320e --- /dev/null +++ b/common/rya.provenance/src/main/java/mvm/rya/rdftriplestore/provenance/rdf/RDFProvenanceModel.java @@ -0,0 +1,13 @@ +package mvm.rya.rdftriplestore.provenance.rdf; + +import java.util.List; + +import org.openrdf.model.Statement; + + +public interface RDFProvenanceModel { + + List<Statement> getStatementsForQuery(String query, String user, String queryType); + + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollectorTest.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollectorTest.java b/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollectorTest.java new file mode 100644 index 0000000..326ef01 --- /dev/null +++ b/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/TriplestoreProvenanceCollectorTest.java @@ -0,0 +1,31 @@ +package mvm.rya.rdftriplestore.provenance; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.sail.Sail; +import org.openrdf.sail.memory.MemoryStore; + +public class TriplestoreProvenanceCollectorTest { + + @Test + public void testCollect() throws ProvenanceCollectionException, RepositoryException, MalformedQueryException, QueryEvaluationException { + Sail ms = new MemoryStore(); + SailRepository repo = new SailRepository(ms); + repo.initialize(); + TriplestoreProvenanceCollector coll = new TriplestoreProvenanceCollector(repo, "fakeUser", "SPARQL"); + coll.recordQuery("fakeQuery"); + String queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } "; + TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString); + TupleQueryResult result = tupleQuery.evaluate(); + // TODO not asserting on the results. + assertTrue(result.hasNext()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModelTest.java ---------------------------------------------------------------------- diff --git a/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModelTest.java b/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModelTest.java new file mode 100644 index 0000000..33f7f64 --- /dev/null +++ b/common/rya.provenance/src/test/java/mvm/rya/rdftriplestore/provenance/rdf/BaseProvenanceModelTest.java @@ -0,0 +1,18 @@ +package mvm.rya.rdftriplestore.provenance.rdf; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openrdf.model.Statement; + +public class BaseProvenanceModelTest { + + @Test + public void testCreateTriples() { + BaseProvenanceModel model = new BaseProvenanceModel(); + List<Statement> statements = model.getStatementsForQuery("SELECT ?query where { ?query rdf:type <rya:query>. }", "fakeuser", "SPARQL"); + assertTrue(!statements.isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/dao/accumulo.rya/pom.xml ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/pom.xml b/dao/accumulo.rya/pom.xml new file mode 100644 index 0000000..82828fb --- /dev/null +++ b/dao/accumulo.rya/pom.xml @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.dao</artifactId> + <version>3.2.9</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>accumulo.rya</artifactId> + <name>${project.groupId}.${project.artifactId}</name> + <properties> + + </properties> + + <dependencies> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>rya.api</artifactId> + </dependency> + + <!-- Accumulo deps --> + <dependency> + <groupId>org.apache.zookeeper</groupId> + <artifactId>zookeeper</artifactId> + <exclusions> + <!-- the log4j that comes with zookeeper 3.3.5 has some bad dependencies --> + <exclusion> + <groupId>javax.jms</groupId> + <artifactId>jms</artifactId> + </exclusion> + <exclusion> + <groupId>com.sun.jdmk</groupId> + <artifactId>jmxtools</artifactId> + </exclusion> + <exclusion> + <groupId>com.sun.jmx</groupId> + <artifactId>jmxri</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-rio-ntriples</artifactId> + <version>${openrdf.sesame.version}</version> + </dependency> + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-rio-nquads</artifactId> + <version>${openrdf.sesame.version}</version> + </dependency> + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-queryalgebra-evaluation</artifactId> + <version>${openrdf.sesame.version}</version> + </dependency> + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-rio-trig</artifactId> + <version>${openrdf.sesame.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + <profiles> + <profile> + <id>accumulo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.accumulo</groupId> + <artifactId>accumulo-core</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>accumulo.iterators</artifactId> + <optional>true</optional> + </dependency> + </dependencies> + </profile> + <profile> + <id>cloudbase</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>com.texeltek</groupId> + <artifactId>accumulo-cloudbase-shim</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>cloudbase.iterators</artifactId> + <optional>true</optional> + </dependency> + </dependencies> + </profile> + <profile> + <id>mr</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <executions> + <execution> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> + </transformers> + </configuration> + </execution> + </executions> + + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloNamespaceTableIterator.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloNamespaceTableIterator.java b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloNamespaceTableIterator.java new file mode 100644 index 0000000..ba3ded3 --- /dev/null +++ b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloNamespaceTableIterator.java @@ -0,0 +1,98 @@ +package mvm.rya.accumulo; + +/* + * #%L + * mvm.rya.accumulo.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import com.google.common.base.Preconditions; +import info.aduna.iteration.CloseableIteration; +import mvm.rya.api.persist.RdfDAOException; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Value; +import org.openrdf.model.Namespace; +import org.openrdf.model.impl.NamespaceImpl; + +import java.io.IOError; +import java.util.Iterator; +import java.util.Map.Entry; + +public class AccumuloNamespaceTableIterator<T extends Namespace> implements + CloseableIteration<Namespace, RdfDAOException> { + + private boolean open = false; + private Iterator<Entry<Key, Value>> result; + + public AccumuloNamespaceTableIterator(Iterator<Entry<Key, Value>> result) throws RdfDAOException { + Preconditions.checkNotNull(result); + open = true; + this.result = result; + } + + @Override + public void close() throws RdfDAOException { + try { + verifyIsOpen(); + open = false; + } catch (IOError e) { + throw new RdfDAOException(e); + } + } + + public void verifyIsOpen() throws RdfDAOException { + if (!open) { + throw new RdfDAOException("Iterator not open"); + } + } + + @Override + public boolean hasNext() throws RdfDAOException { + verifyIsOpen(); + return result != null && result.hasNext(); + } + + @Override + public Namespace next() throws RdfDAOException { + if (hasNext()) { + return getNamespace(result); + } + return null; + } + + public static Namespace getNamespace(Iterator<Entry<Key, Value>> rowResults) { + for (; rowResults.hasNext(); ) { + Entry<Key, Value> next = rowResults.next(); + Key key = next.getKey(); + Value val = next.getValue(); + String cf = key.getColumnFamily().toString(); + String cq = key.getColumnQualifier().toString(); + return new NamespaceImpl(key.getRow().toString(), new String( + val.get())); + } + return null; + } + + @Override + public void remove() throws RdfDAOException { + next(); + } + + public boolean isOpen() { + return open; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRdfConfiguration.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRdfConfiguration.java b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRdfConfiguration.java new file mode 100644 index 0000000..61d1b04 --- /dev/null +++ b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRdfConfiguration.java @@ -0,0 +1,85 @@ +package mvm.rya.accumulo; + +/* + * #%L + * mvm.rya.accumulo.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import java.util.List; + +import mvm.rya.accumulo.experimental.AccumuloIndexer; +import mvm.rya.api.RdfCloudTripleStoreConfiguration; + +import org.apache.accumulo.core.security.Authorizations; +import org.apache.hadoop.conf.Configuration; + +import com.google.common.collect.Lists; + +/** + * Created by IntelliJ IDEA. + * Date: 4/25/12 + * Time: 3:24 PM + * To change this template use File | Settings | File Templates. + */ +public class AccumuloRdfConfiguration extends RdfCloudTripleStoreConfiguration { + + public static final String MAXRANGES_SCANNER = "ac.query.maxranges"; + + public static final String CONF_ADDITIONAL_INDEXERS = "ac.additional.indexers"; + + public AccumuloRdfConfiguration() { + super(); + } + + public AccumuloRdfConfiguration(Configuration other) { + super(other); + } + + @Override + public AccumuloRdfConfiguration clone() { + return new AccumuloRdfConfiguration(this); + } + + public Authorizations getAuthorizations() { + String[] auths = getAuths(); + if (auths == null || auths.length == 0) + return AccumuloRdfConstants.ALL_AUTHORIZATIONS; + return new Authorizations(auths); + } + + public void setMaxRangesForScanner(Integer max) { + setInt(MAXRANGES_SCANNER, max); + } + + public Integer getMaxRangesForScanner() { + return getInt(MAXRANGES_SCANNER, 2); + } + + public void setAdditionalIndexers(Class<? extends AccumuloIndexer>... indexers) { + List<String> strs = Lists.newArrayList(); + for (Class ai : indexers){ + strs.add(ai.getName()); + } + + setStrings(CONF_ADDITIONAL_INDEXERS, strs.toArray(new String[]{})); + } + + public List<AccumuloIndexer> getAdditionalIndexers() { + return getInstances(CONF_ADDITIONAL_INDEXERS, AccumuloIndexer.class); + } +}
