You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/08 17:53:07 UTC

[1/3] git commit: comment fix.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o 13ae49b37 -> df8e6a291


comment fix.


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

Branch: refs/heads/two-dot-o
Commit: f47ed60a97234cc3c25fd3e5d9154390f3818142
Parents: 66c377d
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 8 11:13:40 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 8 11:13:40 2014 -0400

----------------------------------------------------------------------
 .../persistence/collection/EntityCollectionManagerIT.java        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f47ed60a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 3d47e32..00f4a50 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -358,7 +358,7 @@ public class EntityCollectionManagerIT {
         // note its version 
         UUID oldVersion = returned.getVersion();
 
-        // partial update entity but we don't have version number
+        // partial update entity but with new entity that has version = null
         Entity updateEntity = new Entity( origEntity.getId() );
         updateEntity.setField( new StringField("addedField", "other value" ) );
         manager.update(origEntity).toBlocking().lastOrDefault(null);
@@ -367,7 +367,7 @@ public class EntityCollectionManagerIT {
         returned = manager.load(origEntity.getId() ).toBlocking().lastOrDefault(null);
         UUID newVersion = returned.getVersion();
 
-        // this asswer fails
+        // this assert fails
         assertNotEquals( newVersion, oldVersion );
     }
 


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

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


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

Branch: refs/heads/two-dot-o
Commit: df8e6a291c3c42fc3b39b1294d641dffac4b3f25
Parents: c373895 13ae49b
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 8 11:52:34 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 8 11:52:34 2014 -0400

----------------------------------------------------------------------
 .../notifications/ApplicationQueueManager.java  |  7 +-
 .../services/notifications/TaskManager.java     | 85 +++++++++++---------
 2 files changed, 50 insertions(+), 42 deletions(-)
----------------------------------------------------------------------



[2/3] git commit: New stale entity clean-up test.

Posted by sn...@apache.org.
New stale entity clean-up 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/c3738954
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c3738954
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c3738954

Branch: refs/heads/two-dot-o
Commit: c37389548ccc9d502f01e0e92485c25ad1585ce1
Parents: f47ed60
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 8 11:51:20 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 8 11:51:20 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/StaleIndexCleanupTest.java  | 181 +++++++++++++++++++
 1 file changed, 181 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3738954/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
new file mode 100644
index 0000000..5fc9af3
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.corepersistence;
+
+import com.fasterxml.uuid.UUIDComparator;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexFactory;
+import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
+import org.apache.usergrid.persistence.index.query.CandidateResults;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Test on read style clean-up of stale ElasticSearch indexes.
+ */
+public class StaleIndexCleanupTest extends AbstractCoreIT {
+    private static final Logger logger = LoggerFactory.getLogger(StaleIndexCleanupTest.class );
+
+
+    @Test
+    public void testUpdateVersioning() throws Exception {
+
+        final EntityManager em = app.getEntityManager();
+
+        Entity thing = em.create("thing", new HashMap<String, Object>() {{
+            put("name", "thing1");
+        }});
+        em.refreshIndex();
+        
+        assertEquals( 1, queryCollectionCp("things", "select *").size() );
+
+        org.apache.usergrid.persistence.model.entity.Entity cpEntity = getCpEntity(thing);
+        UUID oldVersion = cpEntity.getVersion();
+
+        em.updateProperties(thing, new HashMap<String, Object>() {{
+            put("stuff", "widget");
+        }});
+        em.refreshIndex();
+
+        org.apache.usergrid.persistence.model.entity.Entity cpUpdated = getCpEntity(thing);
+        assertEquals( "widget", cpUpdated.getField("stuff").getValue());
+        UUID newVersion = cpUpdated.getVersion();
+
+        // this assertion fails
+        assertTrue( "New version is greater than old", 
+                UUIDComparator.staticCompare( newVersion, oldVersion ) > 0 );
+
+        // this fails too 
+        assertEquals( 2, queryCollectionCp("things", "select *").size() );
+    }
+
+
+    @Test
+    public void testStaleIndexCleanup() throws Exception {
+
+        logger.info("Started testStaleIndexCleanup()");
+
+        final EntityManager em = app.getEntityManager();
+
+        final List<Entity> things = new ArrayList<Entity>();
+
+        int numEntities = 1;
+        int numUpdates = 3;
+
+        // create 100 entities
+        for ( int i=0; i<numEntities; i++) {
+            final String thingName = "thing" + i;
+            things.add( em.create("thing", new HashMap<String, Object>() {{
+                put("name", thingName);
+            }}));
+        }
+        em.refreshIndex();
+
+        CandidateResults crs = queryCollectionCp( "things", "select *");
+        Assert.assertEquals( numEntities, crs.size() );
+
+        // update each one 10 times
+        for ( Entity thing : things ) {
+
+            for ( int j=0; j<numUpdates; j++) {
+                Entity toUpdate = em.get( thing.getUuid() );
+                thing.setProperty( "property"  + j, RandomStringUtils.randomAlphanumeric(10));
+                em.update(toUpdate);
+                em.refreshIndex();
+            }
+        }
+
+        // new query for total number of result candidates = 1000
+        crs = queryCollectionCp("things", "select *");
+        Assert.assertEquals( numEntities * numUpdates, crs.size() );
+
+        // query for results, should be 100 (and it triggers background clean up of stale indexes)
+
+        // wait a second for batch cleanup to complete
+
+        // query for total number of result candidates = 1000
+    }
+
+
+    /** 
+     * Go around EntityManager and get directly from Core Persistence.
+     */
+    private org.apache.usergrid.persistence.model.entity.Entity getCpEntity( EntityRef eref ) {
+
+        EntityManager em = app.getEntityManager();
+
+        CollectionScope cs = new CollectionScopeImpl(
+            new SimpleId( em.getApplicationId(), TYPE_APPLICATION),
+            new SimpleId( em.getApplicationId(), TYPE_APPLICATION),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( eref.getType() ));
+
+        EntityCollectionManagerFactory ecmf = 
+                CpSetup.getInjector().getInstance( EntityCollectionManagerFactory.class );
+
+        EntityCollectionManager ecm = ecmf.createCollectionManager(cs);
+
+        return ecm.load( new SimpleId( eref.getUuid(), eref.getType()))
+                .toBlocking().lastOrDefault(null);
+    } 
+
+
+    /** 
+     * Go around EntityManager and execute query directly against Core Persistence.
+     * Results may include stale index entries.
+     */
+    private CandidateResults queryCollectionCp( String collName, String query ) {
+
+        EntityManager em = app.getEntityManager();
+
+        EntityIndexFactory eif = CpSetup.getInjector().getInstance( EntityIndexFactory.class );
+
+        ApplicationScope as = new ApplicationScopeImpl( 
+            new SimpleId( em.getApplicationId(), TYPE_APPLICATION));
+        EntityIndex ei = eif.createEntityIndex( as );
+
+        IndexScope is = new IndexScopeImpl(
+            new SimpleId( em.getApplicationId(), TYPE_APPLICATION),
+            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
+        Query rcq = Query.fromQL(query);
+        rcq.setLimit(10000); // no paging
+
+        return ei.search( is, rcq );
+    }
+}