Github user GERey commented on a diff in the pull request:
https://github.com/apache/incubator-usergrid/pull/103#discussion_r20669882
--- Diff:
stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java ---
@@ -48,168 +44,342 @@ public GeoIT() {
}
- @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 );
+ EntityManager em = app.getEntityManager();
+ assertNotNull( em );
- // create user at a location
- Map<String, Object> properties = new LinkedHashMap<String,
Object>() {{
- put( "username", "edanuff" );
- put( "email", "[email protected]" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 37.776753 );
- put("longitude", -122.407846 );
- }} );
- }};
+ // create user at a location
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "username", "edanuff" );
+ put( "email", "[email protected]" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 37.776753 );
+ put("longitude", -122.407846 );
+ }} );
+ }};
- Entity user = em.create( "user", properties );
- assertNotNull( user );
+ Entity user = em.create( "user", properties );
+ assertNotNull( user );
- em.refreshIndex();
+ em.refreshIndex();
- // define center point about 300m from that location
- Point center = new Point( 37.774277, -122.404744 );
+ // define center point about 300m from that location
+ Point center = new Point( 37.774277, -122.404744 );
- Query query = Query.fromQL( "select * where location within 200 of
"
- + center.getLat() + "," +
center.getLon());
- Results listResults = em.searchCollection( em.getApplicationRef(),
"users", query );
+ 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() );
+ 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 );
- assertEquals("1 result less than 400m away from center", 1,
listResults.size() );
+ 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();
+ // 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 );
+ 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() );
+ this.dump( listResults );
- // move user and center to new locations
- updatePos( em, user, 37.426373, -122.14108 );
+ // user no longer found with 400m search
+ assertEquals( 0, listResults.size() );
- center = new Point( 37.774277, -122.404744 );
+ // move user and center to new locations
+ updatePos( em, user, 37.426373, -122.14108 );
- query = Query.fromQL( "select * where location within 200 of "
- + center.getLat() + "," +
center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(),
"users", query );
+ center = new Point( 37.774277, -122.404744 );
- assertEquals( 0, listResults.size() );
+ query = Query.fromQL( "select * where location within 200 of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users",
query );
- updatePos( em, user, 37.774277, -122.404744 );
+ assertEquals( 0, listResults.size() );
- center = new Point( 37.776753, -122.407846 );
+ updatePos( em, user, 37.774277, -122.404744 );
- query = Query.fromQL( "select * where location within 1000 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
+ assertEquals( 1, listResults.size() );
- query = Query.fromQL( "select * where location within " +
Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(),
"users", query );
+ // check at globally large distance
- assertEquals( 1, listResults.size() );
+ query = Query.fromQL( "select * where location within " +
Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users",
query );
- // create a new entity so we have 2
- LinkedHashMap<String, Object> properties2 = new
LinkedHashMap<String, Object>() {{
- put( "username", "sganyo" );
- put( "email", "[email protected]" );
- put( "location", new LinkedHashMap<String, Object>() {{
- put("latitude", 31.1 );
- put("longitude", 121.2 );
- }} );
- }};
- Entity user2 = em.create( "user", properties2 );
- em.refreshIndex();
- assertNotNull( user2 );
+ assertEquals( 1, listResults.size() );
- query = Query.fromQL( "select * where location within 10000 of "
- + center.getLat() + "," +
center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(),
"users", query );
+ // create a new entity so we have 2
+ LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String,
Object>() {{
+ put( "username", "sganyo" );
+ put( "email", "[email protected]" );
+ put( "location", new LinkedHashMap<String, Object>() {{
+ put("latitude", 31.1 );
+ put("longitude", 121.2 );
+ }} );
+ }};
+ Entity user2 = em.create( "user", properties2 );
+ em.refreshIndex();
+ assertNotNull( user2 );
- assertEquals( 1, listResults.size() );
+ query = Query.fromQL( "select * where location within 10000 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
+ query = Query.fromQL( "select * where location within " +
Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ 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( 2, listResults.size() );
- query = Query.fromQL( "select * where location within " +
Integer.MAX_VALUE + " of "
- + center.getLat() + "," + center.getLon());
- 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( 2, listResults.size() );
+ query = Query.fromQL( "select * where location within " +
Integer.MAX_VALUE + " of "
+ + center.getLat() + "," + center.getLon());
+ listResults = em.searchCollection( em.getApplicationRef(), "users",
query );
- Results emSearchResults = em.searchCollection(
em.getApplicationRef(), "users",
- Query.fromQL( "location within 1000 of 37.776753,
-122.407846" ) );
- assertEquals( 1, emSearchResults.size() );
+ assertEquals( 2, listResults.size() );
- updatePos( em, user, 37.776753, -122.407846 );
+ Results emSearchResults = em.searchCollection( em.getApplicationRef(),
"users",
+ Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
+ assertEquals( 1, emSearchResults.size() );
- center = new Point( 37.428526, -122.140916 );
+ updatePos( em, user, 37.776753, -122.407846 );
- query = Query.fromQL( "select * where location within 1000 of "
- + center.getLat() + "," + center.getLon());
- listResults = em.searchCollection( em.getApplicationRef(),
"users", query );
+ center = new Point( 37.428526, -122.140916 );
+ 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() );
+ assertEquals( 0, listResults.size() );
- properties = new LinkedHashMap<String, Object>();
- properties.put( "name", "Brickhouse" );
- properties.put( "address", "426 Brannan Street" );
- properties.put( "location", getLocation( 37.779632, -122.395131 )
);
+ emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+ Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
+ assertEquals( 0, emSearchResults.size() );
- Entity restaurant = em.create( "restaurant", properties );
- assertNotNull( restaurant );
+ properties = new LinkedHashMap<String, Object>();
+ properties.put( "name", "Brickhouse" );
+ properties.put( "address", "426 Brannan Street" );
+ properties.put( "location", getLocation( 37.779632, -122.395131 ) );
- em.createConnection( user, "likes", restaurant );
+ Entity restaurant = em.create( "restaurant", properties );
+ assertNotNull( restaurant );
- em.refreshIndex();
+ em.createConnection( user, "likes", restaurant );
+
+ em.refreshIndex();
- emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 2000 of 37.776753,
-122.407846" ).setConnectionType( "likes" ) );
- assertEquals( 1, emSearchResults.size() );
+ emSearchResults = em.searchConnectedEntities( user,
+ Query.fromQL( "location within 2000 of 37.776753, -122.407846"
).setConnectionType( "likes" ) );
+ assertEquals( 1, emSearchResults.size() );
- emSearchResults = em.searchConnectedEntities( user,
- Query.fromQL( "location within 1000 of 37.776753,
-122.407846" ).setConnectionType( "likes" ) );
- assertEquals( 0, emSearchResults.size() );
+ emSearchResults = em.searchConnectedEntities( user,
+ Query.fromQL( "location within 1000 of 37.776753, -122.407846"
).setConnectionType( "likes" ) );
+ assertEquals( 0, emSearchResults.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 );
+
+ em.refreshIndex();
+
+ Point center = new Point( 37.776753, -122.407846 );
+
+ 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", 0,
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() );
+
+ }
+ @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() );
+
+ }
+ @Test
+ public void testGeo4() throws Exception {
--- End diff --
While a really good test, using local external resources this test took me
about 10+ min alone. Maybe we can tone it down for acceptance ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---