usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [48/50] git commit: Added new updated column serialization for collections
Date Wed, 12 Feb 2014 13:21:56 GMT
Added new updated column serialization for collections


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

Branch: refs/heads/optimistic-tx-semantics
Commit: feea5baa82f71c6a02f04de3abe75d0a9ef992d4
Parents: 499834a
Author: Todd Nine <tnine@apigee.com>
Authored: Mon Feb 10 17:32:07 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Mon Feb 10 17:32:07 2014 -0700

----------------------------------------------------------------------
 .../mvcc/changelog/ChangeLogGeneratorImpl.java  |   2 +-
 .../collection/mvcc/entity/MvccEntity.java      |  21 +++
 .../mvcc/entity/impl/MvccEntityImpl.java        |  30 +++--
 .../mvcc/stage/delete/DeleteStart.java          |   3 +-
 .../collection/mvcc/stage/write/WriteStart.java |   3 +-
 .../MvccEntitySerializationStrategyImpl.java    | 132 ++++++++++++++-----
 .../changelog/ChangeLogGeneratorImplTest.java   |  15 ++-
 .../mvcc/entity/impl/MvccEntityImplTest.java    |  28 ++--
 ...MvccEntitySerializationStrategyImplTest.java | 119 ++++++++++++++++-
 9 files changed, 294 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
index 51d175a..6d43918 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
@@ -65,7 +65,7 @@ public class ChangeLogGeneratorImpl implements ChangeLogGenerator {
             Entity entity = mvccEntity.getEntity().get();
             int compare = UUIDComparator.staticCompare( mvccEntity.getVersion(), minVersion
);
 
-            if ( compare == -1 ) { // less than minVersion
+            if ( compare < 0 ) { // less than minVersion
 
                 for ( Field field : entity.getFields() ) {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
index 7419041..890467c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
@@ -32,6 +32,22 @@ import com.google.common.base.Optional;
  */
 public interface MvccEntity {
 
+    /**
+     * The possible Status of the mvccEntity
+     */
+    public enum Status {
+
+        /**
+         * The entity being written represents a complete entity
+         */
+        COMPLETE,
+
+        /**
+         * The entity being written represents a partial entity
+         */
+        PARTIAL;
+    }
+
 
     /**
      * Get the entity for this context.
@@ -50,4 +66,9 @@ public interface MvccEntity {
      * Get the UUID of the entity
      */
     Id getId();
+
+    /**
+     * Get the status of the entity
+     */
+    Status getStatus();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
index 39e525e..8f29ac0 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -37,22 +37,25 @@ public class MvccEntityImpl implements MvccEntity {
     private final Id entityId;
     private final UUID version;
     private final Optional<Entity> entity;
+    private final Status status;
 
 
-    public MvccEntityImpl( final Id entityId, final UUID version, final Entity entity ) {
-        this( entityId, version, Optional.of( entity ) );
+    public MvccEntityImpl( final Id entityId, final UUID version, final Status status, final
Entity entity ) {
+        this( entityId, version, status, Optional.of( entity ) );
     }
 
 
     public MvccEntityImpl( 
-            final Id entityId, final UUID version, final Optional<Entity> entity )
{
+            final Id entityId, final UUID version, final Status status, final Optional<Entity>
entity ) {
         Preconditions.checkNotNull( entityId, "entity id is required" );
         Preconditions.checkNotNull( version, "version id is required" );
+        Preconditions.checkNotNull( status, "status  is required" );
         Preconditions.checkNotNull( entity, "entity  is required" );
 
         this.entityId = entityId;
         this.version = version;
         this.entity = entity;
+        this.status = status;
     }
 
 
@@ -75,21 +78,29 @@ public class MvccEntityImpl implements MvccEntity {
 
 
     @Override
+    public Status getStatus() {
+        return status;
+    }
+
+
+    @Override
     public boolean equals( final Object o ) {
         if ( this == o ) {
             return true;
         }
-        if ( o == null || getClass() != o.getClass() ) {
+        if ( !( o instanceof MvccEntityImpl ) ) {
             return false;
         }
 
         final MvccEntityImpl that = ( MvccEntityImpl ) o;
 
-        if ( !getId().equals( that.getId() ) ) {
+        if ( !entityId.equals( that.entityId ) ) {
             return false;
         }
-
-        if ( !getVersion().equals( that.getVersion() ) ) {
+        if ( status != that.status ) {
+            return false;
+        }
+        if ( !version.equals( that.version ) ) {
             return false;
         }
 
@@ -99,8 +110,9 @@ public class MvccEntityImpl implements MvccEntity {
 
     @Override
     public int hashCode() {
-        int result = 31 * getId().hashCode();
-        result = 31 * result + getVersion().hashCode();
+        int result = entityId.hashCode();
+        result = 31 * result + version.hashCode();
+        result = 31 * result + status.hashCode();
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/DeleteStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/DeleteStart.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/DeleteStart.java
index b7d6268..d0f344f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/DeleteStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/DeleteStart.java
@@ -106,8 +106,7 @@ public class DeleteStart implements Func1<CollectionIoEvent<Id>,
CollectionIoEve
 
 
         //create the mvcc entity for the next stage
-        final MvccEntityImpl nextStage = new MvccEntityImpl( 
-                entityId, version, Optional.<Entity>absent() );
+        final MvccEntityImpl nextStage = new MvccEntityImpl(entityId, version, MvccEntity.Status.COMPLETE,
Optional.<Entity>absent() );
 
 
         return new CollectionIoEvent<MvccEntity>( collectionScope, nextStage );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
index e2b2dc0..01fee57 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
@@ -78,7 +78,8 @@ public class WriteStart implements Func1<CollectionIoEvent<Entity>,
CollectionIo
 
 
             //create the mvcc entity for the next stage
-            final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, entity
);
+            //todo, we need to create a complete or partial update here (or sooner)
+            final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,
entity );
 
             return new CollectionIoEvent<MvccEntity>( collectionScope, nextStage );
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
index c31145e..82b673d 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.persistence.collection.serialization.impl;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
@@ -53,7 +54,11 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
 import com.netflix.astyanax.model.Column;
 import com.netflix.astyanax.model.ColumnList;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
+import com.netflix.astyanax.model.Composites;
 import com.netflix.astyanax.serializers.AbstractSerializer;
+import com.netflix.astyanax.serializers.BytesArraySerializer;
 import com.netflix.astyanax.serializers.ObjectSerializer;
 import com.netflix.astyanax.serializers.UUIDSerializer;
 
@@ -69,7 +74,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
     private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
 
-    private static final CollectionScopedRowKeySerializer<Id> ROW_KEY_SER = 
+    private static final CollectionScopedRowKeySerializer<Id> ROW_KEY_SER =
             new CollectionScopedRowKeySerializer<Id>( ID_SER );
 
     private static final MultiTennantColumnFamily<CollectionScope, Id, UUID> CF_ENTITY_DATA
=
@@ -94,12 +99,11 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         final UUID colName = entity.getVersion();
         final Id entityId = entity.getId();
 
-        final Optional<Entity> colValue = entity.getEntity();
-
         return doWrite( collectionScope, entityId, new RowOp() {
             @Override
             public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.putColumn( colName, SER.toByteBuffer( colValue ) );
+                colMutation.putColumn( colName,
+                        SER.toByteBuffer( new EntityWrapper( entity.getStatus(), entity.getEntity()
) ) );
             }
         } );
     }
@@ -115,8 +119,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         Column<UUID> column;
 
         try {
-            column = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( ScopedRowKey
-                    .fromKey( collectionScope, entityId ) )
+            column = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( ScopedRowKey.fromKey(
collectionScope, entityId ) )
                              .getColumn( version ).execute().getResult();
         }
 
@@ -129,7 +132,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         }
 
 
-        return new MvccEntityImpl( entityId, version, getEntity( column, entityId ) );
+        return getEntity( entityId, column );
     }
 
 
@@ -146,8 +149,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         ColumnList<UUID> columns = null;
         try {
             columns =
-                    keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( ScopedRowKey
-                            .fromKey( collectionScope, entityId ) )
+                    keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( ScopedRowKey.fromKey(
collectionScope, entityId ) )
                             .withColumnRange( version, null, false, maxSize ).execute().getResult();
         }
         catch ( ConnectionException e ) {
@@ -158,7 +160,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         List<MvccEntity> results = new ArrayList<MvccEntity>( columns.size()
);
 
         for ( Column<UUID> col : columns ) {
-            results.add( new MvccEntityImpl( entityId, col.getName(), getEntity( col, entityId
) ) );
+            results.add( getEntity( entityId, col ) );
         }
 
         return results;
@@ -176,7 +178,8 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         return doWrite( collectionScope, entityId, new RowOp() {
             @Override
             public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.putColumn( version, SER.toByteBuffer( value ) );
+                colMutation.putColumn( version, SER.toByteBuffer(
+                        new EntityWrapper( MvccEntity.Status.COMPLETE, Optional.<Entity>absent()
) ) );
             }
         } );
     }
@@ -218,24 +221,25 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
     private MutationBatch doWrite( final CollectionScope collectionScope, final Id entityId,
final RowOp op ) {
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
-        op.doOp( batch.withRow( CF_ENTITY_DATA, ScopedRowKey.fromKey( collectionScope, entityId
) ));
+        op.doOp( batch.withRow( CF_ENTITY_DATA, ScopedRowKey.fromKey( collectionScope, entityId
) ) );
 
         return batch;
     }
 
 
-    /**
-     * Set the id into the entity if it exists and return it.
-     */
-    private Optional<Entity> getEntity( final Column<UUID> column, final Id entityId
) {
-        final Optional<Entity> deSerialized = column.getValue( SER );
+    private MvccEntity getEntity( final Id entityId, final Column<UUID> col ) {
+
+        final UUID version = col.getName();
+
+        final EntityWrapper deSerialized = col.getValue( SER );
 
         //Inject the id into it.
-        if ( deSerialized.isPresent() ) {
-            EntityUtils.setId( deSerialized.get(), entityId );
+        if ( deSerialized.entity.isPresent() ) {
+            EntityUtils.setId( deSerialized.entity.get(), entityId );
         }
 
-        return deSerialized;
+
+        return new MvccEntityImpl( entityId, version, deSerialized.status, deSerialized.entity
);
     }
 
 
@@ -252,40 +256,108 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
 
     /**
+     * Simple bean wrapper for status and entity
+     */
+    private static class EntityWrapper {
+        private final MvccEntity.Status status;
+        private final Optional<Entity> entity;
+
+
+        private EntityWrapper( final MvccEntity.Status status, final Optional<Entity>
entity ) {
+            this.status = status;
+            this.entity = entity;
+        }
+    }
+
+
+    /**
      * TODO: Serializer for the entity. This just uses object serialization, change this
to use SMILE before production!
      * We want to retain the Optional wrapper.  It helps us easily mark something as cleaned
without removing the column
      * and makes it obvious that the entity could be missing in the api
      */
-    private static class EntitySerializer extends AbstractSerializer<Optional<Entity>>
{
+    private static class EntitySerializer extends AbstractSerializer<EntityWrapper>
{
 
+        private static final BytesArraySerializer BYTES_ARRAY_SERIALIZER = BytesArraySerializer.get();
         private static final ObjectSerializer SER = ObjectSerializer.get();
 
+        private static byte[] STATE_COMPLETE = new byte[] { 0 };
+        private static byte[] STATE_DELETED = new byte[] { 1 };
+        private static byte[] STATE_PARTIAL = new byte[] { 2 };
+
+        private static byte[] VERSION = new byte[] { 0 };
+
+
         //the marker for when we're passed a "null" value
         private static final byte[] EMPTY = new byte[] { 0x0 };
 
 
         @Override
-        public ByteBuffer toByteBuffer( final Optional<Entity> obj ) {
+        public ByteBuffer toByteBuffer( final EntityWrapper wrapper ) {
+
+
+            CompositeBuilder builder = Composites.newCompositeBuilder();
+
+
+            builder.addBytes( VERSION );
+
 
             //mark this version as empty
-            if ( !obj.isPresent() ) {
-                return ByteBuffer.wrap( EMPTY );
+            if ( !wrapper.entity.isPresent() ) {
+                //we're empty
+                builder.addBytes( STATE_DELETED );
+
+                return builder.build();
+            }
+
+            //we have an entity
+
+            if ( wrapper.status == MvccEntity.Status.COMPLETE ) {
+                builder.addBytes( STATE_COMPLETE );
+            }
+
+            else {
+                builder.addBytes( STATE_PARTIAL );
             }
 
-            return SER.toByteBuffer( obj.get() );
+            builder.addBytes( SER.toByteBuffer( wrapper.entity.get() ));
+
+            return builder.build();
         }
 
 
         @Override
-        public Optional<Entity> fromByteBuffer( final ByteBuffer byteBuffer ) {
+        public EntityWrapper fromByteBuffer( final ByteBuffer byteBuffer ) {
+
+            CompositeParser parser = Composites.newCompositeParser( byteBuffer );
 
-            final ByteBuffer check = byteBuffer.duplicate();
 
-            if ( check.remaining() == 1 && check.get() == EMPTY[0] ) {
-                return Optional.absent();
+            final byte[] version = parser.read( BYTES_ARRAY_SERIALIZER );
+
+            if ( !Arrays.equals( VERSION, version ) ) {
+                throw new UnsupportedOperationException( "A version of type " + version +
" is unsupported" );
+            }
+
+
+            final byte[] state = parser.read( BYTES_ARRAY_SERIALIZER );
+
+            /**
+             * It's been deleted, remove it
+             */
+            if ( Arrays.equals( STATE_DELETED, state ) ) {
+                return new EntityWrapper( MvccEntity.Status.COMPLETE, Optional.<Entity>absent()
);
             }
 
-            return Optional.of( ( Entity ) SER.fromByteBuffer( byteBuffer ) );
+            final Entity storedEntity = ( Entity ) parser.read( SER );
+
+            final Optional<Entity> entity = Optional.of( storedEntity );
+
+            if ( Arrays.equals( STATE_COMPLETE, state ) ) {
+                return new EntityWrapper( MvccEntity.Status.COMPLETE, entity );
+            }
+
+            //it's partial by default
+
+            return new EntityWrapper( MvccEntity.Status.PARTIAL, entity );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImplTest.java
b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImplTest.java
index c435eab..d64cc44 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImplTest.java
@@ -23,8 +23,10 @@ import java.util.List;
 
 import org.jukito.JukitoModule;
 import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
 import org.junit.Assert;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -35,6 +37,8 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.collection.guice.CollectionModule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
 import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
 import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
@@ -53,12 +57,19 @@ import rx.Observable;
  * Test basic operation of change log
  */
 @RunWith( JukitoRunner.class )
+@UseModules( TestCollectionModule.class )
 public class ChangeLogGeneratorImplTest {
     private static final Logger LOG = LoggerFactory.getLogger( ChangeLogGeneratorImplTest.class
);
 
     @ClassRule
     public static CassandraRule rule = new CassandraRule();
 
+
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
     @Inject
     private EntityCollectionManagerFactory factory;
 
@@ -66,7 +77,9 @@ public class ChangeLogGeneratorImplTest {
     MvccEntitySerializationStrategy mvccEntitySerializationStrategy;
 
     /**
-     * Test that change log creation follows Todd's example. 
+     * Test that change log creation follows Todd's example.
+     * TODO, can we do this without doing serialization I/O on the entities?  This seems
out of the scope of the changelog
+     * itself
      */
     @Test
     public void testBasicOperation() throws ConnectionException {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
index 4205da7..36bce42 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
@@ -5,6 +5,7 @@ import java.util.UUID;
 
 import org.junit.Test;
 
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -21,28 +22,35 @@ public class MvccEntityImplTest {
     @Test(expected = NullPointerException.class)
     public void entityIdRequired() {
 
-        new MvccEntityImpl( null, UUIDGenerator.newTimeUUID(), Optional.of( new Entity()
) );
+        new MvccEntityImpl( null, UUIDGenerator.newTimeUUID(),  MvccEntity.Status.COMPLETE,Optional.of(
new Entity() ) );
     }
 
 
     @Test(expected = NullPointerException.class)
     public void versionRequired() {
 
-        new MvccEntityImpl( new SimpleId( "test" ), null, Optional.of( new Entity() ) );
+        new MvccEntityImpl( new SimpleId( "test" ), null,  MvccEntity.Status.COMPLETE, Optional.of(
new Entity() ) );
     }
 
 
     @Test(expected = NullPointerException.class)
     public void entityRequired() {
 
-        new MvccEntityImpl( new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), ( Entity
) null );
+        new MvccEntityImpl( new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), MvccEntity.Status.COMPLETE,
( Entity ) null );
     }
 
 
     @Test(expected = NullPointerException.class)
     public void optionalRequired() {
 
-        new MvccEntityImpl( new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), ( Optional
) null );
+        new MvccEntityImpl( new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), MvccEntity.Status.COMPLETE,
( Optional ) null );
+    }
+
+
+    @Test(expected = NullPointerException.class)
+    public void statusRequired() {
+
+        new MvccEntityImpl( new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), null, (
Entity ) null );
     }
 
 
@@ -53,7 +61,7 @@ public class MvccEntityImplTest {
         final UUID version = UUIDGenerator.newTimeUUID();
         final Entity entity = new Entity( entityId );
 
-        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, entity );
+        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,
entity );
 
         assertEquals( entityId, logEntry.getId() );
         assertEquals( version, logEntry.getVersion() );
@@ -68,7 +76,7 @@ public class MvccEntityImplTest {
         final UUID version = UUIDGenerator.newTimeUUID();
         final Entity entity = new Entity( entityId );
 
-        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, Optional.of( entity
) );
+        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version,  MvccEntity.Status.COMPLETE,Optional.of(
entity ) );
 
         assertEquals( entityId, logEntry.getId() );
         assertEquals( version, logEntry.getVersion() );
@@ -83,9 +91,9 @@ public class MvccEntityImplTest {
         final UUID version = UUIDGenerator.newTimeUUID();
         final Entity entity = new Entity( entityId );
 
-        MvccEntityImpl first = new MvccEntityImpl( entityId, version, Optional.of( entity
) );
+        MvccEntityImpl first = new MvccEntityImpl( entityId, version,  MvccEntity.Status.COMPLETE,
Optional.of( entity ) );
 
-        MvccEntityImpl second = new MvccEntityImpl( entityId, version, Optional.of( entity
) );
+        MvccEntityImpl second = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,
Optional.of( entity ) );
 
         assertEquals( first, second );
     }
@@ -98,9 +106,9 @@ public class MvccEntityImplTest {
         final UUID version = UUIDGenerator.newTimeUUID();
         final Entity entity = new Entity( entityId );
 
-        MvccEntityImpl first = new MvccEntityImpl( entityId, version, Optional.of( entity
) );
+        MvccEntityImpl first = new MvccEntityImpl( entityId, version,  MvccEntity.Status.COMPLETE,Optional.of(
entity ) );
 
-        MvccEntityImpl second = new MvccEntityImpl( entityId, version, Optional.of( entity
) );
+        MvccEntityImpl second = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,
Optional.of( entity ) );
 
         assertEquals( first.hashCode(), second.hashCode() );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/feea5baa/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
index ed7c827..c4ccfd4 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
@@ -29,6 +29,7 @@ import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.collection.migration.MigrationManagerFig;
 import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
 import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
 import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
 import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
 import org.apache.usergrid.persistence.collection.util.EntityUtils;
@@ -147,7 +148,7 @@ public class MvccEntitySerializationStrategyImplTest {
         entity.setField( uuidField );
 
 
-        MvccEntity saved = new MvccEntityImpl( id, version, Optional.of( entity ) );
+        MvccEntity saved = new MvccEntityImpl( id, version, MvccEntity.Status.COMPLETE, Optional.of(
entity ) );
 
 
         //persist the entity
@@ -236,7 +237,7 @@ public class MvccEntitySerializationStrategyImplTest {
         EntityUtils.setVersion( entity, version );
 
 
-        MvccEntity saved = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+        MvccEntity saved = new MvccEntityImpl( entityId, version, MvccEntity.Status.COMPLETE,
Optional.of( entity ) );
 
 
         //persist the entity
@@ -297,7 +298,7 @@ public class MvccEntitySerializationStrategyImplTest {
         EntityUtils.setVersion( entityv1, version1 );
 
 
-        MvccEntity saved = new MvccEntityImpl( id, version1, Optional.of( entityv1 ) );
+        MvccEntity saved = new MvccEntityImpl( id, version1, MvccEntity.Status.COMPLETE,
Optional.of( entityv1 ) );
 
 
         //persist the entity
@@ -321,7 +322,7 @@ public class MvccEntitySerializationStrategyImplTest {
         EntityUtils.setVersion( entityv1, version2 );
 
 
-        MvccEntity savedV2 = new MvccEntityImpl( id, version2, Optional.of( entityv2 ) );
+        MvccEntity savedV2 = new MvccEntityImpl( id, version2, MvccEntity.Status.COMPLETE,
Optional.of( entityv2 ) );
 
         serializationStrategy.write( context, savedV2 ).execute();
 
@@ -339,7 +340,7 @@ public class MvccEntitySerializationStrategyImplTest {
 
         final Optional<Entity> empty = Optional.absent();
 
-        MvccEntity clearedV3 = new MvccEntityImpl( id, version3, empty );
+        MvccEntity clearedV3 = new MvccEntityImpl( id, version3, MvccEntity.Status.COMPLETE,
empty );
 
         MvccEntity returnedV3 = serializationStrategy.load( context, id, version3 );
 
@@ -386,6 +387,112 @@ public class MvccEntitySerializationStrategyImplTest {
     }
 
 
+    @Test
+    public void writeLoadDeletePartial() throws ConnectionException {
+
+        final Id organizationId = new SimpleId( "organization" );
+        final Id applicationId = new SimpleId( "application" );
+        final String name = "test";
+
+        CollectionScope context = new CollectionScopeImpl( organizationId,  applicationId,
name );
+
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final String type = "test";
+
+        final Id id = new SimpleId( entityId, type );
+
+        Entity entity = new Entity( id );
+
+        EntityUtils.setVersion( entity, version );
+
+
+        BooleanField boolField = new BooleanField( "boolean", false );
+        DoubleField doubleField = new DoubleField( "double", 1d );
+        IntegerField intField = new IntegerField( "long", 1 );
+        LongField longField = new LongField( "int", 1l );
+        StringField stringField = new StringField( "name", "test" );
+        UUIDField uuidField = new UUIDField( "uuid", UUIDGenerator.newTimeUUID() );
+
+        entity.setField( boolField );
+        entity.setField( doubleField );
+        entity.setField( intField );
+        entity.setField( longField );
+        entity.setField( stringField );
+        entity.setField( uuidField );
+
+
+        MvccEntity saved = new MvccEntityImpl( id, version, MvccEntity.Status.PARTIAL, Optional.of(
entity ) );
+
+
+        //persist the entity
+        serializationStrategy.write( context, saved ).execute();
+
+        //now load it back
+
+        MvccEntity returned = serializationStrategy.load( context, id, version );
+
+        assertEquals( "Mvcc entities are the same", saved, returned );
+
+
+        assertEquals( id, entity.getId() );
+
+
+        Field<Boolean> boolFieldReturned = entity.getField( boolField.getName() );
+
+        assertSame( boolField, boolFieldReturned );
+
+        Field<Double> doubleFieldReturned = entity.getField( doubleField.getName()
);
+
+        assertSame( doubleField, doubleFieldReturned );
+
+        Field<Integer> intFieldReturned = entity.getField( intField.getName() );
+
+        assertSame( intField, intFieldReturned );
+
+        Field<Long> longFieldReturned = entity.getField( longField.getName() );
+
+        assertSame( longField, longFieldReturned );
+
+        Field<String> stringFieldReturned = entity.getField( stringField.getName()
);
+
+        assertSame( stringField, stringFieldReturned );
+
+        Field<UUID> uuidFieldReturned = entity.getField( uuidField.getName() );
+
+        assertSame( uuidField, uuidFieldReturned );
+
+
+        Set<Field> results = new HashSet<Field>();
+        results.addAll( entity.getFields() );
+
+
+        assertTrue( results.contains( boolField ) );
+        assertTrue( results.contains( doubleField ) );
+        assertTrue( results.contains( intField ) );
+        assertTrue( results.contains( longField ) );
+        assertTrue( results.contains( stringField ) );
+        assertTrue( results.contains( uuidField ) );
+
+        assertEquals( 6, results.size() );
+
+
+        assertEquals( id, entity.getId() );
+        assertEquals( version, entity.getVersion() );
+
+
+        //now delete it
+        serializationStrategy.delete( context, id, version ).execute();
+
+        //now get it, should be gone
+
+        returned = serializationStrategy.load( context, id, version );
+
+        assertNull( returned );
+    }
+
+
     @Test(expected = NullPointerException.class)
     public void writeParamsContext() throws ConnectionException {
         serializationStrategy.write( null, mock( MvccEntity.class ) );
@@ -477,4 +584,6 @@ public class MvccEntitySerializationStrategyImplTest {
 
 
 
+
+
 }


Mime
View raw message