You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/12/04 23:39:32 UTC
[1/7] incubator-usergrid git commit: [APIBAAS-1394]Cleaned up GeoIT
tests
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o 7645a7910 -> c4973e939
[APIBAAS-1394]Cleaned up GeoIT tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/72fe1730
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/72fe1730
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/72fe1730
Branch: refs/heads/two-dot-o
Commit: 72fe17307db93a5980ddc7bd233ed1ec72855c11
Parents: 7645a79
Author: ryan bridges <rb...@apigee.com>
Authored: Mon Dec 1 10:36:43 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:21:46 2014 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/persistence/GeoIT.java | 616 +++++++++----------
1 file changed, 305 insertions(+), 311 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/72fe1730/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index ad30064..d8c8b45 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -17,13 +17,10 @@
package org.apache.usergrid.persistence;
+import java.util.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import org.apache.usergrid.persistence.model.field.value.Location;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,372 +39,370 @@ import static org.junit.Assert.assertTrue;
@Concurrent()
public class GeoIT extends AbstractCoreIT {
private static final Logger LOG = LoggerFactory.getLogger( GeoIT.class );
-
-
- public GeoIT() {
+ /*
+ A list of concrete entities with locations to be used for geoQuery tests
+ NOTE: Adding or removing items from this list could affect test outcome!!!
+ */
+ int NEARBY_RADIUS=10000;
+ int CIRCUMFERENCE_OF_THE_EARTH=40000000;
+ private static List<Map<String, Object>> LOCATION_PROPERTIES = new ArrayList<Map<String, Object>>();
+ static {
+ LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
+ put( "name", "norwest" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", -33.746369 );
+ put("longitude", 150.952183 );
+ }} );
+ }});
+ LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
+ put( "type", "store" );
+ put( "name", "ashfield" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", -33.889058 );
+ put("longitude", 151.124024 );
+ }} );
+ }});
+ }
+ public GeoIT() throws Exception{
super();
+// loadGeolocationTestEntities();
}
- @Test
- public void testGeo() throws Exception {
- LOG.info("GeoIT.testGeo");
+ @Test
+ public void testGeo() throws Exception {
+ LOG.info( "GeoIT.testGeo" );
- EntityManager em = app.getEntityManager();
- assertNotNull(em);
-
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put("username", "edanuff");
- put("email", "ed@anuff.com");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", 37.776753);
- put("longitude", -122.407846);
- }
- });
- }
- };
- Entity user = em.create("user", properties);
- assertNotNull(user);
- em.refreshIndex();
- // define center point about 300m from that location
- Point center = new Point(37.774277, -122.404744);
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
- Query query = Query.fromQL("select * where location within 200 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ // create user at a location
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "username", "edanuff" );
+ put( "email", "ed@anuff.com" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753 );
+ put("longitude", -122.407846 );
+ }} );
+ }};
- assertEquals("No results less than 200m away from center", 0, listResults.size());
+ Entity user = em.create( "user", properties );
+ assertNotNull( user );
- query = Query.fromQL("select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ em.refreshIndex();
- this.dump(listResults);
+ // define center point about 300m from that location
+ Point center = new Point( 37.774277, -122.404744 );
- assertEquals("1 result less than 400m away from center", 1, listResults.size());
+ Query query = Query.fromQL( "select * where location within 200 of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- // remove location from user
- properties.remove("location");
- em.updateProperties(user, properties);
- em.refreshIndex();
+ assertEquals("No results less than 200m away from center", 0, listResults.size() );
- query = Query.fromQL("select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ query = Query.fromQL( "select * where location within 400 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- this.dump(listResults);
+ this.dump( listResults );
- // user no longer found with 400m search
- assertEquals(0, listResults.size());
+ assertEquals("1 result less than 400m away from center", 1, listResults.size() );
- // move user and center to new locations
- updatePos(em, user, 37.426373, -122.14108);
+ // remove location from user
+ properties.remove("location");
+ em.updateProperties(user, properties);
+ em.refreshIndex();
- center = new Point(37.774277, -122.404744);
+ query = Query.fromQL( "select * where location within 400 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- query = Query.fromQL("select * where location within 200 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ this.dump( listResults );
- assertEquals(0, listResults.size());
+ // user no longer found with 400m search
+ assertEquals( 0, listResults.size() );
- updatePos(em, user, 37.774277, -122.404744);
+ // move user and center to new locations
+ updatePos( em, user, 37.426373, -122.14108 );
- center = new Point(37.776753, -122.407846);
+ center = new Point( 37.774277, -122.404744 );
- query = Query.fromQL("select * where location within 1000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ query = Query.fromQL( "select * where location within 200 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- assertEquals(1, listResults.size());
+ assertEquals( 0, listResults.size() );
- // check at globally large distance
- query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
-
- assertEquals(1, listResults.size());
-
- // create a new entity so we have 2
- LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
- put("username", "sganyo");
- put("email", "sganyo@anuff.com");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", 31.1);
- put("longitude", 121.2);
- }
- });
- }
- };
- Entity user2 = em.create("user", properties2);
- em.refreshIndex();
- assertNotNull(user2);
+ updatePos( em, user, 37.774277, -122.404744 );
- query = Query.fromQL("select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ center = new Point( 37.776753, -122.407846 );
- assertEquals(1, listResults.size());
+ query = Query.fromQL( "select * where location within 1000 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- // check at globally large distance
- query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals( 1, listResults.size() );
- assertEquals(2, listResults.size());
+ // check at globally large distance
- // check at globally large distance (center point close to other entity)
- center = new Point(31.14, 121.27);
+ query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals( 1, listResults.size() );
- assertEquals(2, listResults.size());
+ // create a new entity so we have 2
+ LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
+ put( "username", "sganyo" );
+ put( "email", "sganyo@anuff.com" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 31.1 );
+ put("longitude", 121.2 );
+ }} );
+ }};
+ Entity user2 = em.create( "user", properties2 );
+ em.refreshIndex();
+ assertNotNull( user2 );
- Results emSearchResults = em.searchCollection(em.getApplicationRef(), "users",
- Query.fromQL("location within 1000 of 37.776753, -122.407846"));
- assertEquals(1, emSearchResults.size());
+ query = Query.fromQL( "select * where location within 10000 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- updatePos(em, user, 37.776753, -122.407846);
+ assertEquals( 1, listResults.size() );
- center = new Point(37.428526, -122.140916);
+ // check at globally large distance
+ query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- query = Query.fromQL("select * where location within 1000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals( 2, listResults.size() );
- assertEquals(0, listResults.size());
+ // check at globally large distance (center point close to other entity)
+ center = new Point( 31.14, 121.27 );
- emSearchResults = em.searchCollection(em.getApplicationRef(), "users",
- Query.fromQL("location within 1000 of 37.428526, -122.140916"));
- assertEquals(0, emSearchResults.size());
+ query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- properties = new LinkedHashMap<String, Object>();
- properties.put("name", "Brickhouse");
- properties.put("address", "426 Brannan Street");
- properties.put("location", getLocation(37.779632, -122.395131));
+ assertEquals( 2, listResults.size() );
- Entity restaurant = em.create("restaurant", properties);
- assertNotNull(restaurant);
+ Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+ Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
+ assertEquals( 1, emSearchResults.size() );
- em.createConnection(user, "likes", restaurant);
+ updatePos( em, user, 37.776753, -122.407846 );
- em.refreshIndex();
+ center = new Point( 37.428526, -122.140916 );
- emSearchResults = em.searchConnectedEntities(user,
- Query.fromQL("location within 2000 of 37.776753, -122.407846").setConnectionType("likes"));
- assertEquals(1, emSearchResults.size());
+ query = Query.fromQL( "select * where location within 1000 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- emSearchResults = em.searchConnectedEntities(user,
- Query.fromQL("location within 1000 of 37.776753, -122.407846").setConnectionType("likes"));
- assertEquals(0, emSearchResults.size());
- }
+ assertEquals( 0, listResults.size() );
- @Test
- public void testGeo2() throws Exception {
- LOG.info("GeoIT.testGeo2");
- EntityManager em = app.getEntityManager();
- assertNotNull(em);
-
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put("type", "store");
- put("name", "norwest");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.746369);
- put("longitude", 150.952183);
- }
- });
- }
- };
- Entity entity = em.create("store", properties);
- assertNotNull(entity);
- properties = new LinkedHashMap<String, Object>() {{
- put("type", "store");
- put("name", "ashfield");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.889058);
- put("longitude", 151.124024);
- }
- });
- }
- };
- entity = em.create("store", properties);
- assertNotNull(entity);
+ emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+ Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
+ assertEquals( 0, emSearchResults.size() );
- em.refreshIndex();
+ properties = new LinkedHashMap<String, Object>();
+ properties.put( "name", "Brickhouse" );
+ properties.put( "address", "426 Brannan Street" );
+ properties.put( "location", getLocation( 37.779632, -122.395131 ) );
- Point center = new Point(37.776753, -122.407846);
+ Entity restaurant = em.create( "restaurant", properties );
+ assertNotNull( restaurant );
- Query query = Query.fromQL("select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ em.createConnection( user, "likes", restaurant );
- this.dump(listResults);
+ em.refreshIndex();
- assertEquals("Results less than 10000m away from center", 0, listResults.size());
+ emSearchResults = em.searchConnectedEntities( user,
+ Query.fromQL( "location within 2000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+ assertEquals( 1, emSearchResults.size() );
- Query query2 = Query.fromQL("select * where location within 40000000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
+ emSearchResults = em.searchConnectedEntities( user,
+ Query.fromQL( "location within 1000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+ assertEquals( 0, emSearchResults.size() );
+ }
- assertEquals("Results from center point to ridiculously far", 2, listResults.size());
+ /**
+ * Load entities for geo queries
+ * 1. Get an instance of the entity manager
+ * 2. load test entities
+ * 3. refresh the index
+ * 4. return the entity manager
+ */
+ private EntityManager loadGeolocationTestEntities() throws Exception{
+ LOG.info( "GeoIT.loadGeolocationTestEntities" );
+ //1. Get an instance of the entity manager
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ //2. load test entities
+ for (Map<String, Object> location : LOCATION_PROPERTIES) {
+ LOG.info( "Create entity with location '{}'", location.get("name"));
+ Entity entity = em.create("store", location);
+ assertNotNull(entity);
}
-
-
- @Test
- public void testGeo3() throws Exception {
- LOG.info("GeoIT.testGeo3");
- EntityManager em = app.getEntityManager();
- assertNotNull(em);
-
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {
- {
- put("name", "norwest");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.746369);
- put("longitude", 150.952183);
- }
- });
- }
- };
- Entity entity = em.create("store", properties);
- assertNotNull(entity);
- properties = new LinkedHashMap<String, Object>() {
- {
- put("name", "ashfield");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.889058);
- put("longitude", 151.124024);
- }
- });
- }
- };
- entity = em.create("store", properties);
- assertNotNull(entity);
-
- em.refreshIndex();
-
- Point center = new Point(-33.746369, 150.952183);
-
- Query query = Query.fromQL("select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
-
- this.dump(listResults);
-
- assertEquals("Results less than 10000m away from center", 1, listResults.size());
-
- Query query2 = Query.fromQL("select * where location within 40000000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
-
- assertEquals("Results from center point to ridiculously far", 2, listResults.size());
+ //3. refresh the index
+ em.refreshIndex();
+ //4. return the entity manager
+ return em;
+ }
+ /**
+ * Validate loaded entities for geo queries
+ * 1. load test entities
+ * 2. validate the size of the result
+ * 3. verify each entity has geo data
+ */
+ @Test
+ public void testGeolocationEntities() throws Exception{
+// 1. load test entities
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ //2. load test entities
+ for(Map<String, Object> location: LOCATION_PROPERTIES){
+ Entity entity = em.create( "store", location );
+ assertNotNull( entity );
+ LOG.debug("Entity {} created", entity.getProperty("name"));
+ }
+ em.refreshIndex();
+// 2. validate the size of the result
+ Query query = new Query();
+ Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+ assertEquals("total number of 'stores'", LOCATION_PROPERTIES.size(), listResults.size() );
+// 3. verify each entity has geo data
+ for(Entity entity: listResults.entities){
+ Location location=(Location)entity.getProperty("location");
+ assertNotNull(location);
}
+ }
+ @Test
+ /**
+ * Load entities with location data and query them from a far away location
+ * 1. create entities with geo
+ * 2. Query the collection from a point more than 10000m from the locations
+ * and ensure that no entities are returned when restricted to a 10000m radius
+ * 3. Query the collection from a point more than 10000m from the locations
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
+ public void testGeoFromFarAwayLocation() throws Exception {
+ //1
+ EntityManager em = loadGeolocationTestEntities();
+ //2
+ Point center = new Point( 37.776753, -122.407846 );
+ Query query = Query.fromQL( "select * where location within "+NEARBY_RADIUS+" of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+ assertEquals("Results within "+NEARBY_RADIUS+"m from center", 0, listResults.size() );
+ //3
+ Query query2 = Query.fromQL( "select * where location within "+CIRCUMFERENCE_OF_THE_EARTH+" of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
+
+ assertEquals("Results within "+CIRCUMFERENCE_OF_THE_EARTH+"m from center", LOCATION_PROPERTIES.size(), listResults.size() );
+
+ }
+ @Test
+ /**
+ * Load entities with location data and query them from a nearby location
+ * 1. create entities with geo
+ * 2. Query the collection from a point less than 10000m from the locations
+ * and ensure that one entity is returned when restricted to a 10000m radius
+ * 3. Query the collection from a point less than 10000m from the locations
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
+ public void testGeoFromNearbyLocation() throws Exception {
+ LOG.info( "GeoIT.testGeoFromNearbyLocation" );
+ //1
+ EntityManager em = loadGeolocationTestEntities();
+
+ Point center = new Point( -33.746369, 150.952185 );
+ Query query = Query.fromQL( "select * where location within "+NEARBY_RADIUS+" of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+ assertEquals("Results within "+NEARBY_RADIUS+"m from center", 1, listResults.size() );
+ //3
+ query = Query.fromQL( "select * where location within "+CIRCUMFERENCE_OF_THE_EARTH+" of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+ assertEquals("Results within "+CIRCUMFERENCE_OF_THE_EARTH+"m from center", LOCATION_PROPERTIES.size(), listResults.size() );
+ }
+ /**
+ * Load entities with location data and query them from multiple locations
+ * to ensure proper bounds
+ * 1. Create entities with geo
+ * 2. Create a list of points from different geographic areas
+ * 3. Query the collection from each point
+ * and ensure that no entities are returned when restricted to a 10000m radius
+ * 4. Query the collection from each point
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
- @Test
- public void testGeo4() throws Exception {
- LOG.info("GeoIT.testGeo4");
- EntityManager em = app.getEntityManager();
- assertNotNull(em);
-
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put("name", "norwest");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.746369);
- put("longitude", 150.952183);
- }
- });
- }
- };
- Entity entity = em.create("store", properties);
- assertNotNull(entity);
- properties = new LinkedHashMap<String, Object>() {{
- put("name", "ashfield");
- put("location", new LinkedHashMap<String, Object>() {
- {
- put("latitude", -33.889058);
- put("longitude", 151.124024);
- }
- });
- }
- };
- entity = em.create("store", properties);
- assertNotNull(entity);
-
- em.refreshIndex();
-
- List<Point> points = new ArrayList<Point>();
- points.add(new Point(33.746369, -89));//Woodland, MS
- points.add(new Point(33.746369, -91));//Beulah, MS
- points.add(new Point(-1.000000, 102.000000));//Somewhere in Indonesia
- points.add(new Point(-90.000000, 90.000000));//Antarctica
- points.add(new Point(90, 90));//Santa's house
- //and the cartesian product...
- for (int i = -90; i <= 90; i++) {
- for (int j = -180; j <= 180; j++) {
- points.add(new Point(i, j));
- }
- }
- Iterator<Point> pointIterator = points.iterator();
- for (Point p = pointIterator.next(); pointIterator.hasNext(); p = pointIterator.next()) {
- Query query = Query.fromQL("select * where location within 10000 of "
- + p.getLat() + "," + p.getLon());
- Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
-
- this.dump(listResults);
- assertEquals("Results less than 10000m away from center", 0, listResults.size());
-
- query = Query.fromQL("select * where location within 40000000 of "
- + p.getLat() + "," + p.getLon());
- listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
-
- assertEquals("Results from center point to ridiculously far", 2, listResults.size());
-
- }
-
+ @Test
+ public void testGeoFromMultipleLocations() throws Exception {
+ LOG.info( "GeoIT.testGeoFromMultipleLocations" );
+ //1 Create entities with geo
+ EntityManager em = loadGeolocationTestEntities();
+ //2 Create a list of points from different geographic areas
+ List<Point> points = new ArrayList<Point>();
+ points.add(new Point( -90.000000, 90.000000 ));//Antarctica
+ points.add(new Point( 90, 90 ));//Santa's house
+ points.add(new Point( 33.746369,-89 ));//Woodland, MS
+ points.add(new Point( 34.35, 58.22)); //Buenos Aires
+ points.add(new Point( 39.55,116.25));//Beijing, China
+ points.add(new Point( 44.52,20.32)); //Belgrade, Serbia
+ points.add(new Point( -1.000000, 102.000000 ));//Somewhere in Indonesia
+ for(Point center:points){
+ //3 Query the collection from each point
+ // and ensure that no entities are returned when restricted to a 10000m radius
+ Query query = Query.fromQL( "select * where location within 10000 of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+ assertEquals("Results less than 10000m away from center", 0, listResults.size() );
+ //4 Query the collection from each point
+ // and ensure that all entities are returned when the distance is set to the
+ // circumference of the earth
+ Query query2 = Query.fromQL( "select * where location within 40000000 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
+ assertEquals("Results from center point to ridiculously far", LOCATION_PROPERTIES.size(), listResults.size() );
+ }
+ }
+ @Test
+ public void testGeoBadPoints() throws Exception {
+ LOG.info( "GeoIT.testGeoBadPoints" );
+ double[][] vertices= {
+ {-91.000000, 90.000000},
+ {91.000000, 90.000000},
+ {90.000000, 400},
+ {90.000000, -270.000000},
+ {-91.000000, -91.000000}
+ };
+ for (int i=0;i<vertices.length;i++){
+ //bad coordinate. bad! you're supposed to have lat between -90 and 90
+ try {
+ Point p = new Point(vertices[i][0], vertices[i][1]);
+ assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]", false);
+ }catch(java.lang.IllegalArgumentException e){
+ assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]" , true);
+ }
}
- @Test
- public void testGeoBadPoints() throws Exception {
- LOG.info("GeoIT.testGeoBadPoints");
- double[][] vertices = {
- {-91.000000, 90.000000},
- {91.000000, 90.000000},
- {90.000000, 400},
- {90.000000, -270.000000},
- {-91.000000, -91.000000}
- };
- for (int i = 0; i < vertices.length; i++) {
- //bad coordinate. bad! you're supposed to have lat between -90 and 90
- try {
- Point p = new Point(vertices[i][0], vertices[i][1]);
- assertTrue("Bad points should throw an exception ["
- + vertices[i][0] + "," + vertices[i][1] + "]", false);
- } catch (java.lang.IllegalArgumentException e) {
- assertTrue("Bad points should throw an exception ["
- + vertices[i][0] + "," + vertices[i][1] + "]", true);
- }
- }
- }
+
+ }
@Test
@@ -518,7 +513,6 @@ public class GeoIT extends AbstractCoreIT {
assertEquals( numEntities, count );
}
-
@Test
public void testDistanceByLimit() throws Exception {
[5/7] incubator-usergrid git commit: [APIBAAS-1394]Broke up larger
tests into more granular tests.
Posted by sn...@apache.org.
[APIBAAS-1394]Broke up larger tests into more granular tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/afde9434
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/afde9434
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/afde9434
Branch: refs/heads/two-dot-o
Commit: afde9434c02c666c64a666439846c89f0afa0065
Parents: 59fd12d
Author: ryan bridges <rb...@apigee.com>
Authored: Tue Dec 2 17:43:31 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:21:47 2014 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/persistence/GeoIT.java | 273 ++++++++++++-------
1 file changed, 182 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/afde9434/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index d8c8b45..5eaeb26 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -39,12 +39,13 @@ import static org.junit.Assert.assertTrue;
@Concurrent()
public class GeoIT extends AbstractCoreIT {
private static final Logger LOG = LoggerFactory.getLogger( GeoIT.class );
+
+ int NEARBY_RADIUS=10000;
+ int CIRCUMFERENCE_OF_THE_EARTH=40000000;
/*
A list of concrete entities with locations to be used for geoQuery tests
NOTE: Adding or removing items from this list could affect test outcome!!!
*/
- int NEARBY_RADIUS=10000;
- int CIRCUMFERENCE_OF_THE_EARTH=40000000;
private static List<Map<String, Object>> LOCATION_PROPERTIES = new ArrayList<Map<String, Object>>();
static {
LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
@@ -63,19 +64,16 @@ public class GeoIT extends AbstractCoreIT {
}} );
}});
}
+
public GeoIT() throws Exception{
super();
-// loadGeolocationTestEntities();
}
@Test
- public void testGeo() throws Exception {
- LOG.info( "GeoIT.testGeo" );
-
-
-
-
+ public void testMovingTarget() throws Exception {
+ LOG.info( "GeoIT.testMovingTarget" );
+ //Get the EntityManager instance
EntityManager em = app.getEntityManager();
assertNotNull( em );
@@ -97,12 +95,14 @@ public class GeoIT extends AbstractCoreIT {
// define center point about 300m from that location
Point center = new Point( 37.774277, -122.404744 );
+ //Assert that the user is not within 200m of our current location
Query query = Query.fromQL( "select * where location within 200 of "
+ center.getLat() + "," + center.getLon());
Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals("No results less than 200m away from center", 0, listResults.size() );
+ //Assert that the user is within 400m of our current location
query = Query.fromQL( "select * where location within 400 of "
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
@@ -154,6 +154,98 @@ public class GeoIT extends AbstractCoreIT {
assertEquals( 1, listResults.size() );
+ em.delete(user);
+
+
+ }
+ /**
+ * Validate the ability to query multiple users excluded by distance
+ * 1. Create two entities with location
+ * 2. Query with a globally large distance to verify locations
+ * 3. Query from a point near user1 with a distance smaller
+ * than the distance between user1 and user2
+ * 4. Query from a point near user2 with a distance smaller
+ * than the distance between user1 and user2
+ * 5. Test that the user is NOT within 1000m of the entity
+ */
+
+ @Test
+ public void testRemovedLocationQuery() throws Exception {
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "username", "edanuff" );
+ put( "email", "ed@anuff.com" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753 );
+ put("longitude", -122.407846 );
+ }} );
+ }};
+
+ Entity user = em.create( "user", properties );
+ assertNotNull( user );
+ em.refreshIndex();
+
+
+ // define center point about 300m from that location
+ Point center = new Point( 37.774277, -122.404744 );
+
+ //Assert that the user is within 400m of our current location
+ Query query = Query.fromQL( "select * where location within 400 of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+
+ this.dump( listResults );
+
+ assertEquals("1 result less than 400m away from center", 1, listResults.size() );
+
+ // remove location from user
+ properties.remove("location");
+ em.updateProperties(user, properties);
+ em.refreshIndex();
+
+ query = Query.fromQL( "select * where location within 400 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+
+ this.dump( listResults );
+
+ // user no longer found with 400m search
+ assertEquals( 0, listResults.size() );
+
+
+
+ em.delete(user);
+ }
+ /**
+ * Validate the ability to query multiple users excluded by distance
+ * 1. Create two entities with location
+ * 2. Query with a globally large distance to verify locations
+ * 3. Query from a point near user1 with a distance smaller
+ * than the distance between user1 and user2
+ * 4. Query from a point near user2 with a distance smaller
+ * than the distance between user1 and user2
+ * 5. Test that the user is NOT within 1000m of the entity
+ */
+
+ @Test
+ public void testGeoDistanceOfMultipleUsers() throws Exception {
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "username", "edanuff" );
+ put( "email", "ed@anuff.com" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753 );
+ put("longitude", -122.407846 );
+ }} );
+ }};
+
+ Entity user = em.create( "user", properties );
+ assertNotNull( user );
+
// create a new entity so we have 2
LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
put( "username", "sganyo" );
@@ -164,94 +256,90 @@ public class GeoIT extends AbstractCoreIT {
}} );
}};
Entity user2 = em.create( "user", properties2 );
- em.refreshIndex();
assertNotNull( user2 );
+ em.refreshIndex();
- query = Query.fromQL( "select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+ Point center = new Point( 37.776753, -122.407846 );
+// Point center2 = new Point( 31.14, 121.27 );
- assertEquals( 1, listResults.size() );
- // check at globally large distance
- query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+ Query query = Query.fromQL("select * where location within 10000 of "
+ center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- assertEquals( 2, listResults.size() );
+ Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- // check at globally large distance (center point close to other entity)
- center = new Point( 31.14, 121.27 );
+ assertEquals( 1, listResults.size() );
- query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+ // check at globally large distance
+ query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of "
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 2, listResults.size() );
- Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
- Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
- assertEquals( 1, emSearchResults.size() );
updatePos( em, user, 37.776753, -122.407846 );
-
center = new Point( 37.428526, -122.140916 );
-
- query = Query.fromQL( "select * where location within 1000 of "
+ query = Query.fromQL("select * where location within 1000 of "
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 0, listResults.size() );
- emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
- Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
- assertEquals( 0, emSearchResults.size() );
+ em.delete(user);
+ em.delete(user2);
+ }
- properties = new LinkedHashMap<String, Object>();
- properties.put( "name", "Brickhouse" );
- properties.put( "address", "426 Brannan Street" );
- properties.put( "location", getLocation( 37.779632, -122.395131 ) );
+ /**
+ * Validate the ability to query connections within proximity of the users
+ * 1. Create an entity with location
+ * 2. Create a user with location
+ * 3. Create a connection between the user and the entity
+ * 4. Test that the user is within 2000m of the entity
+ * 5. Test that the user is NOT within 1000m of the entity
+ */
+ @Test
+ public void testGeoDistanceOfConnection() throws Exception{
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ //1. Create an entity with location
+ Map<String, Object> restaurantProps = new LinkedHashMap<String, Object>();
+ restaurantProps.put( "name", "Brickhouse" );
+ restaurantProps.put( "address", "426 Brannan Street" );
+ restaurantProps.put( "location", getLocation( 37.779632, -122.395131 ) );
+
+ Entity restaurant = em.create( "restaurant", restaurantProps );
+ assertNotNull(restaurant);
+ //2. Create a user with location
+ Map<String, Object> userProperties = new LinkedHashMap<String, Object>() {{
+ put( "username", "edanuff" );
+ put( "email", "ed@anuff.com" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753 );
+ put("longitude", -122.407846 );
+ }} );
+ }};
- Entity restaurant = em.create( "restaurant", properties );
- assertNotNull( restaurant );
+ Entity user = em.create( "user", userProperties );
+ assertNotNull( user );
- em.createConnection( user, "likes", restaurant );
+// em.refreshIndex();
+ //3. Create a connection between the user and the entity
+ em.createConnection(user, "likes", restaurant);
em.refreshIndex();
-
- emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 2000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+ //4. Test that the user is within 2000m of the entity
+ Results emSearchResults = em.searchConnectedEntities( user,
+ Query.fromQL( "location within 2000 of "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("latitude") +", "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("longitude") ).setConnectionType( "likes" ) );
assertEquals( 1, emSearchResults.size() );
-
+ //5. Test that the user is NOT within 1000m of the entity
emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 1000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+ Query.fromQL( "location within 1000 of "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("latitude") +", "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("longitude") ).setConnectionType( "likes" ) );
assertEquals( 0, emSearchResults.size() );
- }
-
- /**
- * Load entities for geo queries
- * 1. Get an instance of the entity manager
- * 2. load test entities
- * 3. refresh the index
- * 4. return the entity manager
- */
- private EntityManager loadGeolocationTestEntities() throws Exception{
- LOG.info( "GeoIT.loadGeolocationTestEntities" );
- //1. Get an instance of the entity manager
-
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
- //2. load test entities
- for (Map<String, Object> location : LOCATION_PROPERTIES) {
- LOG.info( "Create entity with location '{}'", location.get("name"));
- Entity entity = em.create("store", location);
- assertNotNull(entity);
- }
- //3. refresh the index
- em.refreshIndex();
- //4. return the entity manager
- return em;
+ //cleanup
+ em.delete(user);
+ em.delete(restaurant);
}
/**
* Validate loaded entities for geo queries
@@ -380,32 +468,10 @@ public class GeoIT extends AbstractCoreIT {
assertEquals("Results from center point to ridiculously far", LOCATION_PROPERTIES.size(), listResults.size() );
}
}
- @Test
- public void testGeoBadPoints() throws Exception {
- LOG.info( "GeoIT.testGeoBadPoints" );
- double[][] vertices= {
- {-91.000000, 90.000000},
- {91.000000, 90.000000},
- {90.000000, 400},
- {90.000000, -270.000000},
- {-91.000000, -91.000000}
- };
- for (int i=0;i<vertices.length;i++){
- //bad coordinate. bad! you're supposed to have lat between -90 and 90
- try {
- Point p = new Point(vertices[i][0], vertices[i][1]);
- assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]", false);
- }catch(java.lang.IllegalArgumentException e){
- assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]" , true);
- }
- }
- }
-
-
- @Test
+ @Test
public void testPointPaging() throws Exception {
@@ -704,6 +770,31 @@ public class GeoIT extends AbstractCoreIT {
}
+ /**
+ * Load entities for geo queries
+ * 1. Get an instance of the entity manager
+ * 2. load test entities
+ * 3. refresh the index
+ * 4. return the entity manager
+ */
+ private EntityManager loadGeolocationTestEntities() throws Exception{
+ LOG.info( "GeoIT.loadGeolocationTestEntities" );
+ //1. Get an instance of the entity manager
+
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
+ //2. load test entities
+ for (Map<String, Object> location : LOCATION_PROPERTIES) {
+ LOG.info( "Create entity with location '{}'", location.get("name"));
+ Entity entity = em.create("store", location);
+ assertNotNull(entity);
+ }
+ //3. refresh the index
+ em.refreshIndex();
+ //4. return the entity manager
+ return em;
+ }
+
public Map<String, Object> getLocation( double latitude, double longitude ) throws Exception {
Map<String, Object> latlong = new LinkedHashMap<String, Object>();
latlong.put( "latitude", latitude );
[2/7] incubator-usergrid git commit: Cleaned up code formatting
Posted by sn...@apache.org.
Cleaned up code formatting
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/18818f52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/18818f52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/18818f52
Branch: refs/heads/two-dot-o
Commit: 18818f52215f8c15b861f8d9889f2bc5a8ff87f1
Parents: e877a28
Author: ryan bridges <rb...@apigee.com>
Authored: Thu Dec 4 14:16:12 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:21:47 2014 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/persistence/GeoIT.java | 802 ++++++++++---------
1 file changed, 404 insertions(+), 398 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/18818f52/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index aef49ac..f48b88d 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -17,323 +17,330 @@
package org.apache.usergrid.persistence;
-import java.util.*;
-
-import org.apache.usergrid.persistence.model.field.value.Location;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.usergrid.AbstractCoreIT;
import org.apache.usergrid.cassandra.Concurrent;
import org.apache.usergrid.persistence.geo.model.Point;
import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.model.field.value.Location;
import org.apache.usergrid.utils.MapUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
@Concurrent()
public class GeoIT extends AbstractCoreIT {
- private static final Logger LOG = LoggerFactory.getLogger( GeoIT.class );
+ private static final Logger LOG = LoggerFactory.getLogger(GeoIT.class);
- int NEARBY_RADIUS=10000;
- int CIRCUMFERENCE_OF_THE_EARTH=40000000;
+ int NEARBY_RADIUS = 10000;
+ int CIRCUMFERENCE_OF_THE_EARTH = 40000000;
/*
A list of concrete entities with locations to be used for geoQuery tests
NOTE: Adding or removing items from this list could affect test outcome!!!
*/
private static List<Map<String, Object>> LOCATION_PROPERTIES = new ArrayList<Map<String, Object>>();
+
static {
- LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
- put( "name", "norwest" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", -33.746369 );
- put("longitude", 150.952183 );
- }} );
- }});
- LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
- put( "type", "store" );
- put( "name", "ashfield" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", -33.889058 );
- put("longitude", 151.124024 );
- }} );
- }});
+ LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
+ put("name", "norwest");
+ put("location", new LinkedHashMap<String, Object>() {{
+ put("latitude", -33.746369);
+ put("longitude", 150.952183);
+ }});
+ }});
+ LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
+ put("type", "store");
+ put("name", "ashfield");
+ put("location", new LinkedHashMap<String, Object>() {{
+ put("latitude", -33.889058);
+ put("longitude", 151.124024);
+ }});
+ }});
}
- public GeoIT() throws Exception{
+ public GeoIT() throws Exception {
super();
}
- /**
- * Validate the ability to remove an entity's location and remove them from searches
- * 1. Create an entity with location
- * 2. Query with a globally large distance to verify location
- * 3. Remove the entity's location
- * 4. Repeat the query, expecting no results
- */
- @Test
- public void testRemovedLocationQuery() throws Exception {
- //Get the EntityManager instance
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
-
- //1. Create an entity with location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put( "username", "edanuff" );
- put( "email", "ed@anuff.com" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 37.776753 );
- put("longitude", -122.407846 );
- }} );
- }};
- Entity user = em.create( "user", properties );
- assertNotNull( user );
- em.refreshIndex();
-
- //2. Query with a globally large distance to verify location
- Query query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of 0, 0");
- Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- assertEquals("1 result returned", 1, listResults.size() );
-
- //3. Remove the entity's location
- properties.remove("location");
- em.updateProperties(user, properties);
- em.refreshIndex();
-
- //4. Repeat the query, expecting no results
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- assertEquals( 0, listResults.size() );
-
- em.delete(user);
- }
-
- /**
- * Validate the ability to query a moving entity
- * 1. Create an entity with location
- * 2. Query from a point near the entity's location
- * 3. Move the entity farther away from the center point
- * 4. Run the same query again to verify the entity is no longer in the area
- */
- @Test
- public void testMovingTarget() throws Exception {
- LOG.info( "GeoIT.testMovingTarget" );
- //Get the EntityManager instance
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
-
- //1. Create an entity with location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put( "username", "edanuff" );
- put( "email", "ed@anuff.com" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 37.776753 );
- put("longitude", -122.407846 );
- }} );
- }};
- Entity user = em.create( "user", properties );
- assertNotNull( user );
- em.refreshIndex();
-
- Point center = new Point( 37.776753, -122.407846 );
- //2. Query from a point near the entity's location
- Query query = Query.fromQL("select * where location within 100 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- assertEquals( 1, listResults.size() );
-
- //3. Move the entity farther away from the center point
- updatePos( em, user, 37.428526, -122.140916 );
-
- //4. Run the same query again to verify the entity is no longer in the area
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
- assertEquals( 0, listResults.size() );
-
- em.delete(user);
- }
-
- /**
- * Validate the ability to query connections within proximity of the users
- * 1. Create an entity with location
- * 2. Create a user with location
- * 3. Create a connection between the user and the entity
- * 4. Test that the user is within 2000m of the entity
- * 5. Test that the user is NOT within 1000m of the entity
- */
- @Test
- public void testGeoDistanceOfConnection() throws Exception{
- //Get the EntityManager instance
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
- //1. Create an entity with location
- Map<String, Object> restaurantProps = new LinkedHashMap<String, Object>();
- restaurantProps.put( "name", "Brickhouse" );
- restaurantProps.put( "address", "426 Brannan Street" );
- restaurantProps.put( "location", getLocation( 37.779632, -122.395131 ) );
-
- Entity restaurant = em.create( "restaurant", restaurantProps );
- assertNotNull(restaurant);
- //2. Create a user with location
- Map<String, Object> userProperties = new LinkedHashMap<String, Object>() {{
- put( "username", "edanuff" );
- put( "email", "ed@anuff.com" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 37.776753 );
- put("longitude", -122.407846 );
- }} );
- }};
-
- Entity user = em.create( "user", userProperties );
- assertNotNull( user );
-
-// em.refreshIndex();
- //3. Create a connection between the user and the entity
- em.createConnection(user, "likes", restaurant);
-
- em.refreshIndex();
- //4. Test that the user is within 2000m of the entity
- Results emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 2000 of "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("latitude") +", "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("longitude") ).setConnectionType( "likes" ) );
- assertEquals( 1, emSearchResults.size() );
- //5. Test that the user is NOT within 1000m of the entity
- emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 1000 of "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("latitude") +", "+((LinkedHashMap<String, Object>)userProperties.get("location")).get("longitude") ).setConnectionType( "likes" ) );
- assertEquals( 0, emSearchResults.size() );
- //cleanup
- em.delete(user);
- em.delete(restaurant);
- }
- /**
- * Validate loaded entities for geo queries
- * 1. load test entities
- * 2. validate the size of the result
- * 3. verify each entity has geo data
- */
- @Test
- public void testGeolocationEntities() throws Exception{
-// 1. load test entities
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
- //2. load test entities
- for(Map<String, Object> location: LOCATION_PROPERTIES){
- Entity entity = em.create( "store", location );
- assertNotNull( entity );
- LOG.debug("Entity {} created", entity.getProperty("name"));
+ /**
+ * Validate the ability to remove an entity's location and remove them from searches
+ * 1. Create an entity with location
+ * 2. Query with a globally large distance to verify location
+ * 3. Remove the entity's location
+ * 4. Repeat the query, expecting no results
+ */
+ @Test
+ public void testRemovedLocationQuery() throws Exception {
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+
+ //1. Create an entity with location
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put("username", "edanuff");
+ put("email", "ed@anuff.com");
+ put("location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753);
+ put("longitude", -122.407846);
+ }});
+ }};
+ Entity user = em.create("user", properties);
+ assertNotNull(user);
+ em.refreshIndex();
+
+ //2. Query with a globally large distance to verify location
+ Query query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of 0, 0");
+ Results listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals("1 result returned", 1, listResults.size());
+
+ //3. Remove the entity's location
+ properties.remove("location");
+ em.updateProperties(user, properties);
+ em.refreshIndex();
+
+ //4. Repeat the query, expecting no results
+ listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals(0, listResults.size());
+
+ em.delete(user);
}
- em.refreshIndex();
-// 2. validate the size of the result
- Query query = new Query();
- Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
- assertEquals("total number of 'stores'", LOCATION_PROPERTIES.size(), listResults.size() );
-// 3. verify each entity has geo data
- for(Entity entity: listResults.entities){
- Location location=(Location)entity.getProperty("location");
- assertNotNull(location);
+
+ /**
+ * Validate the ability to query a moving entity
+ * 1. Create an entity with location
+ * 2. Query from a point near the entity's location
+ * 3. Move the entity farther away from the center point
+ * 4. Run the same query again to verify the entity is no longer in the area
+ */
+ @Test
+ public void testMovingTarget() throws Exception {
+ LOG.info("GeoIT.testMovingTarget");
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+
+ //1. Create an entity with location
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put("username", "edanuff");
+ put("email", "ed@anuff.com");
+ put("location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753);
+ put("longitude", -122.407846);
+ }});
+ }};
+ Entity user = em.create("user", properties);
+ assertNotNull(user);
+ em.refreshIndex();
+
+ Point center = new Point(37.776753, -122.407846);
+ //2. Query from a point near the entity's location
+ Query query = Query.fromQL("select * where location within 100 of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals(1, listResults.size());
+
+ //3. Move the entity farther away from the center point
+ updatePos(em, user, 37.428526, -122.140916);
+
+ //4. Run the same query again to verify the entity is no longer in the area
+ listResults = em.searchCollection(em.getApplicationRef(), "users", query);
+ assertEquals(0, listResults.size());
+
+ em.delete(user);
}
- }
- @Test
- /**
- * Load entities with location data and query them from a far away location
- * 1. create entities with geo
- * 2. Query the collection from a point more than 10000m from the locations
- * and ensure that no entities are returned when restricted to a 10000m radius
- * 3. Query the collection from a point more than 10000m from the locations
- * and ensure that all entities are returned when the distance is set to the
- * circumference of the earth
- */
- public void testGeoFromFarAwayLocation() throws Exception {
- //1
- EntityManager em = loadGeolocationTestEntities();
- //2
- Point center = new Point( 37.776753, -122.407846 );
- Query query = Query.fromQL( "select * where location within "+NEARBY_RADIUS+" of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
-
- assertEquals("Results within "+NEARBY_RADIUS+"m from center", 0, listResults.size() );
- //3
- Query query2 = Query.fromQL( "select * where location within "+CIRCUMFERENCE_OF_THE_EARTH+" of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
-
- assertEquals("Results within "+CIRCUMFERENCE_OF_THE_EARTH+"m from center", LOCATION_PROPERTIES.size(), listResults.size() );
-
- }
- @Test
- /**
- * Load entities with location data and query them from a nearby location
- * 1. create entities with geo
- * 2. Query the collection from a point less than 10000m from the locations
- * and ensure that one entity is returned when restricted to a 10000m radius
- * 3. Query the collection from a point less than 10000m from the locations
- * and ensure that all entities are returned when the distance is set to the
- * circumference of the earth
- */
- public void testGeoFromNearbyLocation() throws Exception {
- LOG.info( "GeoIT.testGeoFromNearbyLocation" );
- //1
- EntityManager em = loadGeolocationTestEntities();
-
- Point center = new Point( -33.746369, 150.952185 );
- Query query = Query.fromQL( "select * where location within "+NEARBY_RADIUS+" of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
-
- assertEquals("Results within "+NEARBY_RADIUS+"m from center", 1, listResults.size() );
- //3
- query = Query.fromQL( "select * where location within "+CIRCUMFERENCE_OF_THE_EARTH+" of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
-
- assertEquals("Results within "+CIRCUMFERENCE_OF_THE_EARTH+"m from center", LOCATION_PROPERTIES.size(), listResults.size() );
- }
- /**
- * Load entities with location data and query them from multiple locations
- * to ensure proper bounds
- * 1. Create entities with geo
- * 2. Create a list of points from different geographic areas
- * 3. Query the collection from each point
- * and ensure that no entities are returned when restricted to a 10000m radius
- * 4. Query the collection from each point
- * and ensure that all entities are returned when the distance is set to the
- * circumference of the earth
- */
- @Test
- public void testGeoFromMultipleLocations() throws Exception {
- LOG.info( "GeoIT.testGeoFromMultipleLocations" );
- //1 Create entities with geo
- EntityManager em = loadGeolocationTestEntities();
- //2 Create a list of points from different geographic areas
- List<Point> points = new ArrayList<Point>();
- points.add(new Point( -90.000000, 90.000000 ));//Antarctica
- points.add(new Point( 90, 90 ));//Santa's house
- points.add(new Point( 33.746369,-89 ));//Woodland, MS
- points.add(new Point( 34.35, 58.22)); //Buenos Aires
- points.add(new Point( 39.55,116.25));//Beijing, China
- points.add(new Point( 44.52,20.32)); //Belgrade, Serbia
- points.add(new Point( -1.000000, 102.000000 ));//Somewhere in Indonesia
- for(Point center:points){
- //3 Query the collection from each point
- // and ensure that no entities are returned when restricted to a 10000m radius
- Query query = Query.fromQL( "select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
- assertEquals("Results less than 10000m away from center", 0, listResults.size() );
- //4 Query the collection from each point
- // and ensure that all entities are returned when the distance is set to the
- // circumference of the earth
- Query query2 = Query.fromQL( "select * where location within 40000000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
- assertEquals("Results from center point to ridiculously far", LOCATION_PROPERTIES.size(), listResults.size() );
+ /**
+ * Validate the ability to query connections within proximity of the users
+ * 1. Create an entity with location
+ * 2. Create a user with location
+ * 3. Create a connection between the user and the entity
+ * 4. Test that the user is within 2000m of the entity
+ * 5. Test that the user is NOT within 1000m of the entity
+ */
+ @Test
+ public void testGeoDistanceOfConnection() throws Exception {
+ //Get the EntityManager instance
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+ //1. Create an entity with location
+ Map<String, Object> restaurantProps = new LinkedHashMap<String, Object>();
+ restaurantProps.put("name", "Brickhouse");
+ restaurantProps.put("address", "426 Brannan Street");
+ restaurantProps.put("location", getLocation(37.779632, -122.395131));
+
+ Entity restaurant = em.create("restaurant", restaurantProps);
+ assertNotNull(restaurant);
+ //2. Create a user with location
+ Map<String, Object> userProperties = new LinkedHashMap<String, Object>() {{
+ put("username", "edanuff");
+ put("email", "ed@anuff.com");
+ put("location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753);
+ put("longitude", -122.407846);
+ }});
+ }};
+
+ Entity user = em.create("user", userProperties);
+ assertNotNull(user);
+
+ //3. Create a connection between the user and the entity
+ em.createConnection(user, "likes", restaurant);
+
+ em.refreshIndex();
+ //4. Test that the user is within 2000m of the entity
+ Results emSearchResults = em.searchConnectedEntities(user,
+ Query.fromQL("location within 2000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes"));
+ assertEquals(1, emSearchResults.size());
+ //5. Test that the user is NOT within 1000m of the entity
+ emSearchResults = em.searchConnectedEntities(user,
+ Query.fromQL("location within 1000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes"));
+ assertEquals(0, emSearchResults.size());
+ //cleanup
+ em.delete(user);
+ em.delete(restaurant);
}
- }
+ /**
+ * Validate loaded entities for geo queries
+ * 1. load test entities
+ * 2. validate the size of the result
+ * 3. verify each entity has geo data
+ */
+ @Test
+ public void testGeolocationEntities() throws Exception {
+ //1. load test entities
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+ //2. load test entities
+ for (Map<String, Object> location : LOCATION_PROPERTIES) {
+ Entity entity = em.create("store", location);
+ assertNotNull(entity);
+ LOG.debug("Entity {} created", entity.getProperty("name"));
+ }
+ em.refreshIndex();
+ //2. validate the size of the result
+ Query query = new Query();
+ Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("total number of 'stores'", LOCATION_PROPERTIES.size(), listResults.size());
+ //3. verify each entity has geo data
+ for (Entity entity : listResults.entities) {
+ Location location = (Location) entity.getProperty("location");
+ assertNotNull(location);
+ }
+
+ }
+
+ @Test
+ /**
+ * Load entities with location data and query them from a far away location
+ * 1. create entities with geo
+ * 2. Query the collection from a point more than 10000m from the locations
+ * and ensure that no entities are returned when restricted to a 10000m radius
+ * 3. Query the collection from a point more than 10000m from the locations
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
+ public void testGeoFromFarAwayLocation() throws Exception {
+ //1. create entities with geo
+ EntityManager em = loadGeolocationTestEntities();
+ //2. Query the collection from a point more than 10000m from the locations
+ // and ensure that no entities are returned when restricted to a 10000m radius
+ Point center = new Point(37.776753, -122.407846);
+ Query query = Query.fromQL("select * where location within " + NEARBY_RADIUS + " of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+
+ assertEquals("Results within " + NEARBY_RADIUS + "m from center", 0, listResults.size());
+ //3. Query the collection from a point more than 10000m from the locations
+ // and ensure that all entities are returned when the distance is set to the
+ // circumference of the earth
+ Query query2 = Query.fromQL("select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
+
+ assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
+
+ }
+
+ @Test
+ /**
+ * Load entities with location data and query them from a nearby location
+ * 1. create entities with geo
+ * 2. Query the collection from a point less than 10000m from the locations
+ * and ensure that one entity is returned when restricted to a 10000m radius
+ * 3. Query the collection from a point less than 10000m from the locations
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
+ public void testGeoFromNearbyLocation() throws Exception {
+ LOG.info("GeoIT.testGeoFromNearbyLocation");
+ //1. create entities with geo
+ EntityManager em = loadGeolocationTestEntities();
+
+ Point center = new Point(-33.746369, 150.952185);
+
+ //2. Query the collection from a point less than 10000m from the locations
+ // and ensure that one entity is returned when restricted to a 10000m radius
+ Query query = Query.fromQL("select * where location within " + NEARBY_RADIUS + " of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("Results within " + NEARBY_RADIUS + "m from center", 1, listResults.size());
+
+ //3. Query the collection from a point less than 10000m from the locations
+ // and ensure that all entities are returned when the distance is set to the
+ // circumference of the earth
+ query = Query.fromQL("select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
+ }
+
+ /**
+ * Load entities with location data and query them from multiple locations
+ * to ensure proper bounds
+ * 1. Create entities with geo
+ * 2. Create a list of points from different geographic areas
+ * 3. Query the collection from each point
+ * and ensure that no entities are returned when restricted to a 10000m radius
+ * 4. Query the collection from each point
+ * and ensure that all entities are returned when the distance is set to the
+ * circumference of the earth
+ */
+ @Test
+ public void testGeoFromMultipleLocations() throws Exception {
+ LOG.info("GeoIT.testGeoFromMultipleLocations");
+ //1 Create entities with geo
+ EntityManager em = loadGeolocationTestEntities();
+ //2 Create a list of points from different geographic areas
+ List<Point> points = new ArrayList<Point>();
+ points.add(new Point(-90.000000, 90.000000));//Antarctica
+ points.add(new Point(90, 90));//Santa's house
+ points.add(new Point(33.746369, -89));//Woodland, MS
+ points.add(new Point(34.35, 58.22)); //Buenos Aires
+ points.add(new Point(39.55, 116.25));//Beijing, China
+ points.add(new Point(44.52, 20.32)); //Belgrade, Serbia
+ points.add(new Point(-1.000000, 102.000000));//Somewhere in Indonesia
+ for (Point center : points) {
+ //3 Query the collection from each point
+ // and ensure that no entities are returned when restricted to a 10000m radius
+ Query query = Query.fromQL("select * where location within 10000 of "
+ + center.getLat() + "," + center.getLon());
+ Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("Results less than 10000m away from center", 0, listResults.size());
+ //4 Query the collection from each point
+ // and ensure that all entities are returned when the distance is set to the
+ // circumference of the earth
+ Query query2 = Query.fromQL("select * where location within 40000000 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
+ assertEquals("Results from center point to ridiculously far", LOCATION_PROPERTIES.size(), listResults.size());
+ }
+ }
@Test
@@ -341,7 +348,7 @@ public class GeoIT extends AbstractCoreIT {
EntityManager em = app.getEntityManager();
- assertNotNull( em );
+ assertNotNull(em);
// save objects in a diagonal line from -90 -180 to 90 180
@@ -352,21 +359,21 @@ public class GeoIT extends AbstractCoreIT {
float minLongitude = -180;
float maxLongitude = 180;
- float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
+ float lattitudeDelta = (maxLattitude - minLattitude) / numEntities;
- float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+ float longitudeDelta = (maxLongitude - minLongitude) / numEntities;
- for ( int i = 0; i < numEntities; i++ ) {
+ for (int i = 0; i < numEntities; i++) {
float lattitude = minLattitude + lattitudeDelta * i;
float longitude = minLongitude + longitudeDelta * i;
- Map<String, Float> location = MapUtils.hashMap( "latitude", lattitude ).map( "longitude", longitude );
+ Map<String, Float> location = MapUtils.hashMap("latitude", lattitude).map("longitude", longitude);
- Map<String, Object> data = new HashMap<String, Object>( 2 );
- data.put( "name", String.valueOf( i ) );
- data.put( "location", location );
+ Map<String, Object> data = new HashMap<String, Object>(2);
+ data.put("name", String.valueOf(i));
+ data.put("location", location);
- em.create( "store", data );
+ em.create("store", data);
}
em.refreshIndex();
@@ -374,46 +381,46 @@ public class GeoIT extends AbstractCoreIT {
Query query = new Query();
// earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
// just to be save
- query.addFilter( "location within 50000000 of -90, -180" );
- query.setLimit( 100 );
+ query.addFilter("location within 50000000 of -90, -180");
+ query.setLimit(100);
int count = 0;
Results results;
do {
- results = em.searchCollection( em.getApplicationRef(), "stores", query );
+ results = em.searchCollection(em.getApplicationRef(), "stores", query);
- for ( Entity entity : results.getEntities() ) {
- assertEquals( String.valueOf( count ), entity.getName() );
+ for (Entity entity : results.getEntities()) {
+ assertEquals(String.valueOf(count), entity.getName());
count++;
}
// set for the next "page"
- query.setCursor( results.getCursor() );
+ query.setCursor(results.getCursor());
}
- while ( results.getCursor() != null );
+ while (results.getCursor() != null);
// check we got back all 500 entities
- assertEquals( numEntities, count );
+ assertEquals(numEntities, count);
}
@Test
public void testSamePointPaging() throws Exception {
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
// save objects in a diagonal line from -90 -180 to 90 180
int numEntities = 500;
- for ( int i = 0; i < numEntities; i++ ) {
- Map<String, Object> data = new HashMap<String, Object>( 2 );
- data.put( "name", String.valueOf( i ) );
- setPos( data, 0, 0 );
+ for (int i = 0; i < numEntities; i++) {
+ Map<String, Object> data = new HashMap<String, Object>(2);
+ data.put("name", String.valueOf(i));
+ setPos(data, 0, 0);
- em.create( "store", data );
+ em.create("store", data);
}
em.refreshIndex();
@@ -421,36 +428,35 @@ public class GeoIT extends AbstractCoreIT {
Query query = new Query();
// earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
// just to be save
- query.addFilter( "location within 50000000 of 0, 0" );
- query.setLimit( 100 );
+ query.addFilter("location within 50000000 of 0, 0");
+ query.setLimit(100);
int count = 0;
Results results;
do {
- results = em.searchCollection( em.getApplicationRef(), "stores", query );
+ results = em.searchCollection(em.getApplicationRef(), "stores", query);
- for ( Entity entity : results.getEntities() ) {
- assertEquals( String.valueOf( count ), entity.getName() );
+ for (Entity entity : results.getEntities()) {
+ assertEquals(String.valueOf(count), entity.getName());
count++;
}
// set for the next "page"
- query.setCursor( results.getCursor() );
+ query.setCursor(results.getCursor());
}
- while ( results.getCursor() != null );
+ while (results.getCursor() != null);
// check we got back all 500 entities
- assertEquals( numEntities, count );
+ assertEquals(numEntities, count);
}
@Test
public void testDistanceByLimit() throws Exception {
-
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
// save objects in a diagonal line from -90 -180 to 90 180
@@ -461,21 +467,21 @@ public class GeoIT extends AbstractCoreIT {
float minLongitude = -180;
float maxLongitude = 180;
- float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
+ float lattitudeDelta = (maxLattitude - minLattitude) / numEntities;
- float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+ float longitudeDelta = (maxLongitude - minLongitude) / numEntities;
- for ( int i = 0; i < numEntities; i++ ) {
+ for (int i = 0; i < numEntities; i++) {
float lattitude = minLattitude + lattitudeDelta * i;
float longitude = minLongitude + longitudeDelta * i;
- Map<String, Float> location = MapUtils.hashMap( "latitude", lattitude ).map( "longitude", longitude );
+ Map<String, Float> location = MapUtils.hashMap("latitude", lattitude).map("longitude", longitude);
- Map<String, Object> data = new HashMap<String, Object>( 2 );
- data.put( "name", String.valueOf( i ) );
- data.put( "location", location );
+ Map<String, Object> data = new HashMap<String, Object>(2);
+ data.put("name", String.valueOf(i));
+ data.put("location", location);
- em.create( "store", data );
+ em.create("store", data);
}
em.refreshIndex();
@@ -483,23 +489,23 @@ public class GeoIT extends AbstractCoreIT {
Query query = new Query();
// earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
// just to be save
- query.addFilter( "location within 50000000 of -90, -180" );
- query.setLimit( 100 );
+ query.addFilter("location within 50000000 of -90, -180");
+ query.setLimit(100);
int count = 0;
do {
- Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
+ Results results = em.searchCollection(em.getApplicationRef(), "stores", query);
- for ( Entity entity : results.getEntities() ) {
- assertEquals( String.valueOf( count ), entity.getName() );
+ for (Entity entity : results.getEntities()) {
+ assertEquals(String.valueOf(count), entity.getName());
count++;
}
}
- while ( query.getCursor() != null );
+ while (query.getCursor() != null);
// check we got back all 500 entities
- assertEquals( numEntities, count );
+ assertEquals(numEntities, count);
}
@@ -507,25 +513,25 @@ public class GeoIT extends AbstractCoreIT {
public void testGeoWithIntersection() throws Exception {
EntityManager em = app.getEntityManager();
- assertNotNull( em );
+ assertNotNull(em);
int size = 100;
int min = 50;
int max = 90;
- List<Entity> created = new ArrayList<Entity>( size );
+ List<Entity> created = new ArrayList<Entity>(size);
- for ( int i = 0; i < size; i++ ) {
+ for (int i = 0; i < size; i++) {
// save all entities in the same location
- Map<String, Object> data = new HashMap<String, Object>( 2 );
- data.put( "name", String.valueOf( i ) );
- data.put( "index", i );
- setPos( data, 0, 0 );
+ Map<String, Object> data = new HashMap<String, Object>(2);
+ data.put("name", String.valueOf(i));
+ data.put("index", i);
+ setPos(data, 0, 0);
- Entity e = em.create( "store", data );
+ Entity e = em.create("store", data);
- created.add( e );
+ created.add(e);
}
em.refreshIndex();
@@ -535,35 +541,35 @@ public class GeoIT extends AbstractCoreIT {
// String queryString = String.format("select * where location within 100 of 0,
// 0 and index >= %d and index < %d order by index",min, max);
- String queryString = String.format( "select * where index >= %d and index < %d order by index", min, max );
+ String queryString = String.format("select * where index >= %d and index < %d order by index", min, max);
- Query query = Query.fromQL( queryString );
+ Query query = Query.fromQL(queryString);
Results r;
int count = 0;
do {
- r = em.searchCollection( em.getApplicationRef(), "stores", query );
+ r = em.searchCollection(em.getApplicationRef(), "stores", query);
- for ( Entity e : r.getEntities() ) {
- assertEquals( created.get( startDelta + count ), e );
+ for (Entity e : r.getEntities()) {
+ assertEquals(created.get(startDelta + count), e);
count++;
}
- query.setCursor( r.getCursor() );
+ query.setCursor(r.getCursor());
}
- while ( r.hasCursor() );
+ while (r.hasCursor());
- assertEquals( startDelta - ( size - max ), count );
+ assertEquals(startDelta - (size - max), count);
}
@Test
public void testDenseSearch() throws Exception {
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
// save objects in a diagonal line from -90 -180 to 90 180
@@ -574,21 +580,21 @@ public class GeoIT extends AbstractCoreIT {
float minLongitude = 9.89561f;
float maxLongitude = 10.0471f;
- float latitudeDelta = ( maxLatitude - minLatitude ) / numEntities;
+ float latitudeDelta = (maxLatitude - minLatitude) / numEntities;
- float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+ float longitudeDelta = (maxLongitude - minLongitude) / numEntities;
- for ( int i = 0; i < numEntities; i++ ) {
+ for (int i = 0; i < numEntities; i++) {
float latitude = minLatitude + latitudeDelta * i;
float longitude = minLongitude + longitudeDelta * i;
- Map<String, Float> location = MapUtils.hashMap( "latitude", latitude ).map( "longitude", longitude );
+ Map<String, Float> location = MapUtils.hashMap("latitude", latitude).map("longitude", longitude);
- Map<String, Object> data = new HashMap<String, Object>( 2 );
- data.put( "name", String.valueOf( i ) );
- data.put( "location", location );
+ Map<String, Object> data = new HashMap<String, Object>(2);
+ data.put("name", String.valueOf(i));
+ data.put("location", location);
- em.create( "store", data );
+ em.create("store", data);
}
em.refreshIndex();
@@ -602,7 +608,7 @@ public class GeoIT extends AbstractCoreIT {
{
// QuerySlice slice = new QuerySlice( "location", 0 );
- // GeoIterator itr = new GeoIterator( new CollectionGeoSearch(
+ // GeoIterator itr = new GeoIterator( new CollectionGeoSearch(
// em, setup.getIbl(), setup.getCassSvc(), em.getApplicationRef(), "stores" ),
// limit, slice, "location", new Point( lattitude, longitude ), distance );
//
@@ -621,16 +627,16 @@ public class GeoIT extends AbstractCoreIT {
//now test at the EM level, there should be 0 results.
Query query = new Query();
- query.addFilter( "location within 1000 of 48.38626, 9.94175" ); // lat, lon
- query.setLimit( limit );
+ query.addFilter("location within 1000 of 48.38626, 9.94175"); // lat, lon
+ query.setLimit(limit);
- Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
+ Results results = em.searchCollection(em.getApplicationRef(), "stores", query);
- assertEquals( 0, results.size() );
+ assertEquals(0, results.size());
long endTime = System.currentTimeMillis();
- LOG.info( "Runtime took {} milliseconds to search", endTime - startTime );
+ LOG.info("Runtime took {} milliseconds to search", endTime - startTime);
}
}
@@ -642,47 +648,47 @@ public class GeoIT extends AbstractCoreIT {
* 3. refresh the index
* 4. return the entity manager
*/
- private EntityManager loadGeolocationTestEntities() throws Exception{
- LOG.info( "GeoIT.loadGeolocationTestEntities" );
- //1. Get an instance of the entity manager
-
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
- //2. load test entities
- for (Map<String, Object> location : LOCATION_PROPERTIES) {
- LOG.info( "Create entity with location '{}'", location.get("name"));
- Entity entity = em.create("store", location);
- assertNotNull(entity);
- }
- //3. refresh the index
- em.refreshIndex();
- //4. return the entity manager
- return em;
+ private EntityManager loadGeolocationTestEntities() throws Exception {
+ LOG.info("GeoIT.loadGeolocationTestEntities");
+ //1. Get an instance of the entity manager
+
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+ //2. load test entities
+ for (Map<String, Object> location : LOCATION_PROPERTIES) {
+ LOG.info("Create entity with location '{}'", location.get("name"));
+ Entity entity = em.create("store", location);
+ assertNotNull(entity);
+ }
+ //3. refresh the index
+ em.refreshIndex();
+ //4. return the entity manager
+ return em;
}
- public Map<String, Object> getLocation( double latitude, double longitude ) throws Exception {
+ public Map<String, Object> getLocation(double latitude, double longitude) throws Exception {
Map<String, Object> latlong = new LinkedHashMap<String, Object>();
- latlong.put( "latitude", latitude );
- latlong.put( "longitude", longitude );
+ latlong.put("latitude", latitude);
+ latlong.put("longitude", longitude);
return latlong;
}
- public void updatePos( EntityManager em, EntityRef entity, double latitude, double longitude ) throws Exception {
+ public void updatePos(EntityManager em, EntityRef entity, double latitude, double longitude) throws Exception {
Map<String, Object> latlong = new LinkedHashMap<String, Object>();
- latlong.put( "latitude", latitude );
- latlong.put( "longitude", longitude );
+ latlong.put("latitude", latitude);
+ latlong.put("longitude", longitude);
- em.setProperty( entity, "location", latlong );
+ em.setProperty(entity, "location", latlong);
em.refreshIndex();
}
- public void setPos( Map<String, Object> data, double latitude, double longitude ) {
+ public void setPos(Map<String, Object> data, double latitude, double longitude) {
Map<String, Object> latlong = new LinkedHashMap<String, Object>();
- latlong.put( "latitude", latitude );
- latlong.put( "longitude", longitude );
+ latlong.put("latitude", latitude);
+ latlong.put("longitude", longitude);
- data.put( "location", latlong );
+ data.put("location", latlong);
}
}
[3/7] incubator-usergrid git commit: [APIBAAS-1394]Re-adding default
constructor for location field
Posted by sn...@apache.org.
[APIBAAS-1394]Re-adding default constructor for location field
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/59fd12de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/59fd12de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/59fd12de
Branch: refs/heads/two-dot-o
Commit: 59fd12de976c9a9ac00b97a3777ea04652d91ee4
Parents: 72fe173
Author: ryan bridges <rb...@apigee.com>
Authored: Tue Dec 2 12:37:30 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:21:47 2014 -0500
----------------------------------------------------------------------
.../usergrid/persistence/model/field/LocationField.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/59fd12de/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
index 4605e1b..72cfff1 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
@@ -32,6 +32,11 @@ public class LocationField extends AbstractField<Location> {
super( name, value );
}
+ /**
+ * DO NOT DELETE! Jackson needs the default constructor for deserialization!
+ */
+ public LocationField() {
+ }
/**
* Required for Jackson, DO NOT DELETE
@@ -42,7 +47,7 @@ public class LocationField extends AbstractField<Location> {
}
- @Override
+ @Override
public FieldTypeName getTypeName() {
return FieldTypeName.LOCATION;
}
[4/7] incubator-usergrid git commit: Further cleanup of GeoIT tests
Posted by sn...@apache.org.
Further cleanup of GeoIT tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e877a286
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e877a286
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e877a286
Branch: refs/heads/two-dot-o
Commit: e877a286bca7f463831d101abac45b9b98d1ade6
Parents: afde943
Author: ryan bridges <rb...@apigee.com>
Authored: Wed Dec 3 10:11:30 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:21:47 2014 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/persistence/GeoIT.java | 189 +++----------------
1 file changed, 27 insertions(+), 162 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e877a286/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index 5eaeb26..aef49ac 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -69,111 +69,20 @@ public class GeoIT extends AbstractCoreIT {
super();
}
-
- @Test
- public void testMovingTarget() throws Exception {
- LOG.info( "GeoIT.testMovingTarget" );
- //Get the EntityManager instance
- EntityManager em = app.getEntityManager();
- assertNotNull( em );
-
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
- put( "username", "edanuff" );
- put( "email", "ed@anuff.com" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 37.776753 );
- put("longitude", -122.407846 );
- }} );
- }};
-
- Entity user = em.create( "user", properties );
- assertNotNull( user );
-
- em.refreshIndex();
-
- // define center point about 300m from that location
- Point center = new Point( 37.774277, -122.404744 );
-
- //Assert that the user is not within 200m of our current location
- Query query = Query.fromQL( "select * where location within 200 of "
- + center.getLat() + "," + center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- assertEquals("No results less than 200m away from center", 0, listResults.size() );
-
- //Assert that the user is within 400m of our current location
- query = Query.fromQL( "select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- this.dump( listResults );
-
- assertEquals("1 result less than 400m away from center", 1, listResults.size() );
-
- // remove location from user
- properties.remove("location");
- em.updateProperties(user, properties);
- em.refreshIndex();
-
- query = Query.fromQL( "select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- this.dump( listResults );
-
- // user no longer found with 400m search
- assertEquals( 0, listResults.size() );
-
- // move user and center to new locations
- updatePos( em, user, 37.426373, -122.14108 );
-
- center = new Point( 37.774277, -122.404744 );
-
- query = Query.fromQL( "select * where location within 200 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- assertEquals( 0, listResults.size() );
-
- updatePos( em, user, 37.774277, -122.404744 );
-
- center = new Point( 37.776753, -122.407846 );
-
- query = Query.fromQL( "select * where location within 1000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- assertEquals( 1, listResults.size() );
-
- // check at globally large distance
-
- query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- assertEquals( 1, listResults.size() );
-
- em.delete(user);
-
-
- }
/**
- * Validate the ability to query multiple users excluded by distance
- * 1. Create two entities with location
- * 2. Query with a globally large distance to verify locations
- * 3. Query from a point near user1 with a distance smaller
- * than the distance between user1 and user2
- * 4. Query from a point near user2 with a distance smaller
- * than the distance between user1 and user2
- * 5. Test that the user is NOT within 1000m of the entity
+ * Validate the ability to remove an entity's location and remove them from searches
+ * 1. Create an entity with location
+ * 2. Query with a globally large distance to verify location
+ * 3. Remove the entity's location
+ * 4. Repeat the query, expecting no results
*/
-
@Test
public void testRemovedLocationQuery() throws Exception {
//Get the EntityManager instance
EntityManager em = app.getEntityManager();
assertNotNull( em );
+
+ //1. Create an entity with location
Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
put( "username", "edanuff" );
put( "email", "ed@anuff.com" );
@@ -182,58 +91,42 @@ public class GeoIT extends AbstractCoreIT {
put("longitude", -122.407846 );
}} );
}};
-
Entity user = em.create( "user", properties );
assertNotNull( user );
em.refreshIndex();
-
- // define center point about 300m from that location
- Point center = new Point( 37.774277, -122.404744 );
-
- //Assert that the user is within 400m of our current location
- Query query = Query.fromQL( "select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
+ //2. Query with a globally large distance to verify location
+ Query query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of 0, 0");
Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+ assertEquals("1 result returned", 1, listResults.size() );
- this.dump( listResults );
-
- assertEquals("1 result less than 400m away from center", 1, listResults.size() );
-
- // remove location from user
+ //3. Remove the entity's location
properties.remove("location");
em.updateProperties(user, properties);
em.refreshIndex();
- query = Query.fromQL( "select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
+ //4. Repeat the query, expecting no results
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
- this.dump( listResults );
-
- // user no longer found with 400m search
assertEquals( 0, listResults.size() );
-
-
em.delete(user);
}
+
/**
- * Validate the ability to query multiple users excluded by distance
- * 1. Create two entities with location
- * 2. Query with a globally large distance to verify locations
- * 3. Query from a point near user1 with a distance smaller
- * than the distance between user1 and user2
- * 4. Query from a point near user2 with a distance smaller
- * than the distance between user1 and user2
- * 5. Test that the user is NOT within 1000m of the entity
+ * Validate the ability to query a moving entity
+ * 1. Create an entity with location
+ * 2. Query from a point near the entity's location
+ * 3. Move the entity farther away from the center point
+ * 4. Run the same query again to verify the entity is no longer in the area
*/
-
@Test
- public void testGeoDistanceOfMultipleUsers() throws Exception {
+ public void testMovingTarget() throws Exception {
+ LOG.info( "GeoIT.testMovingTarget" );
//Get the EntityManager instance
EntityManager em = app.getEntityManager();
assertNotNull( em );
+
+ //1. Create an entity with location
Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
put( "username", "edanuff" );
put( "email", "ed@anuff.com" );
@@ -242,52 +135,25 @@ public class GeoIT extends AbstractCoreIT {
put("longitude", -122.407846 );
}} );
}};
-
Entity user = em.create( "user", properties );
assertNotNull( user );
-
- // create a new entity so we have 2
- LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
- put( "username", "sganyo" );
- put( "email", "sganyo@anuff.com" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 31.1 );
- put("longitude", 121.2 );
- }} );
- }};
- Entity user2 = em.create( "user", properties2 );
- assertNotNull( user2 );
em.refreshIndex();
Point center = new Point( 37.776753, -122.407846 );
-// Point center2 = new Point( 31.14, 121.27 );
-
-
- Query query = Query.fromQL("select * where location within 10000 of "
+ //2. Query from a point near the entity's location
+ Query query = Query.fromQL("select * where location within 100 of "
+ center.getLat() + "," + center.getLon());
Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
assertEquals( 1, listResults.size() );
- // check at globally large distance
- query = Query.fromQL("select * where location within " + Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+ //3. Move the entity farther away from the center point
+ updatePos( em, user, 37.428526, -122.140916 );
- assertEquals( 2, listResults.size() );
-
-
- updatePos( em, user, 37.776753, -122.407846 );
- center = new Point( 37.428526, -122.140916 );
- query = Query.fromQL("select * where location within 1000 of "
- + center.getLat() + "," + center.getLon());
+ //4. Run the same query again to verify the entity is no longer in the area
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
-
-
assertEquals( 0, listResults.size() );
em.delete(user);
- em.delete(user2);
}
/**
@@ -437,7 +303,6 @@ public class GeoIT extends AbstractCoreIT {
* and ensure that all entities are returned when the distance is set to the
* circumference of the earth
*/
-
@Test
public void testGeoFromMultipleLocations() throws Exception {
LOG.info( "GeoIT.testGeoFromMultipleLocations" );
[7/7] incubator-usergrid git commit: Minor formatting changes only.
Posted by sn...@apache.org.
Minor formatting changes only.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c4973e93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c4973e93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c4973e93
Branch: refs/heads/two-dot-o
Commit: c4973e939b580f973f40b6991e5d1b1dac204181
Parents: eeb22b5
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Dec 4 17:38:14 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Dec 4 17:38:14 2014 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/persistence/GeoIT.java | 41 +++++++++++++-------
1 file changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c4973e93/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index f48b88d..4100cfd 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -17,21 +17,23 @@
package org.apache.usergrid.persistence;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.usergrid.AbstractCoreIT;
import org.apache.usergrid.cassandra.Concurrent;
import org.apache.usergrid.persistence.geo.model.Point;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.model.field.value.Location;
import org.apache.usergrid.utils.MapUtils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
@Concurrent()
public class GeoIT extends AbstractCoreIT {
@@ -39,11 +41,13 @@ public class GeoIT extends AbstractCoreIT {
int NEARBY_RADIUS = 10000;
int CIRCUMFERENCE_OF_THE_EARTH = 40000000;
+
/*
A list of concrete entities with locations to be used for geoQuery tests
NOTE: Adding or removing items from this list could affect test outcome!!!
*/
- private static List<Map<String, Object>> LOCATION_PROPERTIES = new ArrayList<Map<String, Object>>();
+ private static List<Map<String, Object>> LOCATION_PROPERTIES =
+ new ArrayList<Map<String, Object>>();
static {
LOCATION_PROPERTIES.add(new LinkedHashMap<String, Object>() {{
@@ -194,11 +198,17 @@ public class GeoIT extends AbstractCoreIT {
em.refreshIndex();
//4. Test that the user is within 2000m of the entity
Results emSearchResults = em.searchConnectedEntities(user,
- Query.fromQL("location within 2000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes"));
+ Query.fromQL("location within 2000 of "
+ + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude")
+ + ", " + ((LinkedHashMap<String, Object>)
+ userProperties.get("location")).get("longitude")).setConnectionType("likes"));
assertEquals(1, emSearchResults.size());
//5. Test that the user is NOT within 1000m of the entity
emSearchResults = em.searchConnectedEntities(user,
- Query.fromQL("location within 1000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes"));
+ Query.fromQL("location within 1000 of "
+ + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude")
+ + ", " + ((LinkedHashMap<String, Object>)
+ userProperties.get("location")).get("longitude")).setConnectionType("likes"));
assertEquals(0, emSearchResults.size());
//cleanup
em.delete(user);
@@ -263,7 +273,8 @@ public class GeoIT extends AbstractCoreIT {
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
- assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
+ assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH
+ + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
}
@@ -297,7 +308,8 @@ public class GeoIT extends AbstractCoreIT {
query = Query.fromQL("select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of "
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
- assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
+ assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH
+ + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
}
/**
@@ -338,7 +350,8 @@ public class GeoIT extends AbstractCoreIT {
Query query2 = Query.fromQL("select * where location within 40000000 of "
+ center.getLat() + "," + center.getLon());
listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
- assertEquals("Results from center point to ridiculously far", LOCATION_PROPERTIES.size(), listResults.size());
+ assertEquals("Results from center point to ridiculously far",
+ LOCATION_PROPERTIES.size(), listResults.size());
}
}
@@ -541,7 +554,8 @@ public class GeoIT extends AbstractCoreIT {
// String queryString = String.format("select * where location within 100 of 0,
// 0 and index >= %d and index < %d order by index",min, max);
- String queryString = String.format("select * where index >= %d and index < %d order by index", min, max);
+ String queryString = String.format(
+ "select * where index >= %d and index < %d order by index", min, max);
Query query = Query.fromQL(queryString);
@@ -588,7 +602,8 @@ public class GeoIT extends AbstractCoreIT {
float latitude = minLatitude + latitudeDelta * i;
float longitude = minLongitude + longitudeDelta * i;
- Map<String, Float> location = MapUtils.hashMap("latitude", latitude).map("longitude", longitude);
+ Map<String, Float> location =
+ MapUtils.hashMap("latitude", latitude).map("longitude", longitude);
Map<String, Object> data = new HashMap<String, Object>(2);
data.put("name", String.valueOf(i));
[6/7] incubator-usergrid git commit: Revert "[APIBAAS-1394]Re-adding
default constructor for location field" This was added twice during merge.
Posted by sn...@apache.org.
Revert "[APIBAAS-1394]Re-adding default constructor for location field"
This was added twice during merge.
This reverts commit 59fd12de976c9a9ac00b97a3777ea04652d91ee4.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/eeb22b52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/eeb22b52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/eeb22b52
Branch: refs/heads/two-dot-o
Commit: eeb22b52082a576a5939f580db843b9cffdaf1a6
Parents: 18818f5
Author: ryan bridges <rb...@apigee.com>
Authored: Thu Dec 4 14:28:01 2014 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Dec 4 14:28:01 2014 -0500
----------------------------------------------------------------------
.../usergrid/persistence/model/field/LocationField.java | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eeb22b52/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
index 72cfff1..4605e1b 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
@@ -32,11 +32,6 @@ public class LocationField extends AbstractField<Location> {
super( name, value );
}
- /**
- * DO NOT DELETE! Jackson needs the default constructor for deserialization!
- */
- public LocationField() {
- }
/**
* Required for Jackson, DO NOT DELETE
@@ -47,7 +42,7 @@ public class LocationField extends AbstractField<Location> {
}
- @Override
+ @Override
public FieldTypeName getTypeName() {
return FieldTypeName.LOCATION;
}