You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/10/09 21:23:45 UTC

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

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

Conflicts:
	stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
	stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
	stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java


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

Branch: refs/heads/collection_multiget
Commit: ac61f132372f653cf14561fe7a03cb7cb6d8a79c
Parents: f1a88aa 81d4e0e
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 9 11:47:51 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 9 11:47:51 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 179 +++++++++++--------
 .../corepersistence/StaleIndexCleanupTest.java  |  43 ++++-
 .../collection/EntityCollectionManager.java     |   5 +
 .../exception/WriteUniqueVerifyException.java   |   1 -
 .../collection/guice/CollectionModule.java      |  12 +-
 .../impl/EntityCollectionManagerImpl.java       |  13 +-
 .../collection/EntityCollectionManagerIT.java   |  17 ++
 7 files changed, 175 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ac61f132/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
index e5917b0,6756cdc..2625078
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
@@@ -19,8 -19,7 +19,9 @@@
  package org.apache.usergrid.persistence.collection;
  
  
 +import java.util.Collection;
 +
+ import java.util.UUID;
  import org.apache.usergrid.persistence.model.entity.Entity;
  import org.apache.usergrid.persistence.model.entity.Id;
  
@@@ -53,17 -52,16 +54,21 @@@ public interface EntityCollectionManage
       */
      public Observable<Entity> load( Id entityId );
  
+     /**
+      * Return the latest version of the specified entity.
+      */
+     public Observable<UUID> getLatestVersion( Id entityId );
 +    //TODO TN Change load to use multiget and return multiple entities.  Only supports loading 1k per load operation.
 +
 +    /**
 +     * Load all the entityIds into the observable entity set
 +     * @param entityIds
 +     * @return
 +     */
 +    public Observable<EntitySet> load(Collection<Id> entityIds);
  
 -    //TODO TN Change load to use multiget and return multiple entities.  
 -    // Only supports loading 1k per load operation.
  
 -    //TODO Dave add a load versions using a multiget that will return a latest version 
 -    //structure for a collection of entity Ids
 +    //TODO Dave add a load versions using a multiget that will return a latest version structure for a collection of entity Ids
  
  
      /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ac61f132/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 39df9cb,0efb21c..5fe2fbb
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@@ -80,7 -76,11 +83,8 @@@ public class EntityCollectionManagerImp
      private final WriteOptimisticVerify writeOptimisticVerify;
      private final WriteCommit writeCommit;
      private final RollbackAction rollback;
+     private final GetVersion getVersion;
  
 -    //load stages
 -    private final Load load;
 -
  
      //delete stages
      private final MarkStart markStart;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ac61f132/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 823cb87,34061ee..a7f9ea2
--- 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
@@@ -402,130 -389,24 +402,147 @@@ public class EntityCollectionManagerIT 
          assertNotNull( "A new version must be assigned", newVersion );
  
          // new Version should be > old version
 -        assertTrue( UUIDComparator.staticCompare( newVersion, oldVersion ) > 0);
 +        assertTrue( UUIDComparator.staticCompare( newVersion, oldVersion ) > 0 );
 +    }
 +
 +
 +    @Test
 +    public void writeMultiget() {
 +
 +        final CollectionScope context =
 +                new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
 +        final EntityCollectionManager manager = factory.createCollectionManager( context );
 +
 +        final int multigetSize = serializationFig.getMaxLoadSize();
 +
 +        final List<Entity> writtenEntities = new ArrayList<>( multigetSize );
 +        final List<Id> entityIds = new ArrayList<>( multigetSize );
 +
 +        for ( int i = 0; i < multigetSize; i++ ) {
 +            final Entity entity = new Entity( new SimpleId( "test" ) );
 +
 +            final Entity written = manager.write( entity ).toBlocking().last();
 +
 +            writtenEntities.add( written );
 +            entityIds.add( written.getId() );
 +        }
 +
 +
 +        final EntitySet entitySet = manager.load( entityIds ).toBlocking().lastOrDefault( null );
 +
 +        assertNotNull( entitySet );
 +
 +        assertEquals(multigetSize, entitySet.size());
 +        assertFalse(entitySet.isEmpty());
 +
 +        /**
 +         * Validate every element exists
 +         */
 +        for(int i = 0; i < multigetSize; i ++){
 +            final Entity expected = writtenEntities.get( i );
 +
 +            final MvccEntity returned = entitySet.getEntity( expected.getId() );
 +
 +            assertEquals("Same entity returned", expected, returned.getEntity().get());
 +        }
 +
 +
      }
  
 +
 +    /**
 +     * Perform a multiget where every entity will need repaired on load
 +     */
 +    @Test
 +     public void writeMultigetRepair() {
 +
 +           final CollectionScope context =
 +                   new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
 +           final EntityCollectionManager manager = factory.createCollectionManager( context );
 +
 +           final int multigetSize = serializationFig.getMaxLoadSize();
 +
 +           final List<Entity> writtenEntities = new ArrayList<>( multigetSize );
 +           final List<Id> entityIds = new ArrayList<>( multigetSize );
 +
 +           for ( int i = 0; i < multigetSize; i++ ) {
 +               final Entity entity = new Entity( new SimpleId( "test" ) );
 +
 +               final Entity written = manager.write( entity ).toBlocking().last();
 +
 +               written.setField( new BooleanField( "updated", true ) );
 +
 +               final Entity updated  = manager.update( written ).toBlocking().last();
 +
 +               writtenEntities.add( updated );
 +               entityIds.add( updated.getId() );
 +           }
 +
 +
 +           final EntitySet entitySet = manager.load( entityIds ).toBlocking().lastOrDefault( null );
 +
 +           assertNotNull( entitySet );
 +
 +           assertEquals(multigetSize, entitySet.size());
 +           assertFalse(entitySet.isEmpty());
 +
 +           /**
 +            * Validate every element exists
 +            */
 +           for(int i = 0; i < multigetSize; i ++){
 +               final Entity expected = writtenEntities.get( i );
 +
 +               final MvccEntity returned = entitySet.getEntity( expected.getId() );
 +
 +               assertEquals("Same entity returned", expected, returned.getEntity().get());
 +
 +               assertTrue( ( Boolean ) returned.getEntity().get().getField( "updated" ).getValue() );
 +           }
 +
 +
 +       }
 +
 +
 +
 +    @Test(expected = IllegalArgumentException.class)
 +    public void readTooLarge() {
 +
 +        final CollectionScope context =
 +                new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
 +        final EntityCollectionManager manager = factory.createCollectionManager( context );
 +
 +        final int multigetSize = serializationFig.getMaxLoadSize() +1;
 +
 +
 +        final List<Id> entityIds = new ArrayList<>( multigetSize );
 +
 +        for ( int i = 0; i < multigetSize; i++ ) {
 +
 +            entityIds.add( new SimpleId( "simple" ) );
 +        }
 +
 +
 +        //should throw an exception
 +        manager.load( entityIds ).toBlocking().lastOrDefault( null );
 +
 +
 +
 +    }
+     @Test
+     public void testGetVersion() {
+ 
+         CollectionScope context = new CollectionScopeImpl(
+                 new SimpleId( "organization" ),  new SimpleId( "test" ), "test" );
+ 
+         Entity newEntity = new Entity( new SimpleId( "test" ) );
+         EntityCollectionManager manager = factory.createCollectionManager( context );
+         Observable<Entity> observable = manager.write( newEntity );
+         Entity created = observable.toBlocking().lastOrDefault( null );
+ 
+         assertNotNull("Id was assigned", created.getId() );
+         assertNotNull("Version was assigned", created.getVersion() );
+ 
+         assertTrue(UUIDComparator.staticCompare(created.getVersion(), 
+             manager.getLatestVersion( created.getId() ).toBlocking().lastOrDefault(null)) == 0);
+     }
  }