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/08 22:24:03 UTC
[21/50] [abbrv] incubator-usergrid git commit: Further cleanup of
GeoIT tests
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-events
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" );