You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by dl...@apache.org on 2018/01/04 22:07:27 UTC
[05/17] incubator-rya git commit: RYA-414 Removed mongo connection
factory
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java
index ff778ba..cff0996 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java
@@ -26,21 +26,17 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.rya.api.RdfCloudTripleStoreConfiguration;
import org.apache.rya.api.domain.RyaURI;
import org.apache.rya.indexing.GeoConstants;
import org.apache.rya.indexing.GeoRyaSailFactory;
import org.apache.rya.indexing.TemporalInstantRfc3339;
-import org.apache.rya.indexing.accumulo.ConfigUtils;
import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils;
import org.apache.rya.indexing.geotemporal.model.Event;
import org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer;
-import org.apache.rya.indexing.geotemporal.mongo.MongoITBase;
import org.apache.rya.indexing.geotemporal.storage.EventStorage;
import org.apache.rya.mongodb.MongoDBRdfConfiguration;
-import org.junit.Before;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Test;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
@@ -54,123 +50,136 @@ import org.openrdf.repository.sail.SailRepository;
import org.openrdf.repository.sail.SailRepositoryConnection;
import org.openrdf.sail.Sail;
-import com.mongodb.MongoClient;
-
-public class MongoGeoTemporalIndexIT extends MongoITBase {
- private static final String URI_PROPERTY_AT_TIME = "Property:atTime";
-
- private static final ValueFactory VF = ValueFactoryImpl.getInstance();
- private MongoDBRdfConfiguration conf;
- private SailRepositoryConnection conn;
- private MongoClient mongoClient;
- private static final AtomicInteger COUNTER = new AtomicInteger(1);
-
- @Before
- public void setUp() throws Exception{
- mongoClient = super.getMongoClient();
- conf = new MongoDBRdfConfiguration();
- conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MongoGeoTemporalIndexIT.class.getSimpleName() + "_" + COUNTER.getAndIncrement());
- conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya");
- conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya");
- conf.setBoolean(ConfigUtils.USE_MONGO, true);
- conf.setBoolean(OptionalConfigUtils.USE_GEOTEMPORAL, true);
- conf.setMongoClient(mongoClient);
-
- final Sail sail = GeoRyaSailFactory.getInstance(conf);
- conn = new SailRepository(sail).getConnection();
- conn.begin();
-
- addStatements();
- }
-
- @Test
- public void ensureInEventStore_Test() throws Exception {
- final MongoGeoTemporalIndexer indexer = new MongoGeoTemporalIndexer();
- indexer.initIndexer(conf, mongoClient);
-
- final EventStorage events = indexer.getEventStorage(conf);
- final RyaURI subject = new RyaURI("urn:event1");
- final Optional<Event> event = events.get(subject);
- assertTrue(event.isPresent());
- }
-
- @Test
- public void constantSubjQuery_Test() throws Exception {
- final String query =
- "PREFIX time: <http://www.w3.org/2006/time#> \n"
- + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"
- + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>"
- + "SELECT * "
- + "WHERE { "
- + " <urn:event1> time:atTime ?time . "
- + " <urn:event1> geo:asWKT ?point . "
- + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) "
- + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) "
- + "}";
-
- final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- final Set<BindingSet> results = new HashSet<>();
- while(rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- final MapBindingSet expected = new MapBindingSet();
- expected.addBinding("point", VF.createLiteral("POINT (0 0)"));
- expected.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
-
- assertEquals(1, results.size());
- assertEquals(expected, results.iterator().next());
- }
-
- @Test
- public void variableSubjQuery_Test() throws Exception {
- final String query =
- "PREFIX time: <http://www.w3.org/2006/time#> \n"
- + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"
- + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>"
- + "SELECT * "
- + "WHERE { "
- + " ?subj time:atTime ?time . "
- + " ?subj geo:asWKT ?point . "
- + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) "
- + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) "
- + "}";
-
- final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- final List<BindingSet> results = new ArrayList<>();
- while(rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- final MapBindingSet expected1 = new MapBindingSet();
- expected1.addBinding("point", VF.createLiteral("POINT (0 0)"));
- expected1.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
-
- final MapBindingSet expected2 = new MapBindingSet();
- expected2.addBinding("point", VF.createLiteral("POINT (1 1)"));
- expected2.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
-
- assertEquals(2, results.size());
- assertEquals(expected1, results.get(0));
- assertEquals(expected2, results.get(1));
- }
-
- private void addStatements() throws Exception {
- URI subject = VF.createURI("urn:event1");
- final URI predicate = VF.createURI(URI_PROPERTY_AT_TIME);
- Value object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
- conn.add(VF.createStatement(subject, predicate, object));
-
- object = VF.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object));
-
- subject = VF.createURI("urn:event2");
- object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
- conn.add(VF.createStatement(subject, predicate, object));
-
- object = VF.createLiteral("Point(1 1)", GeoConstants.XMLSCHEMA_OGC_WKT);
- conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object));
- }
+public class MongoGeoTemporalIndexIT extends MongoTestBase {
+ private static final String URI_PROPERTY_AT_TIME = "Property:atTime";
+
+ private static final ValueFactory VF = ValueFactoryImpl.getInstance();
+ @Override
+ public void updateConfiguration(final MongoDBRdfConfiguration conf) {
+ // mongoClient = super.getMongoClient();
+ // conf = new MongoDBRdfConfiguration();
+ // conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MongoGeoTemporalIndexIT.class.getSimpleName() + "_" + COUNTER.getAndIncrement());
+ // conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya");
+ // conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya");
+ // conf.setBoolean(ConfigUtils.USE_MONGO, true);
+ conf.setBoolean(OptionalConfigUtils.USE_GEOTEMPORAL, true);
+
+ // conn = new SailRepository(sail).getConnection();
+ // conn.begin();
+
+ }
+
+ @Test
+ public void ensureInEventStore_Test() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepository repo = new SailRepository(sail);
+ try(final MongoGeoTemporalIndexer indexer = new MongoGeoTemporalIndexer()) {
+ indexer.setConf(conf);
+ indexer.init();
+
+ addStatements(repo.getConnection());
+ final EventStorage events = indexer.getEventStorage();
+ final RyaURI subject = new RyaURI("urn:event1");
+ final Optional<Event> event = events.get(subject);
+ assertTrue(event.isPresent());
+ } finally {
+ sail.shutDown();
+ }
+ }
+
+ @Test
+ public void constantSubjQuery_Test() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+
+ try {
+ final String query =
+ "PREFIX time: <http://www.w3.org/2006/time#> \n"
+ + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"
+ + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>"
+ + "SELECT * "
+ + "WHERE { "
+ + " <urn:event1> time:atTime ?time . "
+ + " <urn:event1> geo:asWKT ?point . "
+ + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) "
+ + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) "
+ + "}";
+
+ final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ final Set<BindingSet> results = new HashSet<>();
+ while(rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ final MapBindingSet expected = new MapBindingSet();
+ expected.addBinding("point", VF.createLiteral("POINT (0 0)"));
+ expected.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
+
+ assertEquals(1, results.size());
+ assertEquals(expected, results.iterator().next());
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ @Test
+ public void variableSubjQuery_Test() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+
+ try {
+ final String query =
+ "PREFIX time: <http://www.w3.org/2006/time#> \n"
+ + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"
+ + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>"
+ + "SELECT * "
+ + "WHERE { "
+ + " ?subj time:atTime ?time . "
+ + " ?subj geo:asWKT ?point . "
+ + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) "
+ + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) "
+ + "}";
+
+ final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ final List<BindingSet> results = new ArrayList<>();
+ while(rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ final MapBindingSet expected1 = new MapBindingSet();
+ expected1.addBinding("point", VF.createLiteral("POINT (0 0)"));
+ expected1.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
+
+ final MapBindingSet expected2 = new MapBindingSet();
+ expected2.addBinding("point", VF.createLiteral("POINT (1 1)"));
+ expected2.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
+
+ assertEquals(2, results.size());
+ assertEquals(expected1, results.get(0));
+ assertEquals(expected2, results.get(1));
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ private void addStatements(final SailRepositoryConnection conn) throws Exception {
+ URI subject = VF.createURI("urn:event1");
+ final URI predicate = VF.createURI(URI_PROPERTY_AT_TIME);
+ Value object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
+ conn.add(VF.createStatement(subject, predicate, object));
+
+ object = VF.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object));
+
+ subject = VF.createURI("urn:event2");
+ object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
+ conn.add(VF.createStatement(subject, predicate, object));
+
+ object = VF.createLiteral("Point(1 1)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java
index f35eeb7..f0099c8 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.rya.indexing.geotemporal.model;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.getFilters;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.getSps;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -33,8 +35,8 @@ import org.apache.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE;
import org.apache.rya.indexing.TemporalInstant;
import org.apache.rya.indexing.TemporalInstantRfc3339;
import org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage;
-import org.apache.rya.indexing.geotemporal.mongo.MongoITBase;
import org.apache.rya.indexing.geotemporal.storage.EventStorage;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Test;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
@@ -60,7 +62,7 @@ import info.aduna.iteration.CloseableIteration;
/**
* Unit tests the methods of {@link EventQueryNode}.
*/
-public class EventQueryNodeTest extends MongoITBase {
+public class EventQueryNodeTest extends MongoTestBase {
private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326);
private static final ValueFactory VF = ValueFactoryImpl.getInstance();
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/GeoTemporalMongoDBStorageStrategyTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/GeoTemporalMongoDBStorageStrategyTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/GeoTemporalMongoDBStorageStrategyTest.java
index 4a31599..392d381 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/GeoTemporalMongoDBStorageStrategyTest.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/GeoTemporalMongoDBStorageStrategyTest.java
@@ -28,7 +28,7 @@ import org.apache.rya.indexing.IndexingFunctionRegistry;
import org.apache.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE;
import org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.GeoPolicy;
import org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.TemporalPolicy;
-import org.apache.rya.indexing.geotemporal.GeoTemporalTestBase;
+import org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils;
import org.junit.Before;
import org.junit.Test;
import org.openrdf.model.Resource;
@@ -56,7 +56,7 @@ import com.mongodb.util.JSON;
* @see TemporalPolicy Temporal Filter Functions
* @see GeoPolicy Geo Filter Functions
*/
-public class GeoTemporalMongoDBStorageStrategyTest extends GeoTemporalTestBase {
+public class GeoTemporalMongoDBStorageStrategyTest extends GeoTemporalTestUtils {
private GeoTemporalMongoDBStorageStrategy adapter;
@Before
public void setup() {
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java
index 5b07460..6bd0b6d 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java
@@ -31,6 +31,7 @@ import org.apache.rya.indexing.geotemporal.model.Event;
import org.apache.rya.indexing.geotemporal.storage.EventStorage;
import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventAlreadyExistsException;
import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventStorageException;
+import org.apache.rya.mongodb.MongoTestBase;
import org.joda.time.DateTime;
import org.junit.Test;
@@ -42,7 +43,7 @@ import com.vividsolutions.jts.geom.PrecisionModel;
/**
* Integration tests the methods of {@link MongoEventStorage}.
*/
-public class MongoEventStorageTest extends MongoITBase {
+public class MongoEventStorageTest extends MongoTestBase {
private static final String RYA_INSTANCE_NAME = "testInstance";
private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326);
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java
index f2d0868..9bfe148 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java
@@ -18,6 +18,8 @@
*/
package org.apache.rya.indexing.geotemporal.mongo;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.makeInstant;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.point;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -29,6 +31,7 @@ import org.apache.rya.indexing.GeoConstants;
import org.apache.rya.indexing.TemporalInstant;
import org.apache.rya.indexing.geotemporal.model.Event;
import org.apache.rya.indexing.geotemporal.storage.EventStorage;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Before;
import org.junit.Test;
import org.openrdf.model.Resource;
@@ -43,7 +46,7 @@ import com.vividsolutions.jts.geom.Geometry;
/**
* Integration tests the methods of {@link MongoGeoTemporalIndexer}.
*/
-public class MongoGeoTemporalIndexerIT extends MongoITBase {
+public class MongoGeoTemporalIndexerIT extends MongoTestBase {
private MongoGeoTemporalIndexer indexer;
@Before
@@ -58,7 +61,7 @@ public class MongoGeoTemporalIndexerIT extends MongoITBase {
final RyaStatement geoStmnt = statement(point(0, 0));
final RyaStatement timeStmnt = statement(makeInstant(0));
- final EventStorage store = indexer.getEventStorage(conf);
+ final EventStorage store = indexer.getEventStorage();
indexer.storeStatement(geoStmnt);
Optional<Event> evnt = store.get(geoStmnt.getSubject());
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoITBase.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoITBase.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoITBase.java
deleted file mode 100644
index 2ca2780..0000000
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoITBase.java
+++ /dev/null
@@ -1,64 +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.indexing.geotemporal.mongo;
-
-import org.apache.rya.indexing.accumulo.ConfigUtils;
-import org.apache.rya.indexing.geotemporal.GeoTemporalTestBase;
-import org.apache.rya.indexing.mongodb.MongoIndexingConfiguration;
-import org.apache.rya.mongodb.EmbeddedMongoSingleton;
-import org.junit.After;
-import org.junit.Before;
-
-import com.mongodb.MongoClient;
-
-/**
- * A base class that may be used when implementing Mongo DB integration tests that
- * use the JUnit framework.
- */
-public class MongoITBase extends GeoTemporalTestBase {
-
- private static MongoClient mongoClient = null;
- protected static MongoIndexingConfiguration conf;
-
- @Before
- public void setupTest() throws Exception {
- mongoClient = EmbeddedMongoSingleton.getInstance();
- conf = MongoIndexingConfiguration.builder()
- .setMongoCollectionPrefix("test_")
- .setMongoDBName("testDB")
- .build();
- conf.setBoolean(ConfigUtils.USE_MONGO, true);
- conf.setMongoClient(mongoClient);
- }
-
- @After
- public void cleanupTest() {
- // Remove any DBs that were created by the test.
- for(final String dbName : mongoClient.listDatabaseNames()) {
- mongoClient.dropDatabase(dbName);
- }
- }
-
- /**
- * @return A {@link MongoClient} that is connected to the embedded instance of Mongo DB.
- */
- public MongoClient getMongoClient() {
- return mongoClient;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java
index 81b45d1..4ca6b4c 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
import org.apache.rya.api.domain.RyaStatement;
import org.apache.rya.api.resolver.RdfToRyaConversions;
@@ -31,10 +30,8 @@ import org.apache.rya.indexing.GeoConstants;
import org.apache.rya.indexing.GeoRyaSailFactory;
import org.apache.rya.indexing.accumulo.ConfigUtils;
import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils;
-import org.apache.rya.indexing.geotemporal.mongo.MongoITBase;
-import org.apache.rya.indexing.mongodb.MongoIndexingConfiguration;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.rya.mongodb.MongoDBRdfConfiguration;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Test;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
@@ -48,12 +45,10 @@ import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.QueryLanguage;
import org.openrdf.query.TupleQueryResult;
-import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.repository.sail.SailRepositoryConnection;
import org.openrdf.sail.Sail;
-import com.mongodb.MongoClient;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
@@ -61,238 +56,242 @@ import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.WKTWriter;
-public class MongoGeoIndexerFilterIT extends MongoITBase {
- private static final GeometryFactory GF = new GeometryFactory();
- private static final Geometry WASHINGTON_MONUMENT = GF.createPoint(new Coordinate(38.8895, 77.0353));
- private static final Geometry LINCOLN_MEMORIAL = GF.createPoint(new Coordinate(38.8893, 77.0502));
- private static final Geometry CAPITAL_BUILDING = GF.createPoint(new Coordinate(38.8899, 77.0091));
- private static final Geometry WHITE_HOUSE = GF.createPoint(new Coordinate(38.8977, 77.0365));
-
- private static final AtomicInteger COUNTER = new AtomicInteger(1);
-
- private MongoClient client;
- private Sail sail;
- private SailRepositoryConnection conn;
- @Before
- public void before() throws Exception {
- final MongoIndexingConfiguration indxrConf = MongoIndexingConfiguration.builder()
- .setMongoCollectionPrefix("rya_")
- .setMongoDBName(MongoGeoIndexerFilterIT.class.getSimpleName() + "_" + COUNTER.getAndIncrement())
- .setUseMongoFreetextIndex(false)
- .setUseMongoTemporalIndex(false)
- .build();
-
- client = super.getMongoClient();
- indxrConf.setBoolean(OptionalConfigUtils.USE_GEO, true);
- indxrConf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
- indxrConf.setBoolean(ConfigUtils.USE_MONGO, true);
- indxrConf.setMongoClient(client);
-
- sail = GeoRyaSailFactory.getInstance(indxrConf);
- conn = new SailRepository(sail).getConnection();
- }
-
- @After
- public void after() throws RepositoryException {
- if(conn != null) {
- conn.close();
- }
- }
-
- @Test
- public void nearHappyUsesTest() throws Exception {
- populateRya();
-
- //Only captial
- String query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 0.0, 2000))"
- + "}";
-
- TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- final List<BindingSet> results = new ArrayList<>();
- while (rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- assertEquals(1, results.size());
- assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(0)));
-
- //all but capital
- query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000))"
- + "}";
-
- rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- results.clear();
- while (rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- assertEquals(3, results.size());
- assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
- assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
- assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
-
- // all of them
- query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 6000, 000))"
- + "}";
-
- rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- results.clear();
- while (rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- assertEquals(4, results.size());
- assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
- assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
- assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
- assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
-
- // donut, only 2
- query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000, 100))"
- + "}";
-
- rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- results.clear();
- while (rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- assertEquals(2, results.size());
- assertEquals(WHITE_HOUSE, bindingToGeo(results.get(0)));
- assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(1)));
-
- // all of them
- query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral))"
- + "}";
- rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- results.clear();
- while (rez.hasNext()) {
- final BindingSet bs = rez.next();
- results.add(bs);
- }
- assertEquals(4, results.size());
- assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
- assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
- assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
- assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
- }
-
- @Test(expected = MalformedQueryException.class)
- public void near_invalidDistance() throws Exception {
- populateRya();
-
- //Only captial
- final String query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, distance))"
- + "}";
-
- conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void near_negativeDistance() throws Exception {
- populateRya();
-
- //Only captial
- final String query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, -100))"
- + "}";
-
- final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- while(rez.hasNext()) {
- rez.next();
- }
- }
-
- @Test(expected = QueryEvaluationException.class)
- public void tooManyArgumentsTest() throws Exception {
- populateRya();
-
- // Only captial
- final String query =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "SELECT * \n" //
- + "WHERE { \n" + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 100, 1000, 10))"
- + "}";
-
- conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
- }
-
- private void populateRya() throws Exception {
- // geo 2x2 points
- conn.begin();
- RyaStatement stmnt = statement(WASHINGTON_MONUMENT);
- Statement statement = RyaToRdfConversions.convertStatement(stmnt);
- conn.add(statement);
-
- stmnt = statement(LINCOLN_MEMORIAL);
- statement = RyaToRdfConversions.convertStatement(stmnt);
- conn.add(statement);
-
- stmnt = statement(CAPITAL_BUILDING);
- statement = RyaToRdfConversions.convertStatement(stmnt);
- conn.add(statement);
-
- stmnt = statement(WHITE_HOUSE);
- statement = RyaToRdfConversions.convertStatement(stmnt);
- conn.add(statement);
- conn.commit();
- }
-
- private static Geometry bindingToGeo(final BindingSet bs) throws ParseException {
- final WKTReader w = new WKTReader();
- return w.read(bs.getValue("point").stringValue());
- }
-
- private static RyaStatement statement(final Geometry geo) {
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("urn:geo");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final WKTWriter w = new WKTWriter();
- final Value object = vf.createLiteral(w.write(geo), GeoConstants.XMLSCHEMA_OGC_WKT);
- return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object));
- }
+public class MongoGeoIndexerFilterIT extends MongoTestBase {
+ private static final GeometryFactory GF = new GeometryFactory();
+ private static final Geometry WASHINGTON_MONUMENT = GF.createPoint(new Coordinate(38.8895, 77.0353));
+ private static final Geometry LINCOLN_MEMORIAL = GF.createPoint(new Coordinate(38.8893, 77.0502));
+ private static final Geometry CAPITAL_BUILDING = GF.createPoint(new Coordinate(38.8899, 77.0091));
+ private static final Geometry WHITE_HOUSE = GF.createPoint(new Coordinate(38.8977, 77.0365));
+
+ @Override
+ public void updateConfiguration(final MongoDBRdfConfiguration conf) {
+ conf.setBoolean(OptionalConfigUtils.USE_GEO, true);
+ conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
+ conf.setBoolean(ConfigUtils.USE_MONGO, true);
+ }
+
+ @Test
+ public void nearHappyUsesTest() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+ try {
+ populateRya(conn);
+
+ //Only captial
+ String query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 0.0, 2000))"
+ + "}";
+
+ TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ final List<BindingSet> results = new ArrayList<>();
+ while (rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ assertEquals(1, results.size());
+ assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(0)));
+
+ //all but capital
+ query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000))"
+ + "}";
+
+ rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ results.clear();
+ while (rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ assertEquals(3, results.size());
+ assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
+ assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
+ assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
+
+ // all of them
+ query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 6000, 000))"
+ + "}";
+
+ rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ results.clear();
+ while (rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ assertEquals(4, results.size());
+ assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
+ assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
+ assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
+ assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
+
+ // donut, only 2
+ query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000, 100))"
+ + "}";
+
+ rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ results.clear();
+ while (rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ assertEquals(2, results.size());
+ assertEquals(WHITE_HOUSE, bindingToGeo(results.get(0)));
+ assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(1)));
+
+ // all of them
+ query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral))"
+ + "}";
+ rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ results.clear();
+ while (rez.hasNext()) {
+ final BindingSet bs = rez.next();
+ results.add(bs);
+ }
+ assertEquals(4, results.size());
+ assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
+ assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
+ assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
+ assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ @Test(expected = MalformedQueryException.class)
+ public void near_invalidDistance() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+ try {
+ populateRya(conn);
+
+ //Only captial
+ final String query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, distance))"
+ + "}";
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void near_negativeDistance() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+ try {
+ populateRya(conn);
+
+ //Only captial
+ final String query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, -100))"
+ + "}";
+
+ final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ while(rez.hasNext()) {
+ rez.next();
+ }
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ @Test(expected = QueryEvaluationException.class)
+ public void tooManyArgumentsTest() throws Exception {
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+ try {
+ populateRya(conn);
+
+ // Only captial
+ final String query =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "SELECT * \n" //
+ + "WHERE { \n" + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 100, 1000, 10))"
+ + "}";
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
+ }
+
+ private void populateRya(final SailRepositoryConnection conn) throws Exception {
+ // geo 2x2 points
+ conn.begin();
+ RyaStatement stmnt = statement(WASHINGTON_MONUMENT);
+ Statement statement = RyaToRdfConversions.convertStatement(stmnt);
+ conn.add(statement);
+
+ stmnt = statement(LINCOLN_MEMORIAL);
+ statement = RyaToRdfConversions.convertStatement(stmnt);
+ conn.add(statement);
+
+ stmnt = statement(CAPITAL_BUILDING);
+ statement = RyaToRdfConversions.convertStatement(stmnt);
+ conn.add(statement);
+
+ stmnt = statement(WHITE_HOUSE);
+ statement = RyaToRdfConversions.convertStatement(stmnt);
+ conn.add(statement);
+ conn.commit();
+ }
+
+ private static Geometry bindingToGeo(final BindingSet bs) throws ParseException {
+ final WKTReader w = new WKTReader();
+ return w.read(bs.getValue("point").stringValue());
+ }
+
+ private static RyaStatement statement(final Geometry geo) {
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("urn:geo");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final WKTWriter w = new WKTWriter();
+ final Value object = vf.createLiteral(w.write(geo), GeoConstants.XMLSCHEMA_OGC_WKT);
+ return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
index 57873fd..2d09a6c 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
@@ -19,6 +19,10 @@ package org.apache.rya.indexing.mongo;
*/
import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.bbox;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.line;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.point;
+import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.poly;
import java.util.Map;
import java.util.Set;
@@ -29,11 +33,11 @@ import org.apache.rya.api.resolver.RyaToRdfConversions;
import org.apache.rya.indexing.GeoConstants;
import org.apache.rya.indexing.StatementConstraints;
import org.apache.rya.indexing.accumulo.ConfigUtils;
-import org.apache.rya.indexing.geotemporal.mongo.MongoITBase;
import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils;
import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer;
+import org.apache.rya.mongodb.MongoDBRdfConfiguration;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
@@ -46,21 +50,16 @@ import org.openrdf.model.impl.ValueFactoryImpl;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
-import com.vividsolutions.jts.geom.PrecisionModel;
import info.aduna.iteration.CloseableIteration;
/**
* Tests all of the "simple functions" of the geoindexer.
*/
-public class MongoGeoIndexerSfTest extends MongoITBase {
- private static GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
- private static MongoGeoIndexer g;
-
+public class MongoGeoIndexerSfTest extends MongoTestBase {
private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
// Here is the landscape:
@@ -99,19 +98,10 @@ public class MongoGeoIndexerSfTest extends MongoITBase {
names.put(F, "F");
}
- @Before
- public void before() throws Exception {
+ @Override
+ public void updateConfiguration(final MongoDBRdfConfiguration conf) {
conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
conf.set(OptionalConfigUtils.USE_GEO, "true");
-
- g = new MongoGeoIndexer();
- g.initIndexer(conf, super.getMongoClient());
- g.storeStatement(statement(A));
- g.storeStatement(statement(B));
- g.storeStatement(statement(C));
- g.storeStatement(statement(D));
- g.storeStatement(statement(F));
- g.storeStatement(statement(E));
}
private static RyaStatement statement(final Geometry geo) {
@@ -136,18 +126,28 @@ public class MongoGeoIndexerSfTest extends MongoITBase {
@Test
public void testEquals() throws Exception {
- // point
- compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
- compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // line
- compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
- compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // poly
- compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
- compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
+ try(final MongoGeoIndexer g = new MongoGeoIndexer()) {
+ g.setConf(conf);
+ g.init();
+
+ g.storeStatement(statement(A));
+ g.storeStatement(statement(B));
+ g.storeStatement(statement(C));
+ g.storeStatement(statement(D));
+ g.storeStatement(statement(F));
+ g.storeStatement(statement(E));
+ // point
+ compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
+ compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // line
+ compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
+ compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // poly
+ compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
+ compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
}
// @Test
@@ -163,19 +163,19 @@ public class MongoGeoIndexerSfTest extends MongoITBase {
// compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E);
// }
- @Test
- public void testIntersectsPoint() throws Exception {
+// @Test
+// public void testIntersectsPoint() throws Exception {
// This seems like a bug
// compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F);
// compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Test
- public void testIntersectsLine() throws Exception {
+// }
+//
+// @Test
+// public void testIntersectsLine() throws Exception {
// This seems like a bug
// compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E);
// compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
+// }
// @Test
// public void testIntersectsPoly() throws Exception {
@@ -202,10 +202,10 @@ public class MongoGeoIndexerSfTest extends MongoITBase {
// compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
// }
- @Test
- public void testCrossesLine() throws Exception {
+// @Test
+// public void testCrossesLine() throws Exception {
// compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A);
- }
+// }
// @Test
// public void testCrossesPoly() throws Exception {
@@ -229,30 +229,30 @@ public class MongoGeoIndexerSfTest extends MongoITBase {
// compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F);
// }
- @Test
- public void testContainsLine() throws Exception {
+// @Test
+// public void testContainsLine() throws Exception {
// compare(g.queryContains(E, EMPTY_CONSTRAINTS), E);
- }
+// }
// @Test
// public void testContainsPoly() throws Exception {
// compare(g.queryContains(A, EMPTY_CONSTRAINTS), A);
// compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B);
// }
-
- @Test
- public void testOverlapsPoint() throws Exception {
+//
+// @Test
+// public void testOverlapsPoint() throws Exception {
// compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F);
// You cannot have overlapping points
// compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
+// }
- @Test
- public void testOverlapsLine() throws Exception {
+// @Test
+// public void testOverlapsLine() throws Exception {
// compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E);
// You cannot have overlapping lines
// compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
+// }
// @Test
// public void testOverlapsPoly() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
index 93cabc4..0e0fff2 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
@@ -1,6 +1,4 @@
-package org.apache.rya.indexing.mongo;
-
-/*
+/**
* 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
@@ -18,11 +16,12 @@ package org.apache.rya.indexing.mongo;
* specific language governing permissions and limitations
* under the License.
*/
-
-
+package org.apache.rya.indexing.mongo;
import static org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement;
import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.Set;
@@ -30,11 +29,10 @@ import java.util.Set;
import org.apache.rya.indexing.GeoConstants;
import org.apache.rya.indexing.StatementConstraints;
import org.apache.rya.indexing.accumulo.ConfigUtils;
-import org.apache.rya.indexing.geotemporal.mongo.MongoITBase;
import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils;
import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer;
-import org.junit.Assert;
-import org.junit.Before;
+import org.apache.rya.mongodb.MongoDBRdfConfiguration;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Test;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
@@ -54,21 +52,22 @@ import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
-public class MongoGeoIndexerTest extends MongoITBase {
+public class MongoGeoIndexerTest extends MongoTestBase {
private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
- @Before
- public void before() throws Exception {
+ @Override
+ public void updateConfiguration(final MongoDBRdfConfiguration conf) {
conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
conf.set(OptionalConfigUtils.USE_GEO, "true");
}
@Test
public void testRestrictPredicatesSearch() throws Exception {
- conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
@@ -98,16 +97,17 @@ public class MongoGeoIndexerTest extends MongoITBase {
f.flush();
final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
- Assert.assertEquals(2, actual.size());
- Assert.assertTrue(actual.contains(s3));
- Assert.assertTrue(actual.contains(s4));
+ assertEquals(2, actual.size());
+ assertTrue(actual.contains(s3));
+ assertTrue(actual.contains(s4));
}
}
@Test
public void testPrimeMeridianSearch() throws Exception {
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -131,19 +131,19 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
// Test a ring with a hole in it
final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
// test a ring outside the point
final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
}
}
@@ -151,7 +151,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDcSearch() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -166,13 +167,13 @@ public class MongoGeoIndexerTest extends MongoITBase {
final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
// test a ring outside the point
final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
}
}
@@ -180,7 +181,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDeleteSearch() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -198,20 +200,20 @@ public class MongoGeoIndexerTest extends MongoITBase {
final double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
// test a ring that the point would be outside of if not deleted
final double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
// test a ring for the whole world and make sure the point is gone
// Geomesa is a little sensitive around lon 180, so we only go to 179
final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
}
}
@@ -219,7 +221,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDcSearchWithContext() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -236,10 +239,10 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct context
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
// query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
+ assertEquals(Sets.newHashSet(),
getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
}
}
@@ -248,7 +251,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDcSearchWithSubject() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -265,10 +269,10 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct subject
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
+ assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
// query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
}
}
@@ -276,7 +280,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDcSearchWithSubjectAndContext() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -293,15 +298,15 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct context subject
- Assert.assertEquals(Sets.newHashSet(statement),
+ assertEquals(Sets.newHashSet(statement),
getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
// query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
+ assertEquals(Sets.newHashSet(),
getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
// query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
}
}
@@ -309,7 +314,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testDcSearchWithPredicate() throws Exception {
// test a ring around dc
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
@@ -326,11 +332,11 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct Predicate
- Assert.assertEquals(Sets.newHashSet(statement),
+ assertEquals(Sets.newHashSet(statement),
getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
// query with wrong predicate
- Assert.assertEquals(Sets.newHashSet(),
+ assertEquals(Sets.newHashSet(),
getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
}
}
@@ -339,7 +345,8 @@ public class MongoGeoIndexerTest extends MongoITBase {
public void testAntiMeridianSearch() throws Exception {
// verify that a search works if the bounding box crosses the anti meridian
try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, super.getMongoClient());
+ f.setConf(conf);
+ f.init();
final ValueFactory vf = new ValueFactoryImpl();
final Resource context = vf.createURI("foo:context");
@@ -364,7 +371,7 @@ public class MongoGeoIndexerTest extends MongoITBase {
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java
index 5751887..cbb53e5 100644
--- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java
+++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java
@@ -29,10 +29,8 @@ import org.apache.rya.indexing.TemporalInstant;
import org.apache.rya.indexing.TemporalInstantRfc3339;
import org.apache.rya.indexing.accumulo.ConfigUtils;
import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils;
-import org.apache.rya.indexing.mongodb.MongoIndexingConfiguration;
-import org.apache.rya.mongodb.EmbeddedMongoSingleton;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.rya.mongodb.MongoDBRdfConfiguration;
+import org.apache.rya.mongodb.MongoTestBase;
import org.junit.Test;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
@@ -55,89 +53,75 @@ import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.WKTWriter;
-public class MongoIndexerDeleteIT {
- private MongoClient client;
- private Sail sail;
- private SailRepositoryConnection conn;
-
- @Before
- public void before() throws Exception {
- final MongoIndexingConfiguration indxrConf = MongoIndexingConfiguration.builder()
- .setMongoCollectionPrefix("rya_").setMongoDBName("indexerTests")
- .setUseMongoFreetextIndex(true)
- .setUseMongoTemporalIndex(true)
- .setMongoFreeTextPredicates(RDFS.LABEL.stringValue())
- .setMongoTemporalPredicates("Property:atTime")
- .build();
-
- client = EmbeddedMongoSingleton.getInstance();
- indxrConf.setBoolean(OptionalConfigUtils.USE_GEO, true);
- indxrConf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
- indxrConf.setBoolean(ConfigUtils.USE_MONGO, true);
- indxrConf.setMongoClient(client);
-
- sail = GeoRyaSailFactory.getInstance(indxrConf);
- conn = new SailRepository(sail).getConnection();
- conn.begin();
- }
-
- @After
- public void after() throws Exception {
- if (conn != null) {
- conn.clear();
- }
+public class MongoIndexerDeleteIT extends MongoTestBase {
+ @Override
+ public void updateConfiguration(final MongoDBRdfConfiguration conf) {
+ conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, new String[] {RDFS.LABEL.stringValue()});
+ conf.setStrings(ConfigUtils.TEMPORAL_PREDICATES_LIST, new String[] {"Property:atTime"});
+ conf.setBoolean(ConfigUtils.USE_FREETEXT, true);
+ conf.setBoolean(ConfigUtils.USE_TEMPORAL, true);
+ conf.setBoolean(OptionalConfigUtils.USE_GEO, true);
+ conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
}
@Test
public void deleteTest() throws Exception {
- populateRya();
-
- //The extra 1 is from the person type defined in freetext
- assertEquals(8, client.getDatabase("indexerTests").getCollection("rya__triples").count());
- assertEquals(4, client.getDatabase("indexerTests").getCollection("rya_rya_geo").count());
- assertEquals(1, client.getDatabase("indexerTests").getCollection("rya_rya_temporal").count());
- assertEquals(2, client.getDatabase("indexerTests").getCollection("rya_rya_freetext").count());
-
- //free text -- remove one from many
- String delete = "DELETE DATA \n" //
- + "{\n"
- + " <urn:people> <http://www.w3.org/2000/01/rdf-schema#label> \"Alice Palace Hose\" "
- + "}";
- Update update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
- update.execute();
-
- // temporal -- remove one from one
- delete = "DELETE DATA \n" //
- + "{\n"
- + " <foo:time> <Property:atTime> \"0001-02-03T04:05:06Z\" "
- + "}";
-
- update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
- update.execute();
-
- //geo -- remove many from many
- delete =
- "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
- + "DELETE \n" //
- + "{\n"
- + " <urn:geo> geo:asWKT ?point \n"
- + "}"
- + "WHERE { \n"
- + " <urn:geo> geo:asWKT ?point .\n"
- + " FILTER(geof:sfWithin(?point, \"POLYGON((0 0, 2 0, 2 1, 0 1, 0 0))\"^^geo:wktLiteral))"
- + "}";
-
- update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
- update.execute();
-
- assertEquals(2, client.getDatabase("indexerTests").getCollection("rya_rya_geo").count());
- assertEquals(0, client.getDatabase("indexerTests").getCollection("rya_rya_temporal").count());
- assertEquals(1, client.getDatabase("indexerTests").getCollection("rya_rya_freetext").count());
- assertEquals(4, client.getDatabase("indexerTests").getCollection("rya__triples").count());
+ final Sail sail = GeoRyaSailFactory.getInstance(conf);
+ final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
+ try {
+ populateRya(conn);
+ final MongoClient client = conf.getMongoClient();
+
+ //The extra 1 is from the person type defined in freetext
+ assertEquals(8, client.getDatabase(conf.getMongoDBName()).getCollection(conf.getTriplesCollectionName()).count());
+ assertEquals(4, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_geo").count());
+ assertEquals(1, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_temporal").count());
+ assertEquals(2, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_freetext").count());
+
+ //free text -- remove one from many
+ String delete = "DELETE DATA \n" //
+ + "{\n"
+ + " <urn:people> <http://www.w3.org/2000/01/rdf-schema#label> \"Alice Palace Hose\" "
+ + "}";
+ Update update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
+ update.execute();
+
+ // temporal -- remove one from one
+ delete = "DELETE DATA \n" //
+ + "{\n"
+ + " <foo:time> <Property:atTime> \"0001-02-03T04:05:06Z\" "
+ + "}";
+
+ update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
+ update.execute();
+
+ //geo -- remove many from many
+ delete =
+ "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ + "DELETE \n" //
+ + "{\n"
+ + " <urn:geo> geo:asWKT ?point \n"
+ + "}"
+ + "WHERE { \n"
+ + " <urn:geo> geo:asWKT ?point .\n"
+ + " FILTER(geof:sfWithin(?point, \"POLYGON((0 0, 2 0, 2 1, 0 1, 0 0))\"^^geo:wktLiteral))"
+ + "}";
+
+ update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
+ update.execute();
+
+ assertEquals(2, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_geo").count());
+ assertEquals(0, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_temporal").count());
+ assertEquals(1, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_freetext").count());
+ assertEquals(4, client.getDatabase(conf.getMongoDBName()).getCollection(conf.getTriplesCollectionName()).count());
+ } finally {
+ conn.close();
+ sail.shutDown();
+ }
}
- private void populateRya() throws Exception {
+ private void populateRya(final SailRepositoryConnection conn) throws Exception {
final ValueFactory VF = new ValueFactoryImpl();
// geo 2x2 points
final GeometryFactory GF = new GeometryFactory();
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java
----------------------------------------------------------------------
diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java
index d102bfc..e401589 100644
--- a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java
+++ b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java
@@ -2,12 +2,6 @@ package org.apache.rya.rdftriplestore;
import static com.google.common.base.Preconditions.checkNotNull;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.ValueFactoryImpl;
-import org.openrdf.sail.SailConnection;
-import org.openrdf.sail.SailException;
-import org.openrdf.sail.helpers.SailBase;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -37,6 +31,11 @@ import org.apache.rya.api.persist.joinselect.SelectivityEvalDAO;
import org.apache.rya.rdftriplestore.inference.InferenceEngine;
import org.apache.rya.rdftriplestore.namespace.NamespaceManager;
import org.apache.rya.rdftriplestore.provenance.ProvenanceCollector;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ValueFactoryImpl;
+import org.openrdf.sail.SailConnection;
+import org.openrdf.sail.SailException;
+import org.openrdf.sail.helpers.SailBase;
public class RdfCloudTripleStore extends SailBase {
@@ -53,7 +52,7 @@ public class RdfCloudTripleStore extends SailBase {
@Override
protected SailConnection getConnectionInternal() throws SailException {
- return new RdfCloudTripleStoreConnection(this, conf.clone(), vf);
+ return new RdfCloudTripleStoreConnection(this, conf, vf);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/17cebae3/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java
----------------------------------------------------------------------
diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java
index 921acaa..eaf3033 100644
--- a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java
+++ b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStoreConnection.java
@@ -284,8 +284,8 @@ public class RdfCloudTripleStoreConnection extends SailConnectionBase {
}
try {
- final List<Class<QueryOptimizer>> optimizers = queryConf.getOptimizers();
- final Class<QueryOptimizer> pcjOptimizer = queryConf.getPcjOptimizer();
+ final List<Class<QueryOptimizer>> optimizers = conf.getOptimizers();
+ final Class<QueryOptimizer> pcjOptimizer = conf.getPcjOptimizer();
if(pcjOptimizer != null) {
QueryOptimizer opt = null;
@@ -304,7 +304,7 @@ public class RdfCloudTripleStoreConnection extends SailConnectionBase {
}
final ParallelEvaluationStrategyImpl strategy = new ParallelEvaluationStrategyImpl(
- new StoreTripleSource(queryConf, ryaDAO), inferenceEngine, dataset, queryConf);
+ new StoreTripleSource(conf, ryaDAO), inferenceEngine, dataset, queryConf);
(new BindingAssigner()).optimize(tupleExpr, dataset, bindings);
(new ConstantOptimizer(strategy)).optimize(tupleExpr, dataset,