Repository: incubator-rya Updated Branches: refs/heads/master e2a979dec -> bd9b91241
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/bd9b9124/extras/rya.prospector/src/test/groovy/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.groovy ---------------------------------------------------------------------- diff --git a/extras/rya.prospector/src/test/groovy/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.groovy b/extras/rya.prospector/src/test/groovy/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.groovy deleted file mode 100644 index e518ca8..0000000 --- a/extras/rya.prospector/src/test/groovy/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.groovy +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.rya.prospector.service - -import com.google.common.collect.Iterators -import org.apache.rya.accumulo.AccumuloRdfConfiguration -import org.apache.rya.accumulo.AccumuloRyaDAO -import org.apache.rya.api.domain.RyaStatement -import org.apache.rya.api.domain.RyaType -import org.apache.rya.api.domain.RyaURI -import org.apache.rya.api.persist.RdfEvalStatsDAO -import org.apache.rya.prospector.mr.Prospector -import org.apache.accumulo.core.client.Instance -import org.apache.accumulo.core.client.mock.MockInstance -import org.apache.accumulo.core.security.Authorizations -import org.apache.hadoop.conf.Configuration -import org.apache.hadoop.fs.Path -import org.apache.hadoop.util.ToolRunner -import org.junit.Test -import org.openrdf.model.impl.URIImpl -import org.openrdf.model.vocabulary.XMLSchema - -import static org.junit.Assert.assertEquals -import org.openrdf.model.impl.LiteralImpl -import org.openrdf.model.Value - -/** - * Date: 1/26/13 - * Time: 3:00 PM - */ -class ProspectorServiceEvalStatsDAOTest { - - @Test - public void testCount() throws Exception { - - Instance mock = new MockInstance("accumulo"); - - def connector = mock.getConnector("user", "pass".bytes) - def intable = "rya_spo" - def outtable = "rya_prospects" - if (connector.tableOperations().exists(outtable)) - connector.tableOperations().delete(outtable) - connector.tableOperations().create(outtable) - - AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); - ryaDAO.setConnector(connector); - ryaDAO.init() - - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12"))) - - def confFile = "stats_cluster_config.xml" - def confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()) - def args = (String[]) [confPath]; - ToolRunner.run(new Prospector(), args); - debugTable(connector, outtable) - - def scanner = connector.createScanner(outtable, new Authorizations("U", "FOUO")) - def iter = scanner.iterator() -// assertEquals(11, Iterators.size(iter)) - - ryaDAO.destroy() - - def conf = new Configuration() - conf.addResource(confPath) -// debugTable(connector, outtable) - - def rdfConf = new AccumuloRdfConfiguration(conf) - rdfConf.setAuths("U","FOUO") - def evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf) - evalDao.init() - - List<Value> values = new ArrayList<Value>(); - values.add( new URIImpl("urn:gem#pred")); - - def count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.PREDICATE, values) - assertEquals(4.0, count, 0.001); - - values = new ArrayList<Value>(); - values.add( new LiteralImpl("mydata1")); - - count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); - assertEquals(1.0, count, 0.001); - - values = new ArrayList<Value>(); - values.add( new LiteralImpl("mydata3")); - - count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); - assertEquals(-1.0, count, 0.001); - - //should be in a teardown method - connector.tableOperations().delete(outtable) - } - - @Test - public void testNoAuthsCount() throws Exception { - - Instance mock = new MockInstance("accumulo"); - def connector = mock.getConnector("user", "pass".bytes) - def intable = "rya_spo" - def outtable = "rya_prospects" - if (connector.tableOperations().exists(outtable)) - connector.tableOperations().delete(outtable) - connector.tableOperations().create(outtable) - connector.securityOperations().createUser("user", "pass".bytes, new Authorizations("U", "FOUO")) - - AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); - ryaDAO.setConnector(connector); - ryaDAO.init() - - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12"))) - ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12"))) - - def confFile = "stats_cluster_config.xml" - def confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()) - def args = (String[]) [confPath]; - ToolRunner.run(new Prospector(), args); - - def scanner = connector.createScanner(outtable, new Authorizations("U", "FOUO")) - def iter = scanner.iterator() -// assertEquals(11, Iterators.size(iter)) - - ryaDAO.destroy() - - def conf = new Configuration() - conf.addResource(confPath) - - def rdfConf = new AccumuloRdfConfiguration(conf) -// rdfConf.setAuths("U","FOUO") - def evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf) - evalDao.init() - - - List<Value> values = new ArrayList<Value>(); - values.add( new URIImpl("urn:gem#pred")); - def count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.PREDICATE, values) - assertEquals(4.0, count, 0.001); - - values = new ArrayList<Value>(); - values.add( new LiteralImpl("mydata1")); - count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); - assertEquals(1.0, count, 0.001); - - values = new ArrayList<Value>(); - values.add( new LiteralImpl("mydata3")); - - count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); - assertEquals(-1.0, count, 0.001); - - //should be in a teardown method - connector.tableOperations().delete(outtable) - } - - private void debugTable(def connector, String table) { - connector.createScanner(table, new Authorizations((String[]) ["U", "FOUO"])).iterator().each { - println it - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/bd9b9124/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java new file mode 100644 index 0000000..eac7aab --- /dev/null +++ b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/mr/ProspectorTest.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.prospector.mr; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.util.ToolRunner; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.prospector.domain.IndexEntry; +import org.apache.rya.prospector.domain.TripleValueType; +import org.apache.rya.prospector.service.ProspectorService; +import org.apache.rya.prospector.utils.ProspectorConstants; +import org.junit.Test; +import org.openrdf.model.vocabulary.XMLSchema; + +import com.google.common.collect.Lists; + +/** + * Tests that show when the {@link Prospector} job is run, it creates a table + * containing the correct count information derived from the statements that + * have been stored within a Rya instance. + */ +public class ProspectorTest { + + @Test + public void testCount() throws Exception { + // Load some data into a mock Accumulo and run the Prospector MapReduce job. + final Instance mock = new MockInstance("accumulo"); + + final Connector connector = mock.getConnector("user", new PasswordToken("pass")); + final String outtable = "rya_prospects"; + if (connector.tableOperations().exists(outtable)) { + connector.tableOperations().delete(outtable); + } + connector.tableOperations().create(outtable); + + final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); + ryaDAO.setConnector(connector); + ryaDAO.init(); + + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12"))); + + final String confFile = "stats_cluster_config.xml"; + final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); + final String[] args = { confPath.toString() }; + ToolRunner.run(new Prospector(), args); + ryaDAO.destroy(); + + // Interrogate the results of the Prospect job to ensure the correct results were created. + final Configuration conf = new Configuration(); + conf.addResource(confPath); + + final ProspectorService service = new ProspectorService(connector, outtable); + final String[] auths = {"U", "FOUO"}; + Iterator<Long> prospects = service.getProspects(auths); + List<Long> plist = Lists.newArrayList(prospects); + assertEquals(1, plist.size()); + + final Long prospectTimestamp = plist.iterator().next(); + + final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf); + rdfConf.setAuths("U","FOUO"); + + prospects = service.getProspectsInRange(System.currentTimeMillis() - 100000, System.currentTimeMillis() + 10000, auths); + plist = Lists.newArrayList(prospects); + assertEquals(1, plist.size()); + + // Ensure one of the correct "entity" counts was created. + List<String> queryTerms = new ArrayList<>(); + queryTerms.add("urn:gem:etype"); + final List<IndexEntry> entityEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.ENTITY.getIndexType(), queryTerms, XMLSchema.ANYURI.stringValue(), auths); + + final List<IndexEntry> expectedEntityEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem:etype") + .setDataType(XMLSchema.ANYURI.stringValue()) + .setTripleValueType( TripleValueType.ENTITY.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(5)) + .build()); + + assertEquals(expectedEntityEntries, entityEntries); + + // Ensure one of the correct "subject" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("urn:gem:etype#1234"); + final List<IndexEntry> subjectEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.SUBJECT.getIndexType(), queryTerms, XMLSchema.ANYURI.stringValue(), auths); + + final List<IndexEntry> expectedSubjectEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem:etype#1234") + .setDataType(XMLSchema.ANYURI.stringValue()) + .setTripleValueType( TripleValueType.SUBJECT.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(3)) + .build()); + + assertEquals(expectedSubjectEntries, subjectEntries); + + // Ensure one of the correct "predicate" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("urn:gem#pred"); + final List<IndexEntry> predicateEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.PREDICATE.getIndexType(), queryTerms, XMLSchema.ANYURI.stringValue(), auths); + + final List<IndexEntry> expectedPredicateEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem#pred") + .setDataType(XMLSchema.ANYURI.stringValue()) + .setTripleValueType( TripleValueType.PREDICATE.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(4)) + .build()); + + assertEquals(expectedPredicateEntries, predicateEntries); + + // Ensure one of the correct "object" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("mydata1"); + final List<IndexEntry> objectEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.OBJECT.getIndexType(), queryTerms, XMLSchema.STRING.stringValue(), auths); + + final List<IndexEntry> expectedObjectEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("mydata1") + .setDataType(XMLSchema.STRING.stringValue()) + .setTripleValueType( TripleValueType.OBJECT.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(1)) + .build()); + + assertEquals(expectedObjectEntries, objectEntries); + + // Ensure one of the correct "subjectpredicate" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("urn:gem:etype#1234"); + queryTerms.add("urn:gem#pred"); + final List<IndexEntry> subjectPredicateEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.SUBJECT_PREDICATE.getIndexType(), queryTerms, XMLSchema.STRING.stringValue(), auths); + + final List<IndexEntry> expectedSubjectPredicateEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem:etype#1234"+ "\u0000" + "urn:gem#pred") + .setDataType(XMLSchema.STRING.stringValue()) + .setTripleValueType( TripleValueType.SUBJECT_PREDICATE.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(3)) + .build()); + + assertEquals(expectedSubjectPredicateEntries, subjectPredicateEntries); + + // Ensure one of the correct "predicateobject" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("urn:gem#pred"); + queryTerms.add("12"); + final List<IndexEntry> predicateObjectEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.PREDICATE_OBJECT.getIndexType(), queryTerms, XMLSchema.STRING.stringValue(), auths); + + final List<IndexEntry> expectedPredicateObjectEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem#pred" + "\u0000" + "12") + .setDataType(XMLSchema.STRING.stringValue()) + .setTripleValueType( TripleValueType.PREDICATE_OBJECT.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(2)) // XXX This might be a bug. The object matching doesn't care about type. + .build()); + + assertEquals(expectedPredicateObjectEntries, predicateObjectEntries); + + // Ensure one of the correct "" counts was created. + queryTerms = new ArrayList<String>(); + queryTerms.add("urn:gem:etype#1234"); + queryTerms.add("mydata1"); + final List<IndexEntry> subjectObjectEntries = service.query(plist, ProspectorConstants.COUNT, TripleValueType.SUBJECT_OBJECT.getIndexType(), queryTerms, XMLSchema.STRING.stringValue(), auths); + + final List<IndexEntry> expectedSubjectObjectEntries = Lists.newArrayList( + IndexEntry.builder() + .setIndex(ProspectorConstants.COUNT) + .setData("urn:gem:etype#1234" + "\u0000" + "mydata1") + .setDataType(XMLSchema.STRING.stringValue()) + .setTripleValueType( TripleValueType.SUBJECT_OBJECT.getIndexType() ) + .setVisibility("") + .setTimestamp(prospectTimestamp) + .setCount(new Long(1)) + .build()); + + assertEquals(expectedSubjectObjectEntries, subjectObjectEntries); + } + + /** + * Prints the content of an Accumulo table to standard out. Only use then when + * debugging the test. + */ + private void debugTable(Connector connector, String table) throws TableNotFoundException { + final Iterator<Entry<Key, Value>> it = connector.createScanner(table, new Authorizations(new String[]{"U", "FOUO"})).iterator(); + while(it.hasNext()) { + final Entry<Key, Value> entry = it.next(); + System.out.println( entry ); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/bd9b9124/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java new file mode 100644 index 0000000..f048742 --- /dev/null +++ b/extras/rya.prospector/src/test/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAOTest.java @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.prospector.service; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.util.ToolRunner; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.api.persist.RdfEvalStatsDAO; +import org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF; +import org.apache.rya.prospector.mr.Prospector; +import org.junit.Test; +import org.openrdf.model.Value; +import org.openrdf.model.impl.LiteralImpl; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.model.vocabulary.XMLSchema; + +/** + * Tests that show when the {@link Prospector} job is run, the + * {@link ProspectorServiceEvalStatsDAO} may be used to fetch cardinality + * information from the prospect table. + */ +public class ProspectorServiceEvalStatsDAOTest { + + @Test + public void testCount() throws Exception { + // Load some data into a mock Accumulo and run the Prospector MapReduce job. + final Instance mock = new MockInstance("accumulo"); + + final Connector connector = mock.getConnector("user", new PasswordToken("pass")); + final String outtable = "rya_prospects"; + if (connector.tableOperations().exists(outtable)) { + connector.tableOperations().delete(outtable); + } + connector.tableOperations().create(outtable); + + final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); + ryaDAO.setConnector(connector); + ryaDAO.init(); + + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12"))); + + final String confFile = "stats_cluster_config.xml"; + final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); + final String[] args = { confPath.toString() }; + ToolRunner.run(new Prospector(), args); + + ryaDAO.destroy(); + + final Configuration conf = new Configuration(); + conf.addResource(confPath); + + final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf); + rdfConf.setAuths("U","FOUO"); + final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf); + evalDao.init(); + + // Get the cardinality of the 'urn:gem#pred' predicate. + List<Value> values = new ArrayList<Value>(); + values.add( new URIImpl("urn:gem#pred") ); + double count = evalDao.getCardinality(rdfConf, CARDINALITY_OF.PREDICATE, values); + assertEquals(4.0, count, 0.001); + + // Get the cardinality of the 'mydata1' object. + values = new ArrayList<Value>(); + values.add( new LiteralImpl("mydata1")); + count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); + assertEquals(1.0, count, 0.001); + + // Get the cardinality of the 'mydata3' object. + values = new ArrayList<Value>(); + values.add( new LiteralImpl("mydata3")); + count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); + assertEquals(-1.0, count, 0.001); + } + + @Test + public void testNoAuthsCount() throws Exception { + // Load some data into a mock Accumulo and run the Prospector MapReduce job. + final Instance mock = new MockInstance("accumulo"); + + final Connector connector = mock.getConnector("user", new PasswordToken("pass")); + final String outtable = "rya_prospects"; + if (connector.tableOperations().exists(outtable)) { + connector.tableOperations().delete(outtable); + } + connector.tableOperations().create(outtable); + connector.securityOperations().createUser("user", "pass".getBytes(), new Authorizations("U", "FOUO")); + + final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); + ryaDAO.setConnector(connector); + ryaDAO.init(); + + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12"))); + ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12"))); + + final String confFile = "stats_cluster_config.xml"; + final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString()); + final String[] args = { confPath.toString() }; + ToolRunner.run(new Prospector(), args); + + ryaDAO.destroy(); + + final Configuration conf = new Configuration(); + conf.addResource(confPath); + + final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf); + final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf); + evalDao.init(); + + // Get the cardinality of the 'urn:gem#pred' predicate. + List<Value> values = new ArrayList<Value>(); + values.add( new URIImpl("urn:gem#pred")); + double count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.PREDICATE, values); + assertEquals(4.0, count, 0.001); + + // Get the cardinality of the 'mydata1' object. + values = new ArrayList<Value>(); + values.add( new LiteralImpl("mydata1")); + count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); + assertEquals(1.0, count, 0.001); + + // Get the cardinality of the 'mydata3' object. + values = new ArrayList<Value>(); + values.add( new LiteralImpl("mydata3")); + count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values); + assertEquals(-1.0, count, 0.001); + } + + /** + * Prints the content of an Accumulo table to standard out. Only use then when + * debugging the test. + */ + private void debugTable(Connector connector, String table) throws TableNotFoundException { + final Iterator<Entry<Key, org.apache.accumulo.core.data.Value>> it = connector.createScanner(table, new Authorizations(new String[]{"U", "FOUO"})).iterator(); + while(it.hasNext()) { + System.out.println( it.next() ); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/bd9b9124/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index ef2e7d8..4f7148a 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,6 @@ under the License. <commons.pool.version>1.6</commons.pool.version> <!-- Newest: 1.6 --> <gmaven.version>1.3</gmaven.version> <!-- Newest: 1.5 --> - <groovy.version>2.3.11</groovy.version> <!-- Newest: 2.4.5 --> <guava.version>14.0.1</guava.version> <!-- Newest: 18.0 --> @@ -400,24 +399,6 @@ under the License. <version>${embed.mongo.version}</version> </dependency> - <!-- Groovy --> - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - <version>${groovy.version}</version> - </dependency> - <dependency> - <groupId>org.codehaus.gmaven.runtime</groupId> - <artifactId>gmaven-runtime-1.7</artifactId> - <version>${gmaven.version}</version> - <exclusions> - <exclusion> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Spring --> <dependency> <groupId>org.springframework.shell</groupId> @@ -775,42 +756,6 @@ under the License. </configuration> </plugin> <plugin> - <groupId>org.codehaus.gmaven</groupId> - <artifactId>gmaven-plugin</artifactId> - <version>${gmaven.version}</version> - <dependencies> - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - <version>${groovy.version}</version> - </dependency> - <dependency> - <groupId>org.codehaus.gmaven.runtime</groupId> - <artifactId>gmaven-runtime-1.7</artifactId> - <version>${gmaven.version}</version> - <exclusions> - <exclusion> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <executions> - <execution> - <configuration> - <providerSelection>1.7</providerSelection> - </configuration> - <goals> - <goal>generateStubs</goal> - <goal>compile</goal> - <goal>generateTestStubs</goal> - <goal>testCompile</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <configuration> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/bd9b9124/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java index daf446c..63c5d13 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java @@ -642,6 +642,10 @@ public class QueryJoinSelectOptimizerTest { QueryJoinSelectOptimizer qjs = new QueryJoinSelectOptimizer(ars, accc); System.out.println("Originial query is " + te); qjs.optimize(te, null, null); + + TupleExpr what = getTupleExpr(Q4); + System.out.println("lolol: \n" + what); + Assert.assertTrue(te.equals(getTupleExpr(Q4))); System.out.print("Optimized query is " + te);