You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by mi...@apache.org on 2016/10/15 20:06:59 UTC
[39/69] [abbrv] [partial] incubator-rya git commit: RYA-198 Renaming
Files
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/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
deleted file mode 100644
index 2baa92d..0000000
--- a/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/HashedWholeRowTripleResolverTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package mvm.rya.api.resolver.triple.impl;
-
-/*
- * 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.
- */
-
-
-
-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/44a2dcf0/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
deleted file mode 100644
index 30409ff..0000000
--- a/common/rya.api/src/test/java/mvm/rya/api/resolver/triple/impl/WholeRowTripleResolverTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package mvm.rya.api.resolver.triple.impl;
-
-/*
- * 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.
- */
-
-
-
-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/44a2dcf0/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
deleted file mode 100644
index db377e1..0000000
--- a/common/rya.api/src/test/java/mvm/rya/api/utils/RdfIOTest.java
+++ /dev/null
@@ -1,67 +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 mvm.rya.api.utils;
-
-//
-//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/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java
new file mode 100644
index 0000000..6db6053
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaTypeTest.java
@@ -0,0 +1,119 @@
+package mvm.rya.api.domain;
+
+/*
+ * 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.
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openrdf.model.vocabulary.XMLSchema;
+
+public class RyaTypeTest {
+ static RyaType a = new RyaType(XMLSchema.STRING, "http://www.example.com/Alice");
+ static RyaType b = new RyaType(XMLSchema.STRING, "http://www.example.com/Bob");
+ static RyaType c = new RyaType(XMLSchema.STRING, "http://www.example.com/Carol");
+ static RyaType aUri = new RyaType(XMLSchema.ANYURI, "http://www.example.com/Alice");
+ static RyaType bUri = new RyaType(XMLSchema.ANYURI, "http://www.example.com/Bob");
+ RyaType nullData = new RyaType(XMLSchema.STRING, null);
+ RyaType nullType = new RyaType(null, "http://www.example.com/Alice");
+ RyaType nullBoth = new RyaType(null, null);
+ RyaType same = new RyaType(XMLSchema.STRING, "http://www.example.com/Alice");
+
+ @Test
+ public void testCompareTo() throws Exception {
+ Assert.assertEquals("compareTo(self) should return zero.", 0, aUri.compareTo(aUri));
+ Assert.assertFalse("compareTo should return nonzero for different data and type.", aUri.compareTo(b) == 0);
+ Assert.assertFalse("compareTo should return nonzero for same data and different datatypes.", a.compareTo(aUri) == 0);
+ Assert.assertFalse("compareTo should return nonzero for same datatype and different data.", bUri.compareTo(aUri) == 0);
+ Assert.assertEquals("compareTo should return zero for different objects with matching data and datatype.",
+ 0, a.compareTo(same));
+ }
+
+ @Test
+ public void testCompareToNullFields() throws Exception {
+ Assert.assertEquals("[has no nulls].compareTo([has null data]) should return -1", -1, a.compareTo(nullData));
+ Assert.assertEquals("[has no nulls].compareTo([has null type]) should return -1 if data is equal",
+ -1, a.compareTo(nullType));
+ Assert.assertEquals("[has null data].compareTo([has no nulls]) should return 1", 1, nullData.compareTo(a));
+ Assert.assertEquals("[has null type].compareTo([has no nulls]) should return 1 if data is equal",
+ 1, nullType.compareTo(a));
+ Assert.assertEquals("[has null type].compareTo([has null data]) should return -1", -1, nullType.compareTo(nullData));
+ }
+
+ @Test
+ public void testCompareToSymmetry() throws Exception {
+ int forward = Integer.signum(a.compareTo(b));
+ int backward = Integer.signum(b.compareTo(a));
+ Assert.assertEquals("Comparison of different values with same type should yield opposite signs.", forward, backward * -1);
+ forward = Integer.signum(bUri.compareTo(b));
+ backward = Integer.signum(b.compareTo(bUri));
+ Assert.assertEquals("Comparison of same values with different types should yield opposite signs.", forward, backward*-1);
+ forward = Integer.signum(aUri.compareTo(b));
+ backward = Integer.signum(b.compareTo(aUri));
+ Assert.assertEquals("Comparison of different values with different types should yield opposite signs.",
+ forward, backward * -1);
+ }
+
+ @Test
+ public void testCompareToTransitive() throws Exception {
+ int sign = Integer.signum(a.compareTo(b));
+ Assert.assertEquals("compareTo(a,b) and compareTo(b,c) should have the same sign.",
+ sign, Integer.signum(b.compareTo(c)));
+ Assert.assertEquals("if a > b > c, compareTo(a,c) should be consistent.", sign, Integer.signum(a.compareTo(c)));
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ Assert.assertTrue("Same data and datatype should be equal.", a.equals(same));
+ Assert.assertFalse("Same data, different datatype should be unequal.", a.equals(aUri));
+ Assert.assertFalse("Same datatype, different data should be unequal.", a.equals(b));
+ }
+
+ @Test
+ public void testEqualsNullFields() throws Exception {
+ Assert.assertFalse("equals(null) should return false.", a.equals(null));
+ Assert.assertFalse("Same data, one null datatype should be unequal.", a.equals(nullType));
+ Assert.assertFalse("Same datatype, one null data should be unequal.", a.equals(nullData));
+ RyaType sameNull = new RyaType(null, null);
+ Assert.assertTrue("Matching null fields should be equal.", sameNull.equals(nullBoth));
+ }
+
+ @Test
+ public void testEqualsCompareToConsistency() throws Exception {
+ Assert.assertEquals("equals and compareTo inconsistent for matching values and types.",
+ a.equals(same), a.compareTo(same) == 0);
+ Assert.assertEquals("equals and compareTo inconsistent for different values with same types.",
+ a.equals(b), a.compareTo(b) == 0);
+ Assert.assertEquals("equals and compareTo inconsistent for same values having different types.",
+ a.equals(aUri), a.compareTo(aUri) == 0);
+ Assert.assertEquals("equals and compareTo inconsistent for different values and different types.",
+ a.equals(bUri), a.compareTo(bUri) == 0);
+ }
+
+ @Test
+ public void testHashCodeEquals() throws Exception {
+ Assert.assertEquals("Same data and same type should yield same hash code.",
+ a.hashCode(), same.hashCode());
+ Assert.assertEquals("Same type and both null data should yield same hash code.",
+ nullData.hashCode(), new RyaType(XMLSchema.STRING, null).hashCode());
+ Assert.assertEquals("Same data and both null type should yield same hash code.",
+ nullType.hashCode(), new RyaType(null, "http://www.example.com/Alice").hashCode());
+ Assert.assertEquals("Null type and null data should yield same hash code.",
+ nullBoth.hashCode(), new RyaType(null, null).hashCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaURIPrefixTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaURIPrefixTest.java b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaURIPrefixTest.java
new file mode 100644
index 0000000..3966679
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/domain/RyaURIPrefixTest.java
@@ -0,0 +1,37 @@
+package mvm.rya.api.domain;
+
+/*
+ * 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.
+ */
+
+
+
+import junit.framework.TestCase;
+
+/**
+ * Date: 7/24/12
+ * Time: 3:30 PM
+ */
+public class RyaURIPrefixTest extends TestCase {
+
+ public void testPrefix() throws Exception {
+ String prefix = "urn:test#";
+ RyaURIPrefix uriPrefix = new RyaURIPrefix(prefix);
+ assertEquals(prefix, uriPrefix.getPrefix());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsTest.java b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsTest.java
new file mode 100644
index 0000000..c613fee
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsTest.java
@@ -0,0 +1,140 @@
+package mvm.rya.api.instance;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+import com.google.common.base.Optional;
+
+import mvm.rya.api.instance.RyaDetails.EntityCentricIndexDetails;
+import mvm.rya.api.instance.RyaDetails.FreeTextIndexDetails;
+import mvm.rya.api.instance.RyaDetails.GeoIndexDetails;
+import mvm.rya.api.instance.RyaDetails.JoinSelectivityDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails.PCJUpdateStrategy;
+import mvm.rya.api.instance.RyaDetails.ProspectorDetails;
+import mvm.rya.api.instance.RyaDetails.TemporalIndexDetails;
+
+/**
+ * Tests the methods of {@link RyaDetails}.
+ */
+public class RyaDetailsTest {
+
+ @Test
+ public void equals() {
+ final RyaDetails.Builder builder = RyaDetails.builder();
+
+ builder.setRyaInstanceName("test_instance")
+ .setRyaVersion("1.2.3.4")
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setFreeTextDetails( new FreeTextIndexDetails(true) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true)
+ .setFluoDetails( new FluoDetails("test_instance_rya_pcj_updater") )
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 1")
+ .setUpdateStrategy(PCJUpdateStrategy.BATCH)
+ .setLastUpdateTime( new Date() ))
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 2")
+ .setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL)))
+ .setProspectorDetails( new ProspectorDetails(Optional.of(new Date())) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails(Optional.of(new Date())) );
+
+ final RyaDetails details1 = builder.build();
+ final RyaDetails details2 = builder.build();
+ assertEquals(details1, details2);
+ }
+
+ @Test
+ public void hashcode() {
+ final RyaDetails.Builder builder = RyaDetails.builder();
+
+ builder.setRyaInstanceName("test_instance")
+ .setRyaVersion("1.2.3.4")
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setFreeTextDetails( new FreeTextIndexDetails(true) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true)
+ .setFluoDetails( new FluoDetails("test_instance_rya_pcj_updater") )
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 1")
+ .setUpdateStrategy(PCJUpdateStrategy.BATCH)
+ .setLastUpdateTime( new Date() ))
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 2")
+ .setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL)))
+ .setProspectorDetails( new ProspectorDetails(Optional.of(new Date())) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails(Optional.of(new Date())) );
+
+ final RyaDetails details1 = builder.build();
+ final RyaDetails details2 = builder.build();
+ assertEquals(details1.hashCode(), details2.hashCode());
+ }
+
+ @Test
+ public void constructor() {
+ final RyaDetails originalDetails = RyaDetails.builder()
+ .setRyaInstanceName("test_instance")
+ .setRyaVersion("1.2.3.4")
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setFreeTextDetails( new FreeTextIndexDetails(true) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true)
+ .setFluoDetails( new FluoDetails("test_instance_rya_pcj_updater") )
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 1")
+ .setUpdateStrategy(PCJUpdateStrategy.BATCH)
+ .setLastUpdateTime( new Date() ))
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 2")
+ .setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL)))
+ .setProspectorDetails( new ProspectorDetails(Optional.of(new Date())) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails(Optional.of(new Date())) )
+ .build();
+
+ // Create a new Builder using another RyaDetails object.
+ final RyaDetails.Builder builder = new RyaDetails.Builder( originalDetails );
+
+ // Show it builds the object that was passed into it.
+ assertEquals(originalDetails, builder.build());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsToConfigurationTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsToConfigurationTest.java b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsToConfigurationTest.java
new file mode 100644
index 0000000..960e8a9
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsToConfigurationTest.java
@@ -0,0 +1,84 @@
+package mvm.rya.api.instance;
+
+/*
+ * 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.
+ */
+
+import static mvm.rya.api.instance.ConfigurationFields.USE_ENTITY;
+import static mvm.rya.api.instance.ConfigurationFields.USE_FREETEXT;
+import static mvm.rya.api.instance.ConfigurationFields.USE_GEO;
+import static mvm.rya.api.instance.ConfigurationFields.USE_PCJ;
+import static mvm.rya.api.instance.ConfigurationFields.USE_TEMPORAL;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
+
+import com.google.common.base.Optional;
+
+import mvm.rya.api.instance.RyaDetails.EntityCentricIndexDetails;
+import mvm.rya.api.instance.RyaDetails.FreeTextIndexDetails;
+import mvm.rya.api.instance.RyaDetails.GeoIndexDetails;
+import mvm.rya.api.instance.RyaDetails.JoinSelectivityDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails.PCJUpdateStrategy;
+import mvm.rya.api.instance.RyaDetails.ProspectorDetails;
+import mvm.rya.api.instance.RyaDetails.TemporalIndexDetails;
+
+public class RyaDetailsToConfigurationTest {
+ @Test
+ public void populateConfigTest() {
+ final RyaDetails.Builder builder = RyaDetails.builder();
+
+ builder.setRyaInstanceName("test_instance")
+ .setRyaVersion("1.2.3.4")
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setFreeTextDetails( new FreeTextIndexDetails(false) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true)
+ .setFluoDetails( new FluoDetails("test_instance_rya_pcj_updater") )
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 1")
+ .setUpdateStrategy(PCJUpdateStrategy.BATCH)
+ .setLastUpdateTime( new Date() ))
+ .addPCJDetails(
+ PCJDetails.builder()
+ .setId("pcj 2")
+ .setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL)))
+ .setProspectorDetails( new ProspectorDetails(Optional.of(new Date())) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails(Optional.of(new Date())) );
+ final Configuration conf = new Configuration();
+ RyaDetailsToConfiguration.addRyaDetailsToConfiguration(builder.build(), conf);
+
+ //defaults are set to cause the assert to fail
+ assertTrue(conf.getBoolean(USE_ENTITY, false));
+ assertFalse(conf.getBoolean(USE_FREETEXT, true));
+ assertTrue(conf.getBoolean(USE_GEO, false));
+ assertTrue(conf.getBoolean(USE_TEMPORAL, false));
+ assertTrue(conf.getBoolean(USE_PCJ, false));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsUpdaterTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsUpdaterTest.java b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsUpdaterTest.java
new file mode 100644
index 0000000..596cc7b
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/instance/RyaDetailsUpdaterTest.java
@@ -0,0 +1,141 @@
+/**
+ * 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 mvm.rya.api.instance;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+import com.google.common.base.Optional;
+
+import mvm.rya.api.instance.RyaDetails.EntityCentricIndexDetails;
+import mvm.rya.api.instance.RyaDetails.FreeTextIndexDetails;
+import mvm.rya.api.instance.RyaDetails.GeoIndexDetails;
+import mvm.rya.api.instance.RyaDetails.JoinSelectivityDetails;
+import mvm.rya.api.instance.RyaDetails.PCJIndexDetails;
+import mvm.rya.api.instance.RyaDetails.ProspectorDetails;
+import mvm.rya.api.instance.RyaDetails.TemporalIndexDetails;
+import mvm.rya.api.instance.RyaDetailsRepository.ConcurrentUpdateException;
+import mvm.rya.api.instance.RyaDetailsRepository.NotInitializedException;
+import mvm.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException;
+import mvm.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator;
+import mvm.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException;
+
+/**
+ * Tests the methods of {@link RyaDetailsUpdater}.
+ */
+public class RyaDetailsUpdaterTest {
+
+ @Test
+ public void update() throws RyaDetailsRepositoryException, CouldNotApplyMutationException {
+ // Setup initial details and mock a repository that returns them.
+ final RyaDetails originalDetails = RyaDetails.builder()
+ .setRyaInstanceName("instanceName")
+ .setRyaVersion("0.0.0.0")
+ .setFreeTextDetails( new FreeTextIndexDetails(true) )
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails( Optional.<Date>absent() ) )
+ .setProspectorDetails( new ProspectorDetails( Optional.<Date>absent() ))
+ .build();
+
+ final RyaDetailsRepository detailsRepo = mock( RyaDetailsRepository.class );
+ when( detailsRepo.getRyaInstanceDetails() ).thenReturn( originalDetails );
+
+ // Use an updater to change the Rya version number.
+ new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
+ @Override
+ public RyaDetails mutate(final RyaDetails old) {
+ return RyaDetails.builder(old)
+ .setRyaVersion("1.1.1.1")
+ .build();
+ }
+ });
+
+ // Verify the repository was asked to update the details.
+ final RyaDetails mutatedDetails = RyaDetails.builder(originalDetails)
+ .setRyaVersion("1.1.1.1")
+ .build();
+ verify(detailsRepo, times(1)).update( eq(originalDetails), eq(mutatedDetails) );
+ }
+
+ @Test
+ public void update_concurrentUpdateEncountered() throws NotInitializedException, RyaDetailsRepositoryException, CouldNotApplyMutationException {
+ // Setup initial details and mock a repository that returns them.
+ final RyaDetails originalDetails = RyaDetails.builder()
+ .setRyaInstanceName("instanceName")
+ .setRyaVersion("0.0.0.0")
+ .setFreeTextDetails( new FreeTextIndexDetails(true) )
+ .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) )
+ .setGeoIndexDetails( new GeoIndexDetails(true) )
+ .setTemporalIndexDetails( new TemporalIndexDetails(true) )
+ .setPCJIndexDetails(
+ PCJIndexDetails.builder()
+ .setEnabled(true) )
+ .setJoinSelectivityDetails( new JoinSelectivityDetails( Optional.<Date>absent() ) )
+ .setProspectorDetails( new ProspectorDetails( Optional.<Date>absent() ))
+ .build();
+
+ final RyaDetails otherUsersUpdate = RyaDetails.builder(originalDetails)
+ .setRyaVersion("1.1.1.1")
+ .build();
+
+ // The first time get detail is called, we get the original state for the details.
+ // When the mutator tries to update using those, it throws an exception.
+ // The second iteration, the other user's state is updated.
+ // When the mutator tries to update again, it succeeds.
+ final RyaDetailsRepository detailsRepo = mock( RyaDetailsRepository.class );
+
+ when( detailsRepo.getRyaInstanceDetails() )
+ .thenReturn( originalDetails )
+ .thenReturn( otherUsersUpdate );
+
+ doThrow( ConcurrentUpdateException.class ).when( detailsRepo ).update( eq(originalDetails), any(RyaDetails.class) );
+
+ // Run the test.
+ new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
+ @Override
+ public RyaDetails mutate(final RyaDetails old) {
+ return RyaDetails.builder(old)
+ .setTemporalIndexDetails( new TemporalIndexDetails(false) )
+ .build();
+ }
+ });
+
+ // Verify the intended mutation eventually gets committed.
+ final RyaDetails finalDetails = RyaDetails.builder(originalDetails)
+ .setRyaVersion("1.1.1.1")
+ .setTemporalIndexDetails( new TemporalIndexDetails(false) )
+ .build();
+
+ verify(detailsRepo, times(1)).update( eq(otherUsersUpdate), eq(finalDetails) );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java b/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java
new file mode 100644
index 0000000..40a9c68
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/persist/query/RyaQueryTest.java
@@ -0,0 +1,63 @@
+package mvm.rya.api.persist.query;
+
+/*
+ * 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.
+ */
+
+
+
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.domain.RyaURI;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ */
+public class RyaQueryTest {
+
+ @Test
+ public void testBuildQueryWithOptions() {
+ RyaURI subj = new RyaURI("urn:test#1234");
+ RyaURI pred = new RyaURI("urn:test#pred");
+ RyaURI obj = new RyaURI("urn:test#obj");
+ RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
+ String[] auths = {"U,FOUO"};
+ long currentTime = System.currentTimeMillis();
+ RyaQuery ryaQuery = RyaQuery.builder(ryaStatement).setAuths(auths).setNumQueryThreads(4).setRegexObject("regexObj")
+ .setRegexPredicate("regexPred").setRegexSubject("regexSubj").setTtl(100l).setBatchSize(10).
+ setCurrentTime(currentTime).setMaxResults(1000l)
+ .build();
+
+ assertNotNull(ryaQuery);
+ assertEquals(ryaStatement, ryaQuery.getQuery());
+ assertEquals(4, (int) ryaQuery.getNumQueryThreads());
+ assertEquals("regexObj", ryaQuery.getRegexObject());
+ assertEquals("regexPred", ryaQuery.getRegexPredicate());
+ assertEquals("regexSubj", ryaQuery.getRegexSubject());
+ assertEquals(100l, (long) ryaQuery.getTtl());
+ assertEquals(10, (int) ryaQuery.getBatchSize());
+ assertEquals(currentTime, (long) ryaQuery.getCurrentTime());
+ assertEquals(1000l, (long) ryaQuery.getMaxResults());
+ assertTrue(Arrays.equals(auths, ryaQuery.getAuths()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/AbstractTriplePatternStrategyTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/AbstractTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/AbstractTriplePatternStrategyTest.java
new file mode 100644
index 0000000..919e4cc
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/AbstractTriplePatternStrategyTest.java
@@ -0,0 +1,192 @@
+package mvm.rya.api.query.strategy;
+
+/*
+ * 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.
+ */
+
+
+
+import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP;
+import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO;
+import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.api.RdfCloudTripleStoreConstants;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.domain.RyaType;
+import mvm.rya.api.domain.RyaURI;
+import mvm.rya.api.query.strategy.wholerow.OspWholeRowTriplePatternStrategy;
+import mvm.rya.api.query.strategy.wholerow.PoWholeRowTriplePatternStrategy;
+import mvm.rya.api.query.strategy.wholerow.SpoWholeRowTriplePatternStrategy;
+import mvm.rya.api.resolver.RyaContext;
+import mvm.rya.api.resolver.RyaTripleContext;
+import mvm.rya.api.resolver.triple.TripleRow;
+import mvm.rya.api.resolver.triple.TripleRowRegex;
+import mvm.rya.api.resolver.triple.impl.WholeRowTripleResolver;
+
+import org.openrdf.model.vocabulary.XMLSchema;
+
+/**
+ * Date: 7/25/12
+ * Time: 11:41 AM
+ */
+public class AbstractTriplePatternStrategyTest extends TestCase {
+ public class MockRdfConfiguration extends RdfCloudTripleStoreConfiguration {
+
+ @Override
+ public RdfCloudTripleStoreConfiguration clone() {
+ return new MockRdfConfiguration();
+ }
+
+ }
+
+ public void testRegex() throws Exception {
+ RyaURI subj = new RyaURI("urn:test#1234");
+ RyaURI pred = new RyaURI("urn:test#pred");
+ RyaURI obj = new RyaURI("urn:test#obj");
+ RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowTripleResolver().serialize(ryaStatement);
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ String row = new String(tripleRow.getRow());
+ TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
+ TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
+ TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
+ //pred
+ TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null);
+ Pattern p = Pattern.compile(tripleRowRegex.getRow());
+ Matcher matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+ //subj
+ tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+ //obj
+ tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //po table
+ row = new String(serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO).getRow());
+ tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = poStrategy.buildRegex(subj.getData(), pred.getData(), obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //various regex
+ tripleRowRegex = poStrategy.buildRegex(null, "urn:test#pr[e|d]{2}", null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //does not match
+ tripleRowRegex = poStrategy.buildRegex(null, "hello", null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertFalse(matcher.matches());
+ }
+
+ public void testObjectTypeInfo() throws Exception {
+ RyaURI subj = new RyaURI("urn:test#1234");
+ RyaURI pred = new RyaURI("urn:test#pred");
+ RyaType obj = new RyaType(XMLSchema.LONG, "10");
+ RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(ryaStatement);
+ TripleRow tripleRow = serialize.get(SPO);
+
+ String row = new String(tripleRow.getRow());
+ TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
+ //obj
+ byte[][] bytes = RyaContext.getInstance().serializeType(obj);
+ String objStr = new String(bytes[0]);
+ byte[] objectTypeInfo = bytes[1];
+ TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ Pattern p = Pattern.compile(tripleRowRegex.getRow());
+ Matcher matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //build row with same object str data
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> dupTriple_str = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(
+ new RyaStatement(subj, pred, new RyaType(XMLSchema.STRING, objStr))
+ );
+ TripleRow tripleRow_dup_str = dupTriple_str.get(SPO);
+
+ row = new String(tripleRow_dup_str.getRow());
+ spoStrategy = new SpoWholeRowTriplePatternStrategy();
+
+ tripleRowRegex = spoStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertFalse(matcher.matches());
+
+ //po table
+ TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
+ tripleRowRegex = poStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ String po_row = new String(serialize.get(PO).getRow());
+ matcher = p.matcher(po_row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = poStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(new String(dupTriple_str.get(PO).getRow()));
+ assertFalse(matcher.matches());
+
+ //osp table
+ TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
+ tripleRowRegex = ospStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ String osp_row = new String(serialize.get(OSP).getRow());
+ matcher = p.matcher(osp_row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = ospStrategy.buildRegex(null, null,
+ objStr
+ , null, objectTypeInfo);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(new String(dupTriple_str.get(OSP).getRow()));
+ assertFalse(matcher.matches());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java
new file mode 100644
index 0000000..25fae9b
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategyTest.java
@@ -0,0 +1,244 @@
+package mvm.rya.api.query.strategy.wholerow;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.hadoop.io.Text;
+import org.junit.Before;
+import org.openrdf.model.impl.URIImpl;
+
+/*
+ * 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.
+ */
+
+
+
+import junit.framework.TestCase;
+import mvm.rya.api.RdfCloudTripleStoreConstants;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.domain.RyaType;
+import mvm.rya.api.domain.RyaTypeRange;
+import mvm.rya.api.domain.RyaURI;
+import mvm.rya.api.domain.RyaURIRange;
+import mvm.rya.api.query.strategy.ByteRange;
+import mvm.rya.api.query.strategy.TriplePatternStrategy;
+import mvm.rya.api.resolver.RyaContext;
+import mvm.rya.api.resolver.RyaTripleContext;
+import mvm.rya.api.resolver.triple.TripleRow;
+import mvm.rya.api.resolver.triple.TripleRowRegex;
+import mvm.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver;
+
+/**
+ * Date: 7/14/12
+ * Time: 11:46 AM
+ */
+public class HashedPoWholeRowTriplePatternStrategyTest 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"));
+ HashedPoWholeRowTriplePatternStrategy strategy = new HashedPoWholeRowTriplePatternStrategy();
+ RyaContext ryaContext = RyaContext.getInstance();
+ RyaTripleContext ryaTripleContext;
+
+ 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);
+
+ @Before
+ public void setUp() {
+ MockRdfCloudConfiguration config = new MockRdfCloudConfiguration();
+ config.set(MockRdfCloudConfiguration.CONF_PREFIX_ROW_WITH_HASH, Boolean.TRUE.toString());
+ ryaTripleContext = RyaTripleContext.getInstance(config);
+ }
+
+
+ public void testRegex() throws Exception {
+ RyaURI subj = new RyaURI("urn:test#1234");
+ RyaURI pred = new RyaURI("urn:test#pred");
+ RyaURI obj = new RyaURI("urn:test#obj");
+ RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowHashedTripleResolver().serialize(ryaStatement);
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ String row = new String(tripleRow.getRow());
+ TriplePatternStrategy spoStrategy = new HashedSpoWholeRowTriplePatternStrategy();
+ TriplePatternStrategy poStrategy = new HashedPoWholeRowTriplePatternStrategy();
+ TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
+ //pred
+ TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null);
+ Pattern p = Pattern.compile(tripleRowRegex.getRow());
+ Matcher matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+ //subj
+ tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+ //obj
+ tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //po table
+ row = new String(serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO).getRow());
+ tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ tripleRowRegex = poStrategy.buildRegex(subj.getData(), pred.getData(), obj.getData(), null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //various regex
+ tripleRowRegex = poStrategy.buildRegex(null, "urn:test#pr[e|d]{2}", null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertTrue(matcher.matches());
+
+ //does not match
+ tripleRowRegex = poStrategy.buildRegex(null, "hello", null, null, null);
+ p = Pattern.compile(tripleRowRegex.getRow());
+ matcher = p.matcher(row);
+ assertFalse(matcher.matches());
+ }
+
+
+ public void testPoRange() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, rangeURI, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(null, uri, rangeURI2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ private void assertContains(ByteRange value, byte[] row) {
+ Text rowText = new Text(row);
+ Text startText = new Text(value.getStart());
+ Text endText = new Text(value.getEnd());
+ assertTrue((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ;
+ }
+
+ private void assertContainsFalse(ByteRange value, byte[] row) {
+ Text rowText = new Text(row);
+ Text startText = new Text(value.getStart());
+ Text endText = new Text(value.getEnd());
+ assertFalse((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ;
+ }
+
+ public void testPoRangeCustomType() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, customType1, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, customTypeRange1, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(null, uri, customTypeRange2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testPo() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, uri, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(null, uri, uri2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testPoCustomType() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, customType1, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, customType1, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(null, uri, customType2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testPosRange() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(rangeURI, uri, uri, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(rangeURI2, uri, uri, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testPRange() throws Exception {
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, rangeURI, null, null, null);
+ assertNull(entry);
+ }
+
+ public void testP() throws Exception {
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, null, null, null);
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
+ assertContains(entry.getValue(), tripleRow.getRow());
+ }
+
+ 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)
+ assertFalse(strategy.handles(null, rangeURI, null, null));
+ assertFalse(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/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java
new file mode 100644
index 0000000..f751866
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategyTest.java
@@ -0,0 +1,199 @@
+package mvm.rya.api.query.strategy.wholerow;
+
+/*
+ * 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.
+ */
+
+
+//
+import java.util.Map;
+
+import junit.framework.TestCase;
+import mvm.rya.api.RdfCloudTripleStoreConstants;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.domain.RyaType;
+import mvm.rya.api.domain.RyaTypeRange;
+import mvm.rya.api.domain.RyaURI;
+import mvm.rya.api.domain.RyaURIRange;
+import mvm.rya.api.query.strategy.ByteRange;
+import mvm.rya.api.resolver.RyaContext;
+import mvm.rya.api.resolver.RyaTripleContext;
+import mvm.rya.api.resolver.triple.TripleRow;
+
+import org.apache.hadoop.io.Text;
+import org.junit.Before;
+import org.openrdf.model.impl.URIImpl;
+
+/**
+ * Date: 7/14/12
+ * Time: 7:47 AM
+ */
+public class HashedSpoWholeRowTriplePatternStrategyTest 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"));
+ HashedSpoWholeRowTriplePatternStrategy strategy = new HashedSpoWholeRowTriplePatternStrategy();
+ RyaContext ryaContext = RyaContext.getInstance();
+ RyaTripleContext ryaTripleContext;
+
+ 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);
+
+ @Before
+ public void setUp() {
+ MockRdfCloudConfiguration config = new MockRdfCloudConfiguration();
+ config.set(MockRdfCloudConfiguration.CONF_PREFIX_ROW_WITH_HASH, Boolean.TRUE.toString());
+ ryaTripleContext = RyaTripleContext.getInstance(config);
+ }
+
+ public void testSpo() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, uri, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+
+ entry = strategy.defineRange(uri, uri, uri2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ private void assertContains(ByteRange value, byte[] row) {
+ Text rowText = new Text(row);
+ Text startText = new Text(value.getStart());
+ Text endText = new Text(value.getEnd());
+ assertTrue((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ;
+ }
+
+ private void assertContainsFalse(ByteRange value, byte[] row) {
+ Text rowText = new Text(row);
+ Text startText = new Text(value.getStart());
+ Text endText = new Text(value.getEnd());
+ assertFalse((startText.compareTo(rowText) <= 0) &&(endText.compareTo(rowText) >= 0)) ;
+ }
+
+ public void testSpoCustomType() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, customType1, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, customType1, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(uri, uri, customType2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testSpoRange() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, rangeURI, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(uri, uri, rangeURI2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testSpoRangeCustomType() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, customType1, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, customTypeRange1, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(uri, uri, customTypeRange2, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testSp() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, null, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+ entry = strategy.defineRange(uri, uri2, null, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testSpRange() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, rangeURI, null, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+ entry = strategy.defineRange(uri, rangeURI2, null, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testS() throws Exception {
+ Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(
+ new RyaStatement(uri, uri, uri, null));
+ TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, null, null, null, null);
+ assertContains(entry.getValue(), tripleRow.getRow());
+
+ entry = strategy.defineRange(uri2, null, null, null, null);
+ assertContainsFalse(entry.getValue(), tripleRow.getRow());
+ }
+
+ public void testSRange() throws Exception {
+
+ Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(rangeURI, null, null, null, null);
+ assertNull(entry);
+ }
+
+ 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));
+
+ //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/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/MockRdfCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/MockRdfCloudConfiguration.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/MockRdfCloudConfiguration.java
new file mode 100644
index 0000000..ddb7fa8
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/MockRdfCloudConfiguration.java
@@ -0,0 +1,32 @@
+package mvm.rya.api.query.strategy.wholerow;
+
+/*
+ * 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.
+ */
+
+
+import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+
+public class MockRdfCloudConfiguration extends RdfCloudTripleStoreConfiguration {
+
+ @Override
+ public RdfCloudTripleStoreConfiguration clone() {
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java
new file mode 100644
index 0000000..57b27be
--- /dev/null
+++ b/common/rya.api/src/test/java/org/apache/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategyTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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 mvm.rya.api.query.strategy.wholerow;
+
+//
+//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));
+// }
+//}