You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/03/03 17:41:04 UTC

[1/8] incubator-usergrid git commit: Exclude Codehaus Jackson JAX-RS dependency, plus some better logging & test improvements.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-432 497ac0574 -> 44c098942


Exclude Codehaus Jackson JAX-RS dependency, plus some better logging & test improvements.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2f6edd71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2f6edd71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2f6edd71

Branch: refs/heads/USERGRID-432
Commit: 2f6edd71c1a2a2b4aa09b46de49455668d970cc2
Parents: 80cd97e
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Feb 27 15:42:49 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Feb 27 15:42:49 2015 -0500

----------------------------------------------------------------------
 stack/rest/pom.xml                              |  37 +----
 .../org/apache/usergrid/rest/SimplestTest.java  |  40 ++++-
 .../applications/queries/GeoPagingTest.java     |  44 +++---
 .../endpoints/CollectionEndpoint.java           | 155 ++++++++++++++-----
 .../endpoints/mgmt/OrgResource.java             |  81 +++++++---
 .../rest/test/resource2point0/model/Entity.java |   6 -
 stack/services/pom.xml                          |   6 +
 stack/test-utils/pom.xml                        |  10 +-
 8 files changed, 254 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/pom.xml
----------------------------------------------------------------------
diff --git a/stack/rest/pom.xml b/stack/rest/pom.xml
index 34a3858..3ad58b4 100644
--- a/stack/rest/pom.xml
+++ b/stack/rest/pom.xml
@@ -255,6 +255,11 @@
         </dependency>
 
         <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>com.yammer.metrics</groupId>
             <artifactId>metrics-spring</artifactId>
         </dependency>
@@ -375,38 +380,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.codehaus.jackson</groupId>
-            <artifactId>jackson-xc</artifactId>
-            <version>${jackson-version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <!-- Arquillian deps -->
-
-        <!--<dependency>-->
-            <!--<groupId>org.jboss.arquillian</groupId>-->
-            <!--<artifactId>arquillian-bom</artifactId>-->
-            <!--<version>1.1.7.Final</version>-->
-            <!--<scope>test</scope>-->
-            <!--<type>pom</type>-->
-        <!--</dependency>-->
-
-        <!--<dependency>-->
-            <!--<groupId>org.jboss.arquillian.junit</groupId>-->
-            <!--<artifactId>arquillian-junit-container</artifactId>-->
-            <!--<version>1.1.7.Final</version>-->
-            <!--<scope>test</scope>-->
-        <!--</dependency>-->
-
-        <!--<dependency>-->
-              <!--<groupId>org.jboss.shrinkwrap.resolver</groupId>-->
-              <!--<artifactId>shrinkwrap-resolver-depchain</artifactId>-->
-              <!--<version>2.1.1</version>-->
-              <!--<scope>test</scope>-->
-              <!--<type>pom</type>-->
-        <!--</dependency>-->
-
         <!--  use the external test client.  Just depend on the maven jetty plugin to launch jetty -->
         <dependency>
             <groupId>com.sun.jersey.jersey-test-framework</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
index 6703c1b..27898a9 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
@@ -16,20 +16,56 @@
  */
 package org.apache.usergrid.rest;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.usergrid.persistence.DynamicEntity;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
+import org.apache.usergrid.utils.MapUtils;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+
 /**
- * Simplest test verifies if REST test infrastructure is functioning.
+ * Simple test verifies if REST test infrastructure is functioning.
  */
 public class SimplestTest extends org.apache.usergrid.rest.test.resource2point0.AbstractRestIT {
-    private static final Logger log = LoggerFactory.getLogger(SimplestTest.class);
+    private static final Logger logger = LoggerFactory.getLogger(SimplestTest.class);
 
     @Test
     public void getGetToken() {
         assertNotNull( getAdminToken() );
     }
+
+    @Test
+    public void testEntityPost() {
+
+        Entity cat = new Entity();
+        cat.put("name", "Bertha");
+        cat.put("property1", "value1");
+        Entity savedCat = this.app().collection("cats").post(cat);
+
+        assertEquals( cat.get("property1"), savedCat.get("property1"));
+    }
+
+    @Test
+    public void testEntityPostAndGet() {
+
+        Entity dog = new Entity();
+        dog.put("name", "Pokey");
+        dog.put("property1", "value1");
+        this.app().collection("dogs").post(dog);
+        refreshIndex();
+
+        Collection savedDogs = this.app().collection("dogs").get();
+        Entity savedDog = (Entity)savedDogs.iterator().next();
+        assertEquals( dog.get("property1"), savedDog.get("property1"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index 6c48af2..f9fe5b3 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -152,55 +152,47 @@ public class GeoPagingTest extends AbstractRestIT {
   }
 
   /**
-   * Test that geolocation returns entities with consistent ordering
-   * 1. Create several entities
-   * 2. Query a subset of the entities
-   * 3. Test that the entities were returned in the order expected
-   *
-   * @throws IOException
+   * Test that geo-query returns co-located entities in expected order.
    */
   @Test // USERGRID-1401
   public void groupQueriesWithConsistentResults() throws IOException {
 
     int maxRangeLimit = 20;
-    Entity[] saved = new Entity[maxRangeLimit];
-    //Our base entity that the others will derive from
-    Entity actor = new Entity();
-    actor.put("displayName", "Erin");
-    actor.put("location", new MapUtils.HashMapBuilder<String, Double>()
-        .map("latitude", 37.0)
-        .map("longitude", -75.0));
-    Entity props = new Entity();
+    Entity[] cats = new Entity[maxRangeLimit];
 
-    props.put("actor", actor);
-    props.put("verb", "go");
-    props.put("content", "bragh");
     // 1. Create several entities
     for (int i = 0; i < 20; i++) {
-      String newPath = String.format("/kero" + i);
-      props.put("path", newPath);
-      props.put("ordinal", i);
-      saved[i] = this.app().collection("groups").post(props);
+      Entity cat = new Entity();
+      cat.put("name", "cat" + i);
+      cat.put("location", new MapUtils.HashMapBuilder<String, Double>()
+          .map("latitude", 37.0)
+          .map("longitude", -75.0));
+      cat.put("ordinal", i);
+      cats[i] = cat;
+      this.app().collection("cats").post(cat);
     }
     this.refreshIndex();
 
     QueryParameters params = new QueryParameters();
     for (int consistent = 0; consistent < 20; consistent++) {
+
       // 2. Query a subset of the entities
       String query = String.format(
-          "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d",
-          saved[7].get("ordinal"), saved[10].get("ordinal"));
+          "select * where location within 100 of 37, -75 and ordinal >= %s and ordinal < %s",
+          cats[7].get("ordinal"), cats[10].get("ordinal"));
       params.setQuery(query);
-      Collection collection = this.app().collection("groups").get(params);
+      Collection collection = this.app().collection("cats").get(params);
 
       assertEquals(3, collection.getResponse().getEntityCount());
       List entities = collection.getResponse().getEntities();
+
       // 3. Test that the entities were returned in the order expected
       for (int i = 0; i < 3; i++) {
+
         // shouldn't start at 10 since you're excluding it above in the query, it should return 9,8,7
         Entity entity = (Entity)entities.get(i);
-        Entity savedEntity = saved[7 + i];
-        assertEquals(savedEntity.get("uuid"), entity.get("uuid"));
+        Entity savedEntity = cats[7 + i];
+        assertEquals(savedEntity.get("ordinal"), entity.get("ordinal"));
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
index 6f62a20..5d48524 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
@@ -16,14 +16,19 @@
  */
 package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sun.jersey.api.client.WebResource;
 import org.apache.usergrid.rest.test.resource2point0.model.*;
 import org.apache.usergrid.rest.test.resource2point0.model.Collection;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 import org.apache.usergrid.services.ServiceParameter;
 import org.apache.usergrid.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.*;
 
 
@@ -31,6 +36,7 @@ import java.util.*;
  * //myorg/myapp/mycollection
  */
 public class CollectionEndpoint extends NamedResource {
+    private static final Logger logger = LoggerFactory.getLogger(CollectionEndpoint.class);
 
     protected List<String> acceptHeaders = new ArrayList<String> ();
 
@@ -62,12 +68,13 @@ public class CollectionEndpoint extends NamedResource {
     }
 
     /**
-     *
+     * <pre>
      * app.collection("users").uniqueID("fred").connection("following").collection("users").uniqueID("barney").post();
      * POST /users/fred/following/users/barney?token=<token>
      *
      * app.collection("users").uniqueID("fred").connection().collection("users").uniqueID("barney").post();
      * POST /users/fred/groups/theitcrowd?token=<token>
+     * </pre>
      */
     public CollectionEndpoint collection(final String identifier){
         return new CollectionEndpoint(identifier, context, this);
@@ -76,10 +83,9 @@ public class CollectionEndpoint extends NamedResource {
 
 
     /**
-     * Get a list of entities
-     * @return
+     * Get a list of entities.
      *
-     * @usage
+     * <pre>
      * //with token
      * app.collection("users").get(); //return entity
      * GET /users?token=<token>
@@ -97,6 +103,7 @@ public class CollectionEndpoint extends NamedResource {
      * GET /users
      *
      * collection = app.collection("users").get(collection);
+     * <pre>
      */
     public Collection get(){
         return get(null, true);
@@ -115,26 +122,37 @@ public class CollectionEndpoint extends NamedResource {
 
         WebResource resource  = getResource(useToken);
         resource = addParametersToResource(resource, parameters);
-        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .get(ApiResponse.class);
+
+        // use string type so we can log actual response from server
+        String responseString = resource.type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(acceptHeader)
+            .get(String.class);
+
+        logger.debug("Response from get: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
 
         return new Collection(response);
     }
 
     /**
      * Gets the next page using only default settings with the passed in collection.
-     * @param collection
-     * @param useToken
-     * @return
      *
-     * @usage
+     * <pre>
      * Collection usersCollection =  app.collection("users").get();
      * //iterate through the collection
      * while(usersCollection.hasNext()){
      *  Entity bob = usersCollection.next();
      *     assert("blah",bob.get("words"));
-     * }     *
+     * }
      * usersCollection = app.collections("users").getNextPage(usersCollection.cursor);
+     * </pre>
      */
     //TODO: add queryParameters here
     public Collection getNextPage(Collection collection, QueryParameters passedParameters ,final boolean useToken) {
@@ -159,10 +177,9 @@ public class CollectionEndpoint extends NamedResource {
     }
 
     /**
-     * DELETE on a collection endpoint with query (use DELETE on entity for single entity delete)
-     *
-     * @return ApiResponse
+     * DELETE on a collection endpoint with query (use DELETE on entity for single entity delete).
      *
+     * <pre>
      * //with token
      * app.collection("users").delete(parameters);
      * DELETE /users?ql=select * where created > 0&token=<token>
@@ -173,89 +190,155 @@ public class CollectionEndpoint extends NamedResource {
      *
      * app.collection("users").delete(null, false);
      * DELETE /users
+     * </pre>
      */
     public ApiResponse delete( final QueryParameters parameters ){
         return delete(parameters, true);
     }
 
-    public ApiResponse delete(final QueryParameters parameters, final boolean useToken){
+    public ApiResponse delete(final QueryParameters parameters, final boolean useToken) {
+
         String acceptHeader = MediaType.APPLICATION_JSON;
+
         if (this.acceptHeaders.size() > 0) {
             acceptHeader = StringUtils.join(this.acceptHeaders, ',');
         }
 
         WebResource resource  = getResource(useToken);
         resource = addParametersToResource(resource, parameters);
-        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .delete(ApiResponse.class);
+        return resource.type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(acceptHeader)
+            .delete(ApiResponse.class);
     }
 
     /**
-     * Post an entity to a collection
-     * @param payload
-     * @return
+     * Post an entity to a collection.
      *
+     * <pre>
      * app.collection("users").post(entity);
      * POST /users {"color","red"}
-     *
+     * </pre>
      */
     public Entity post(Entity payload){
+
         String acceptHeader = MediaType.APPLICATION_JSON;
         if (this.acceptHeaders.size() > 0) {
             acceptHeader = StringUtils.join(this.acceptHeaders, ',');
         }
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .post(ApiResponse.class, payload);
+
+        // use string type so we can log actual response from server
+        String responseString = getResource(true)
+            .type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(acceptHeader)
+            .post(String.class, payload);
+
+        logger.debug("Response from post: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
+
         return new Entity(response);
     }
 
-    public Entity post(){
+    public Entity post() {
+
         String acceptHeader = MediaType.APPLICATION_JSON;
+
         if (this.acceptHeaders.size() > 0) {
             acceptHeader = StringUtils.join(this.acceptHeaders, ',');
         }
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .post(ApiResponse.class);
+
+        // use string type so we can log actual response from server
+        String responseString = getResource(true)
+            .type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(acceptHeader)
+            .post(String.class);
+
+        logger.debug("Response from post: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
+
         return new Entity(response);
     }
 
-    public ApiResponse post(List<Entity> entityList){
+    public ApiResponse post(List<Entity> entityList) {
+
         String acceptHeader = MediaType.APPLICATION_JSON;
+
         if (this.acceptHeaders.size() > 0) {
             acceptHeader = StringUtils.join(this.acceptHeaders, ',');
         }
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .post(ApiResponse.class,entityList);
+
+        // use string type so we can log actual response from server
+        String responseString = getResource(true)
+            .type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(acceptHeader)
+            .post(String.class, entityList );
+
+        logger.debug("Response from post: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
+
         return response;
     }
 
     /**
-     * PUT a payload to a collection
+     * PUT a payload to a collection.
      *
+     * <pre>
      * app.collection("users").put(entity, param);
      * PUT /users?ql=select * where created > 0&token=<token>
      *
      * app.collection("users").put(entity, false, param);
      * PUT /users?ql=select * where created > 0
-     *
+     * </pre>
      */
     public ApiResponse put( final QueryParameters parameters, Entity entity ){
         return put(parameters, true, entity);
     }
 
-    public ApiResponse put(final QueryParameters parameters, final boolean useToken, Entity entity){
+    public ApiResponse put(final QueryParameters parameters, final boolean useToken, Entity entity) {
+
         String acceptHeader = MediaType.APPLICATION_JSON;
         if (this.acceptHeaders.size() > 0) {
             acceptHeader = StringUtils.join(this.acceptHeaders, ',');
         }
+
         WebResource resource  = getResource(useToken);
         addParametersToResource(getResource(), parameters);
-        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
-                .put(ApiResponse.class, entity);
-    }
-
 
+        // use string type so we can log actual response from server
+        String responseString = resource.type(MediaType.APPLICATION_JSON_TYPE)
+            .accept(acceptHeader)
+            .post(String.class, entity);
 
+        logger.debug("Response from put: " + responseString);
 
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
 
+        return response;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
index 839f2cd..1a940bd 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
 
 import javax.ws.rs.core.MediaType;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
@@ -30,13 +31,19 @@ import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 import com.sun.jersey.api.client.WebResource;
 
 import com.sun.jersey.api.representation.Form;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.io.StringReader;
 
-//TODO: add error checking to each of the rest calls.
+
+//TODO: add error checking to each of the REST calls.
 /**
  * Manages the Management/ORG endpoint.
  */
 public class OrgResource  extends NamedResource {
+    private static final Logger logger = LoggerFactory.getLogger(OrgResource.class);
 
     public OrgResource( final ClientContext context, final UrlResource parent ) {
         super( "orgs", context, parent );
@@ -48,15 +55,15 @@ public class OrgResource  extends NamedResource {
     }
 
     /**
-     * This post is for the POST params case, where the entire call is made using queryParameters
-     * @return
+     * This post is for the POST params case, where the entire call is made using queryParameters.
      */
     public Organization post(Form form){
-        //Seems like an apiresponse can't handle what gets returned from the from urlended media type
 
-        ApiResponse response = getResource().type( MediaType.APPLICATION_FORM_URLENCODED )
-                                       .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, form );
+        // Seems like an apiresponse can't handle what gets returned from the from urlended media type
 
+        ApiResponse response = getResource().type( MediaType.APPLICATION_FORM_URLENCODED )
+            .accept(MediaType.APPLICATION_JSON)
+            .post(ApiResponse.class, form);
 
         Organization organization = new Organization(response);
         organization.setOwner( response );
@@ -64,25 +71,50 @@ public class OrgResource  extends NamedResource {
     }
 
     /**
-     * This post is for the POST params case, where the entire call is made using queryParameters
-     * @return
+     * This post is for the POST params case, where the entire call is made using queryParameters.
      */
     public Organization post(QueryParameters parameters){
-        //Seems like an apiresponse can't handle what gets returned from the from urlended media type
+
+        // Seems like an ApiResponse can't handle what gets returned from the from URL encoded media type
         WebResource resource = addParametersToResource( getResource(), parameters);
 
-            ApiResponse response = resource.type( MediaType.APPLICATION_FORM_URLENCODED )
-                                        .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class );
+        // use string type so we can log actual response from server
+        String responseString = resource.type(MediaType.APPLICATION_JSON_TYPE)
+            .accept(MediaType.APPLICATION_JSON)
+            .post(String.class);
 
+        logger.debug("Response from post: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
 
         Organization org = new Organization(response);
         org.setOwner( response );
+
         return org;
     }
 
     public Organization post(Organization organization){
-        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                     .post( ApiResponse.class,organization );
+
+        // use string type so we can log actual response from server
+        String responseString = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(MediaType.APPLICATION_JSON)
+            .post(String.class, organization);
+
+        logger.debug("Response from post: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
 
         Organization org = new Organization(response);
         org.setOwner( response );
@@ -91,8 +123,21 @@ public class OrgResource  extends NamedResource {
     }
 
     public Organization put(Organization organization){
-        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .put(ApiResponse.class, organization);
+
+        // use string type so we can log actual response from server
+        String responseString = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(MediaType.APPLICATION_JSON)
+            .put(String.class, organization);
+
+        logger.debug("Response from put: " + responseString);
+
+        ObjectMapper mapper = new ObjectMapper();
+        ApiResponse response;
+        try {
+            response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+        } catch (IOException e) {
+            throw new RuntimeException("Error parsing response", e);
+        }
 
         Organization org = new Organization(response);
         org.setOwner( response );
@@ -106,9 +151,9 @@ public class OrgResource  extends NamedResource {
     }
 
     public void delete(){
-        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .delete(ApiResponse.class);
-
+        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+            .accept(MediaType.APPLICATION_JSON)
+            .delete(ApiResponse.class);
     }
     public CredentialsResource credentials(){
         return new CredentialsResource(  context ,this );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index b616be8..89bf092 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -1,6 +1,3 @@
-/**
- * Created by ApigeeCorporation on 12/4/14.
- */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -18,10 +15,8 @@
  * limitations under the License.
  */
 
-
 package org.apache.usergrid.rest.test.resource2point0.model;
 
-
 import java.io.Serializable;
 import java.util.*;
 
@@ -38,7 +33,6 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
  * Contains a model that can be deconstructed from the api response. This is a base level value that contains the bare
  * minumum of what other classes use. Such as . users or groups.
  */
-
 public class Entity implements Serializable, Map<String,Object> {
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/services/pom.xml
----------------------------------------------------------------------
diff --git a/stack/services/pom.xml b/stack/services/pom.xml
index ad54fb5..46b0878 100644
--- a/stack/services/pom.xml
+++ b/stack/services/pom.xml
@@ -394,6 +394,12 @@
           <groupId>com.github.fernandospr</groupId>
           <artifactId>java-wns</artifactId>
           <version>1.3</version>
+          <exclusions>
+              <exclusion>
+                  <artifactId>jackson-jaxrs</artifactId>
+                  <groupId>org.codehaus.jackson</groupId>
+              </exclusion>
+          </exclusions>
       </dependency>
 
   </dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2f6edd71/stack/test-utils/pom.xml
----------------------------------------------------------------------
diff --git a/stack/test-utils/pom.xml b/stack/test-utils/pom.xml
index 5c3539b..d9728af 100644
--- a/stack/test-utils/pom.xml
+++ b/stack/test-utils/pom.xml
@@ -242,7 +242,7 @@
             <!-- we need this in all scopes, not just test -->
         </dependency>
 
-        <!--  "The artifact junit:junit-dep:jar:4.11 has been relocated to junit:junit:jar:4.11"    
+        <!--  "The artifact junit:junit-dep:jar:4.11 has been relocated to junit:junit:jar:4.11"
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit-dep</artifactId>
@@ -256,10 +256,10 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.codehaus.jackson</groupId>
-            <artifactId>jackson-mapper-asl</artifactId>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.codehaus.jackson</groupId>-->
+            <!--<artifactId>jackson-mapper-asl</artifactId>-->
+        <!--</dependency>-->
 
         <dependency>
             <groupId>org.apache.tomcat.embed</groupId>


[4/8] incubator-usergrid git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-432

Posted by sf...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-432


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9f521c7d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9f521c7d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9f521c7d

Branch: refs/heads/USERGRID-432
Commit: 9f521c7d8f133fc68f6c7907180e3779f199b168
Parents: 0f9e8c9 489bf45
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 08:22:54 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 08:22:54 2015 -0700

----------------------------------------------------------------------
 stack/rest/pom.xml                              |  37 +----
 .../org/apache/usergrid/rest/SimplestTest.java  |  35 -----
 .../applications/queries/GeoPagingTest.java     |  44 +++---
 .../endpoints/CollectionEndpoint.java           | 155 ++++++++++++++-----
 .../endpoints/mgmt/OrgResource.java             |  81 +++++++---
 .../rest/test/resource2point0/model/Entity.java |   6 -
 stack/services/pom.xml                          |   6 +
 stack/test-utils/pom.xml                        |  11 --
 8 files changed, 211 insertions(+), 164 deletions(-)
----------------------------------------------------------------------



[8/8] incubator-usergrid git commit: async delete by query

Posted by sf...@apache.org.
async delete by query


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/44c09894
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/44c09894
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/44c09894

Branch: refs/heads/USERGRID-432
Commit: 44c0989422ed0912f3e5ed5643f79910ac1057e6
Parents: 66f4bfb
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Mar 3 09:40:23 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Mar 3 09:40:23 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 21 ++++---
 .../usergrid/corepersistence/CpWalker.java      |  4 +-
 .../corepersistence/StaleIndexCleanupTest.java  | 14 ++---
 .../cassandra/EntityManagerFactoryImplIT.java   | 25 ++++----
 .../usergrid/persistence/index/EntityIndex.java |  6 +-
 .../index/IndexOperationMessage.java            |  7 ++-
 .../index/impl/EsEntityIndexImpl.java           | 65 +++++++++++++++-----
 .../index/impl/EsIndexBufferConsumerImpl.java   | 20 ++++--
 .../persistence/index/impl/EntityIndexTest.java |  2 +-
 stack/pom.xml                                   |  6 ++
 10 files changed, 113 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index bc227d8..6d97605 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -350,7 +350,7 @@ public class CpEntityManager implements EntityManager {
         Id id = new SimpleId( entityRef.getUuid(), entityRef.getType() );
 
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-                applicationScope.getApplication(),  entityRef.getType());
+            getApplicationScope().getApplication(),  entityRef.getType());
 
 
         //        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
@@ -433,7 +433,7 @@ public class CpEntityManager implements EntityManager {
 
 
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-                applicationScope.getApplication(),  type);
+            getApplicationScope().getApplication(),  type);
 
 
         //        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
@@ -491,11 +491,16 @@ public class CpEntityManager implements EntityManager {
 
     @Override
     public void update( Entity entity ) throws Exception {
-
+        if(entity == null)
+            return;
+        Preconditions.checkNotNull("entity should never be null",entity);
+        String type = entity.getType();
+        Preconditions.checkNotNull("entity type should never be null",type);
+        Id appId  = getApplicationScope().getApplication();
+        Preconditions.checkNotNull("app scope should never be null",appId);
         // first, update entity index in its own collection scope
 
-        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-                applicationScope.getApplication(),  entity.getType());
+        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(appId, type );
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
@@ -569,7 +574,7 @@ public class CpEntityManager implements EntityManager {
             return Observable.empty();
         }
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-                applicationScope.getApplication(), entityRef.getType()  );
+            getApplicationScope().getApplication(), entityRef.getType()  );
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 
@@ -2122,7 +2127,7 @@ public class CpEntityManager implements EntityManager {
                                           final Object propertyValue ) {
 
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
-                applicationScope.getApplication(), collectionName);
+            getApplicationScope().getApplication(), collectionName);
 
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 
@@ -2446,7 +2451,7 @@ public class CpEntityManager implements EntityManager {
         org.apache.usergrid.persistence.model.entity.Entity cpEntity = entityToCpEntity( entity, importId );
 
         // prepare to write and index Core Persistence Entity into default scope
-        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), eType);
+        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(getApplicationScope().getApplication(), eType);
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index 928b210..4b902d8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -140,7 +140,9 @@ public class CpWalker {
                                 targetNodeEntityRef.getUuid() );
                             return;
                         }
-
+                        if(entity == null){
+                            return;
+                        }
                         String collName = CpNamingUtils.getCollectionName( edge.getType() );
                         visitor.visitCollectionEntry( em, collName, entity );
                     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
index 831e2ce..703a497 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
@@ -135,6 +135,7 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
     @Ignore("Broken until search connections is fixed")
     public void testStaleIndexCleanup() throws Exception {
 
+
         logger.info( "Started testStaleIndexCleanup()" );
 
         // turn off post processing stuff that cleans up stale entities
@@ -237,7 +238,7 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
 
         // query for total number of result candidates = numEntities
         crs = queryCollectionCp( "things", "thing", "select *" );
-        Assert.assertEquals( "Expect stale candidates de-indexed", numEntities, crs.size() );
+        Assert.assertEquals( "Expect stale candidates de-indexed", numEntities, crs.size() );//20,21
     }
 
 
@@ -345,7 +346,7 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
             things.add( em.create("thing", new HashMap<String, Object>() {{
                 put("name", thingName);
             }}));
-            Thread.sleep( writeDelayMs );
+//            Thread.sleep( writeDelayMs );
         }
         em.refreshIndex();
 
@@ -382,14 +383,11 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
         // wait for indexes to be cleared for the deleted entities
         count = 0;
         do {
-            Thread.sleep(100);
+            if(count>0){Thread.sleep(200);}
             crs = queryCollectionCp("things", "thing", "select *");
-            em.refreshIndex();
-        } while ( crs.size() > 0 && count++ < 15 );
+        } while ( crs.size() == numEntities && count++ < 15 );
 
-        // query Core Persistence directly for total number of result candidates
-        crs = queryCollectionCp("things", "thing", "select *");
-        Assert.assertEquals( "Expect candidates without earlier stale entities", numEntities, crs.size() );
+        Assert.assertEquals("Expect candidates without earlier stale entities", crs.size(),numEntities);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index b4a67e8..0ca6e8b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -41,6 +41,9 @@ import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.setup.ConcurrentProcessSingleton;
 import rx.functions.Func0;
 import rx.functions.Func1;
+import rx.functions.Func2;
+
+import javax.annotation.concurrent.NotThreadSafe;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -49,7 +52,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-
+@NotThreadSafe
 public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
     private static final Logger logger = LoggerFactory.getLogger( EntityManagerFactoryImplIT.class );
@@ -124,13 +127,13 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         em.refreshIndex();
 
-        Func1< Map<String, UUID> ,Boolean> findDeletedApps = new Func1<Map<String, UUID> ,Boolean>() {
+        Func2<UUID, Map<String, UUID> ,Boolean> findApps = new Func2<UUID,Map<String, UUID> ,Boolean>() {
             @Override
-            public Boolean call( Map<String, UUID> deletedApps) {
+            public Boolean call(UUID applicationId,  Map<String, UUID> apps) {
                 try {
                     boolean found = false;
-                    for (String appName : deletedApps.keySet()) {
-                        UUID appId = deletedApps.get(appName);
+                    for (String appName : apps.keySet()) {
+                        UUID appId = apps.get(appName);
                         if (appId.equals(applicationId)) {
                             found = true;
                             break;
@@ -144,8 +147,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         };
 
         boolean found = false;
-        for(int i=0;i<5;i++){
-            found = findDeletedApps.call(emf.getDeletedApplications());
+        for(int i=0;i<10;i++){
+            found = findApps.call(applicationId,emf.getDeletedApplications());
             if(found){
                 break;
             } else{
@@ -179,8 +182,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         // test to see that app now works and is happy
 
         // it should not be found in the deleted apps collection
-        for(int i=0;i<5;i++){
-            found = findDeletedApps.call(emf.getDeletedApplications());
+        for(int i=0;i<10;i++){
+            found = findApps.call(applicationId,emf.getDeletedApplications());
             if(!found){
                 break;
             } else{
@@ -189,8 +192,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         }
         assertFalse("Restored app found in deleted apps collection", found);
 
-        for(int i=0;i<5;i++){
-            found = findDeletedApps.call(setup.getEmf().getApplications());
+        for(int i=0;i<10;i++){
+            found = findApps.call(applicationId,setup.getEmf().getApplications());
             if(!found){
                 break;
             } else{

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index d239641..b888e09 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -25,8 +25,10 @@ import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.model.entity.Id;
+import org.elasticsearch.action.ListenableActionFuture;
 
 import java.util.Map;
+import java.util.concurrent.Future;
 
 
 /**
@@ -76,14 +78,14 @@ public interface EntityIndex {
      * effectively removing all versions of an entity from all index scopes
      * @param entityId The entityId to remove
      */
-    public void deleteAllVersionsOfEntity(final Id entityId );
+    public Future deleteAllVersionsOfEntity(final Id entityId );
 
     /**
      * Takes all the previous versions of the current entity and deletes all previous versions
      * @param id The id to remove
      * @param version The max version to retain
      */
-    public void deletePreviousVersions(final Id id, final UUID version);
+    public Future deletePreviousVersions(final Id id, final UUID version);
 
     /**
      * Refresh the index.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
index 501233e..944a71f 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.persistence.index;
 
 import org.apache.usergrid.persistence.core.future.BetterFuture;
+import org.elasticsearch.action.ActionRequestBuilder;
 import org.elasticsearch.action.support.replication.ShardReplicationOperationRequestBuilder;
 
 import java.util.Iterator;
@@ -27,7 +28,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
  * Container for index operations.
  */
 public  class IndexOperationMessage {
-    private final ConcurrentLinkedQueue<ShardReplicationOperationRequestBuilder> builders;
+    private final ConcurrentLinkedQueue<ActionRequestBuilder> builders;
     private final BetterFuture<IndexOperationMessage> containerFuture;
 
     public IndexOperationMessage(){
@@ -41,7 +42,7 @@ public  class IndexOperationMessage {
         });
     }
 
-    public void addOperation(ShardReplicationOperationRequestBuilder builder){
+    public void addOperation(ActionRequestBuilder builder){
         builders.add(builder);
     }
 
@@ -49,7 +50,7 @@ public  class IndexOperationMessage {
      * return operations for the message
      * @return
      */
-    public ConcurrentLinkedQueue<ShardReplicationOperationRequestBuilder> getOperations(){
+    public ConcurrentLinkedQueue<ActionRequestBuilder> getOperations(){
         return builders;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index ad638c6..a8b0cc4 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -19,6 +19,8 @@ package org.apache.usergrid.persistence.index.impl;
 
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 import org.apache.commons.lang.StringUtils;
@@ -35,6 +37,8 @@ import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.elasticsearch.action.ActionListener;
+import org.elasticsearch.action.ListenableActionFuture;
 import org.elasticsearch.action.ShardOperationFailedException;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
@@ -444,7 +448,8 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
                 try {
                     String[] indexes = ArrayUtils.addAll(
                         getIndexes(AliasType.Read),
-                        getIndexes(AliasType.Write) );
+                        getIndexes(AliasType.Write)
+                    );
 
                     if ( indexes.length == 0 ) {
                         logger.debug( "Not refreshing indexes, none found for app {}",
@@ -510,26 +515,38 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
 
     @Override
-    public void deleteAllVersionsOfEntity( Id entityId ) {
+    public ListenableActionFuture deleteAllVersionsOfEntity(final Id entityId ) {
 
         String idString = IndexingUtils.idString(entityId).toLowerCase();
 
         final TermQueryBuilder tqb = QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, idString );
 
-        final DeleteByQueryResponse response = esProvider.getClient()
-            .prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute().actionGet();
+        final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
+            .prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute();
 
+        response.addListener(new ActionListener<DeleteByQueryResponse>() {
+            @Override
+            public void onResponse(DeleteByQueryResponse response) {
+                logger.debug( "Deleted entity {}:{} from all index scopes with response status = {}",
+                    entityId.getType(), entityId.getUuid(), response.status().toString());
+
+                checkDeleteByQueryResponse( tqb, response );
+            }
 
-        logger.debug( "Deleted entity {}:{} from all index scopes with response status = {}",
-            entityId.getType(), entityId.getUuid(), response.status().toString());
+            @Override
+            public void onFailure(Throwable e) {
+                logger.error("Deleted entity {}:{} from all index scopes with error {}",
+                    entityId.getType(), entityId.getUuid(), e);
 
-       checkDeleteByQueryResponse( tqb, response );
 
+            }
+        });
+        return response;
     }
 
 
     @Override
-    public void deletePreviousVersions( final Id entityId, final UUID version ) {
+    public ListenableActionFuture deletePreviousVersions( final Id entityId, final UUID version ) {
 
         String idString = IndexingUtils.idString( entityId ).toLowerCase();
 
@@ -538,15 +555,28 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
                 FilterBuilders.rangeFilter(ENTITY_VERSION_FIELDNAME).lt(version.timestamp())
         );
 
-        final DeleteByQueryResponse response = esProvider.getClient()
-            .prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( fqb ).execute().actionGet();
+        final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
+            .prepareDeleteByQuery(alias.getWriteAlias()).setQuery(fqb).execute();
 
-        //error message needs to be retooled so that it describes the entity more throughly
-        logger.debug( "Deleted entity {}:{} with version {} from all "
-                + "index scopes with response status = {}",
-            entityId.getType(), entityId.getUuid(), version,  response.status().toString()  );
+        response.addListener(new ActionListener<DeleteByQueryResponse>() {
+            @Override
+            public void onResponse(DeleteByQueryResponse response) {
+                //error message needs to be retooled so that it describes the entity more throughly
+                logger.debug( "Deleted entity {}:{} with version {} from all "
+                        + "index scopes with response status = {}",
+                    entityId.getType(), entityId.getUuid(), version,  response.status().toString()  );
+
+                checkDeleteByQueryResponse( fqb, response );
+            }
+
+            @Override
+            public void onFailure(Throwable e) {
+                logger.error("Deleted entity {}:{} from all index scopes with error {}",
+                    entityId.getType(), entityId.getUuid(), e);
+            }
+        });
 
-        checkDeleteByQueryResponse( fqb, response );
+        return response;
     }
 
 
@@ -560,13 +590,14 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
             final ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
 
             for ( ShardOperationFailedException failedException : failures ) {
-                throw new IndexException( String.format("Unable to delete by query %s. "
+                logger.error( String.format("Unable to delete by query %s. "
                         + "Failed with code %d and reason %s on shard %s in index %s",
                     query.toString(),
                     failedException.status().getStatus(),
                     failedException.reason(),
                     failedException.shardId(),
-                    failedException.index() ) );
+                    failedException.index() )
+                );
             }
 
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index 09c7097..fbb7a40 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -28,11 +28,13 @@ import org.apache.usergrid.persistence.index.IndexBufferConsumer;
 import org.apache.usergrid.persistence.index.IndexBufferProducer;
 import org.apache.usergrid.persistence.index.IndexFig;
 import org.apache.usergrid.persistence.index.IndexOperationMessage;
+import org.elasticsearch.action.ActionRequestBuilder;
 import org.elasticsearch.action.WriteConsistencyLevel;
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
+import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.support.replication.ShardReplicationOperationRequestBuilder;
 import org.elasticsearch.client.Client;
@@ -94,24 +96,26 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
         }
 
         //process and flatten all the messages to builder requests
-        Observable<ShardReplicationOperationRequestBuilder> flattenMessages = Observable.from(operationMessages)
+        Observable<ActionRequestBuilder> flattenMessages = Observable.from(operationMessages)
             .subscribeOn(Schedulers.io())
-            .flatMap(new Func1<IndexOperationMessage, Observable<ShardReplicationOperationRequestBuilder>>() {
+            .flatMap(new Func1<IndexOperationMessage, Observable<ActionRequestBuilder>>() {
                 @Override
-                public Observable<ShardReplicationOperationRequestBuilder> call(IndexOperationMessage operationMessage) {
+                public Observable<ActionRequestBuilder> call(IndexOperationMessage operationMessage) {
                     return Observable.from(operationMessage.getOperations());
                 }
             });
 
+
+
         //batch shard operations into a bulk request
         flattenMessages
             .buffer(config.getIndexBatchSize())
-            .doOnNext(new Action1<List<ShardReplicationOperationRequestBuilder>>() {
+            .doOnNext(new Action1<List<ActionRequestBuilder>>() {
                 @Override
-                public void call(List<ShardReplicationOperationRequestBuilder> builders) {
+                public void call(List<ActionRequestBuilder> builders) {
                     try {
                         final BulkRequestBuilder bulkRequest = initRequest();
-                        for (ShardReplicationOperationRequestBuilder builder : builders) {
+                        for (ActionRequestBuilder builder : builders) {
                             indexSizeCounter.dec();
                             if (builder instanceof IndexRequestBuilder) {
                                 bulkRequest.add((IndexRequestBuilder) builder);
@@ -119,6 +123,10 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
                             if (builder instanceof DeleteRequestBuilder) {
                                 bulkRequest.add((DeleteRequestBuilder) builder);
                             }
+                            if(builder instanceof DeleteByQueryRequestBuilder){
+                                DeleteByQueryRequestBuilder deleteByQueryRequestBuilder = (DeleteByQueryRequestBuilder) builder;
+                                deleteByQueryRequestBuilder.get();
+                            }
                         }
                         sendRequest(bulkRequest);
                     }catch (Exception e){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 83ba1ec..7bfbb52 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -182,7 +182,7 @@ public class EntityIndexTest extends BaseIT {
     }
 
     @Test
-    public void testDeleteByQueryWithAlias() throws IOException {
+    public void testDeleteWithAlias() throws IOException {
         Id appId = new SimpleId( "application" );
 
         ApplicationScope applicationScope = new ApplicationScopeImpl( appId );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44c09894/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 513d3bb..53755b3 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -1515,6 +1515,12 @@
                               <groupId>org.apache.maven.surefire</groupId>
                               <artifactId>surefire-junit47</artifactId>
                               <version>${surefire.plugin.version}</version>
+                              <exclusions>
+                                  <exclusion>
+                                      <groupId>org.apache.maven.surfire</groupId>
+                                      <artifactId>common-junit3</artifactId>
+                                  </exclusion>
+                              </exclusions>
                           </dependency>
                       </dependencies>
                   </plugin>


[5/8] incubator-usergrid git commit: changing app delete logic in test

Posted by sf...@apache.org.
changing app delete logic in test


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f0b11c62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f0b11c62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f0b11c62

Branch: refs/heads/USERGRID-432
Commit: f0b11c62101db82b41a0614224d52e53342c276b
Parents: 9f521c7
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 11:00:39 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 11:00:39 2015 -0700

----------------------------------------------------------------------
 .../cassandra/EntityManagerFactoryImplIT.java   | 55 ++++++++++++--------
 .../services/notifications/QueueListener.java   | 10 ++--
 .../resources/usergrid-custom-test.properties   |  3 ++
 3 files changed, 43 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f0b11c62/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index c3bc020..20bf7eb 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -39,6 +39,7 @@ import org.apache.usergrid.persistence.cassandra.util.TraceTagManager;
 import org.apache.usergrid.persistence.cassandra.util.TraceTagReporter;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.setup.ConcurrentProcessSingleton;
+import rx.functions.Func0;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -97,7 +98,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         // create an application with a collection and an entity
 
-        UUID applicationId = setup.createApplication( "test-org-" + rand, "test-app-" + rand );
+        final UUID applicationId = setup.createApplication( "test-org-" + rand, "test-app-" + rand );
 
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
 
@@ -122,16 +123,35 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         em.refreshIndex();
 
+        Func0<Boolean> func0 = new Func0<Boolean>() {
+            @Override
+            public Boolean call() {
+                try {
+                    boolean found = false;
+                    Map<String, UUID> deletedApps = emf.getDeletedApplications();
+                    for (String appName : deletedApps.keySet()) {
+                        UUID appId = deletedApps.get(appName);
+                        if (appId.equals(applicationId)) {
+                            found = true;
+                            break;
+                        }
+                    }
+                    return found;
+                }catch (Exception e){
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+
         boolean found = false;
-        Map<String, UUID> deletedApps = emf.getDeletedApplications();
-        for ( String appName : deletedApps.keySet() ) {
-            UUID appId = deletedApps.get( appName );
-            if ( appId.equals( applicationId )) {
-                found = true;
+        for(int i=0;i<5;i++){
+            found = func0.call();
+            if(found){
                 break;
+            } else{
+              Thread.sleep(100);
             }
         }
-
         assertTrue("Deleted app not found in deleted apps collection", found );
 
         // attempt to get entities in application's collections in various ways should all fail
@@ -159,26 +179,17 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         // test to see that app now works and is happy
 
         // it should not be found in the deleted apps collection
-        found = false;
-        deletedApps = emf.getDeletedApplications();
-        for ( String appName : deletedApps.keySet() ) {
-            UUID appId = deletedApps.get( appName );
-            if ( appId.equals( applicationId )) {
-                found = true;
+        for(int i=0;i<5;i++){
+            found = func0.call();
+            if(!found){
                 break;
+            } else{
+                Thread.sleep(100);
             }
         }
         assertFalse("Restored app found in deleted apps collection", found);
 
-        found = false;
-        appMap = setup.getEmf().getApplications();
-        for ( String appName : appMap.keySet() ) {
-            UUID appId = appMap.get( appName );
-            if ( appId.equals( applicationId )) {
-                found = true;
-                break;
-            }
-        }
+        found = func0.call();
         assertTrue("Restored app not found in apps collection", found);
 
         // TODO: this assertion should work!

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f0b11c62/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
index 5247a25..df27d2b 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
@@ -41,7 +41,9 @@ import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
 
-
+/**
+ * Singleton listens for notifications queue messages
+ */
 public class QueueListener  {
     public  final int MESSAGE_TRANSACTION_TIMEOUT =  25 * 1000;
     private final QueueManagerFactory queueManagerFactory;
@@ -83,10 +85,8 @@ public class QueueListener  {
         this.metricsService = smf.getApplicationContext().getBean( Injector.class ).getInstance(MetricsFactory.class);
         this.properties = props;
         this.queueScopeFactory = smf.getApplicationContext().getBean( Injector.class ).getInstance(QueueScopeFactory.class);
-
     }
 
-
     /**
      * Start the service and begin consuming messages
      */
@@ -99,6 +99,10 @@ public class QueueListener  {
             int threadCount = 0;
 
             try {
+                boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run","true"));
+                if(!shouldRun){
+                    return;
+                }
                 sleepBetweenRuns = new Long(properties.getProperty("usergrid.notifications.listener.sleep.between", ""+sleepBetweenRuns)).longValue();
                 sleepWhenNoneFound = new Long(properties.getProperty("usergrid.notifications.listener.sleep.after", ""+DEFAULT_SLEEP)).longValue();
                 batchSize = new Integer(properties.getProperty("usergrid.notifications.listener.batchSize", (""+batchSize)));

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f0b11c62/stack/services/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/usergrid-custom-test.properties b/stack/services/src/test/resources/usergrid-custom-test.properties
index 60e06a1..1ddfead 100644
--- a/stack/services/src/test/resources/usergrid-custom-test.properties
+++ b/stack/services/src/test/resources/usergrid-custom-test.properties
@@ -27,3 +27,6 @@ notification.concurrent.batches=2
 hystrix.threadpool.graph_user.coreSize=50
 hystrix.threadpool.graph_async.coreSize=50
 usergrid.scheduler.job.timeout=300000
+
+usergrid.notifications.listener.run=false
+


[2/8] incubator-usergrid git commit: Removing unnecessary test class and commented out dependencies.

Posted by sf...@apache.org.
Removing unnecessary test class and commented out dependencies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/489bf458
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/489bf458
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/489bf458

Branch: refs/heads/USERGRID-432
Commit: 489bf458e561833ed0d84c7e290b2986e3c8280e
Parents: 2f6edd7
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Feb 27 16:36:58 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Feb 27 16:36:58 2015 -0500

----------------------------------------------------------------------
 .../org/apache/usergrid/rest/SimplestTest.java  | 71 --------------------
 stack/test-utils/pom.xml                        | 11 ---
 2 files changed, 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/489bf458/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
deleted file mode 100644
index 27898a9..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.rest;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.usergrid.persistence.DynamicEntity;
-import org.apache.usergrid.rest.test.resource2point0.model.Collection;
-import org.apache.usergrid.rest.test.resource2point0.model.Entity;
-import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
-import org.apache.usergrid.utils.MapUtils;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-
-/**
- * Simple test verifies if REST test infrastructure is functioning.
- */
-public class SimplestTest extends org.apache.usergrid.rest.test.resource2point0.AbstractRestIT {
-    private static final Logger logger = LoggerFactory.getLogger(SimplestTest.class);
-
-    @Test
-    public void getGetToken() {
-        assertNotNull( getAdminToken() );
-    }
-
-    @Test
-    public void testEntityPost() {
-
-        Entity cat = new Entity();
-        cat.put("name", "Bertha");
-        cat.put("property1", "value1");
-        Entity savedCat = this.app().collection("cats").post(cat);
-
-        assertEquals( cat.get("property1"), savedCat.get("property1"));
-    }
-
-    @Test
-    public void testEntityPostAndGet() {
-
-        Entity dog = new Entity();
-        dog.put("name", "Pokey");
-        dog.put("property1", "value1");
-        this.app().collection("dogs").post(dog);
-        refreshIndex();
-
-        Collection savedDogs = this.app().collection("dogs").get();
-        Entity savedDog = (Entity)savedDogs.iterator().next();
-        assertEquals( dog.get("property1"), savedDog.get("property1"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/489bf458/stack/test-utils/pom.xml
----------------------------------------------------------------------
diff --git a/stack/test-utils/pom.xml b/stack/test-utils/pom.xml
index d9728af..fecf069 100644
--- a/stack/test-utils/pom.xml
+++ b/stack/test-utils/pom.xml
@@ -242,12 +242,6 @@
             <!-- we need this in all scopes, not just test -->
         </dependency>
 
-        <!--  "The artifact junit:junit-dep:jar:4.11 has been relocated to junit:junit:jar:4.11"
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit-dep</artifactId>
-        </dependency>-->
-
         <!-- Test Dependencies -->
 
         <dependency>
@@ -256,11 +250,6 @@
             <scope>test</scope>
         </dependency>
 
-        <!--<dependency>-->
-            <!--<groupId>org.codehaus.jackson</groupId>-->
-            <!--<artifactId>jackson-mapper-asl</artifactId>-->
-        <!--</dependency>-->
-
         <dependency>
             <groupId>org.apache.tomcat.embed</groupId>
             <artifactId>tomcat-embed-core</artifactId>


[6/8] incubator-usergrid git commit: change timeout

Posted by sf...@apache.org.
change timeout


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/4d6bee0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/4d6bee0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/4d6bee0d

Branch: refs/heads/USERGRID-432
Commit: 4d6bee0d88c3335c8fef95f3da0fcdbfdfaca08a
Parents: f0b11c6
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 12:14:51 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 12:14:51 2015 -0700

----------------------------------------------------------------------
 .../persistence/cassandra/EntityManagerFactoryImplIT.java | 10 +++++++++-
 .../org/apache/usergrid/persistence/index/IndexFig.java   |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4d6bee0d/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 20bf7eb..3f42356 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -189,7 +189,15 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         }
         assertFalse("Restored app found in deleted apps collection", found);
 
-        found = func0.call();
+        found = false;
+        appMap = setup.getEmf().getApplications();
+        for ( String appName : appMap.keySet() ) {
+            UUID appId = appMap.get( appName );
+            if ( appId.equals( applicationId )) {
+                found = true;
+                break;
+            }
+        }
         assertTrue("Restored app not found in apps collection", found);
 
         // TODO: this assertion should work!

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4d6bee0d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
index 8040a62..9893ca5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
@@ -51,7 +51,7 @@ public interface IndexFig extends GuicyFig {
 
     public static final String INDEX_BUFFER_SIZE = "elasticsearch.buffer_size";
 
-    public static final String INDEX_BUFFER_TIMEOUT = "elasticsearch.buffer_size";
+    public static final String INDEX_BUFFER_TIMEOUT = "elasticsearch.buffer_timeout";
 
     public static final String INDEX_BATCH_SIZE = "elasticsearch.batch_size";
 


[7/8] incubator-usergrid git commit: change queue listener bootstrap

Posted by sf...@apache.org.
change queue listener bootstrap


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/66f4bfb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/66f4bfb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/66f4bfb9

Branch: refs/heads/USERGRID-432
Commit: 66f4bfb92f07f5eb066c175e94ffae4c39865998
Parents: 4d6bee0
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 12:42:26 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 12:42:26 2015 -0700

----------------------------------------------------------------------
 .../cassandra/EntityManagerFactoryImplIT.java   | 25 ++++++++++----------
 .../usergrid/rest/JobServiceBoostrap.java       | 12 ++++++++++
 .../services/notifications/QueueListener.java   |  9 +------
 .../resources/usergrid-services-context.xml     |  3 +--
 4 files changed, 26 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 3f42356..b4a67e8 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -40,6 +40,7 @@ import org.apache.usergrid.persistence.cassandra.util.TraceTagReporter;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.setup.ConcurrentProcessSingleton;
 import rx.functions.Func0;
+import rx.functions.Func1;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -123,12 +124,11 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         em.refreshIndex();
 
-        Func0<Boolean> func0 = new Func0<Boolean>() {
+        Func1< Map<String, UUID> ,Boolean> findDeletedApps = new Func1<Map<String, UUID> ,Boolean>() {
             @Override
-            public Boolean call() {
+            public Boolean call( Map<String, UUID> deletedApps) {
                 try {
                     boolean found = false;
-                    Map<String, UUID> deletedApps = emf.getDeletedApplications();
                     for (String appName : deletedApps.keySet()) {
                         UUID appId = deletedApps.get(appName);
                         if (appId.equals(applicationId)) {
@@ -145,11 +145,11 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         boolean found = false;
         for(int i=0;i<5;i++){
-            found = func0.call();
+            found = findDeletedApps.call(emf.getDeletedApplications());
             if(found){
                 break;
             } else{
-              Thread.sleep(100);
+              Thread.sleep(500);
             }
         }
         assertTrue("Deleted app not found in deleted apps collection", found );
@@ -180,22 +180,21 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         // it should not be found in the deleted apps collection
         for(int i=0;i<5;i++){
-            found = func0.call();
+            found = findDeletedApps.call(emf.getDeletedApplications());
             if(!found){
                 break;
             } else{
-                Thread.sleep(100);
+                Thread.sleep(500);
             }
         }
         assertFalse("Restored app found in deleted apps collection", found);
 
-        found = false;
-        appMap = setup.getEmf().getApplications();
-        for ( String appName : appMap.keySet() ) {
-            UUID appId = appMap.get( appName );
-            if ( appId.equals( applicationId )) {
-                found = true;
+        for(int i=0;i<5;i++){
+            found = findDeletedApps.call(setup.getEmf().getApplications());
+            if(!found){
                 break;
+            } else{
+                Thread.sleep(500);
             }
         }
         assertTrue("Restored app not found in apps collection", found);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
index a921f22..ed45c91 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest;
 
 import org.apache.usergrid.batch.service.JobSchedulerService;
 import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.notifications.QueueListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +45,9 @@ public class JobServiceBoostrap implements
     @Autowired
     private Properties properties;
 
+    @Autowired
+    private QueueListener notificationsQueueListener;
+
     public JobServiceBoostrap() {
     }
 
@@ -65,6 +69,14 @@ public class JobServiceBoostrap implements
         } else {
             logger.info( "Scheduler Service disabled" );
         }
+
+        boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run","true"));
+        if(shouldRun){
+            notificationsQueueListener.start();
+        }else{
+            logger.info("QueueListener: never started due to config value usergrid.notifications.listener.run.");
+        }
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
index df27d2b..d34cc22 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
@@ -99,10 +99,7 @@ public class QueueListener  {
             int threadCount = 0;
 
             try {
-                boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run","true"));
-                if(!shouldRun){
-                    return;
-                }
+
                 sleepBetweenRuns = new Long(properties.getProperty("usergrid.notifications.listener.sleep.between", ""+sleepBetweenRuns)).longValue();
                 sleepWhenNoneFound = new Long(properties.getProperty("usergrid.notifications.listener.sleep.after", ""+DEFAULT_SLEEP)).longValue();
                 batchSize = new Integer(properties.getProperty("usergrid.notifications.listener.batchSize", (""+batchSize)));
@@ -135,10 +132,6 @@ public class QueueListener  {
                 LOG.error("QueueListener: failed to start:", e);
             }
             LOG.info("QueueListener: done starting.");
-//        }else{
-//            LOG.info("QueueListener: never started due to config value usergrid.notifications.listener.run.");
-//        }
-
     }
 
     private void execute(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index e97481b..666051d 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -89,8 +89,7 @@
 
   <bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
 
-  <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener"
-        scope="singleton">
+  <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener">
     <constructor-arg name="emf" ref="entityManagerFactory" />
     <constructor-arg name="props" ref="properties" />
     <constructor-arg name="smf" ref="serviceManagerFactory" />


[3/8] incubator-usergrid git commit: adding application creation protection

Posted by sf...@apache.org.
adding application creation protection


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0f9e8c9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0f9e8c9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0f9e8c9f

Branch: refs/heads/USERGRID-432
Commit: 0f9e8c9f478f497fef54b3aa6612133b511c8922
Parents: 497ac05
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 08:22:49 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 08:22:49 2015 -0700

----------------------------------------------------------------------
 .../test/java/org/apache/usergrid/rest/AbstractRestIT.java   | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0f9e8c9f/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index 5f4a534..1b3ee65 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -33,6 +33,7 @@ import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.management.OrganizationOwnerInfo;
 
+import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.slf4j.Logger;
@@ -146,7 +147,12 @@ public abstract class AbstractRestIT extends JerseyTest {
             orgInfo = orgOwnerInfo.getOrganization();
         }
 
-        appInfo = setup.getMgmtSvc().createApplication(orgInfo.getUuid(), "app-" + rand);
+        String appname =  "app-" + rand;
+        try {
+            appInfo = setup.getMgmtSvc().createApplication(orgInfo.getUuid(),appname);
+        }catch(ApplicationAlreadyExistsException e){
+            LOG.error("Failed to create application"+appname+", maybe this is ok", e);
+        }
         refreshIndex( orgInfo.getName(), appInfo.getName() );
 
         orgAppPath = appInfo.getName() + "/";