usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [4/5] Major refactor complete. Need to work on scheduling of futures.
Date Wed, 04 Dec 2013 03:45:18 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategy.java
index 3d16fe1..f3350ad 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategy.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategy.java
@@ -21,7 +21,7 @@ public interface MvccEntitySerializationStrategy
      * @param entity The entity to persist
      * @return The MutationBatch operations for this update
      */
-    public MutationBatch write( MvccEntity entity );
+    public MutationBatch write(CollectionContext context, MvccEntity entity );
 
 
     /**
@@ -35,7 +35,7 @@ public interface MvccEntitySerializationStrategy
      * If the entity version has been cleared, the MvccEntity will be returned, but the optional entity
      * will not be set
      */
-    public MvccEntity load( CollectionContext context, UUID entityId, UUID version ) throws ConnectionException;
+    public MvccEntity load( CollectionContext context, UUID entityId, UUID version );
 
     /**
      * Load a list, from highest to lowest of the entity with versions <= version up to maxSize elements
@@ -48,8 +48,7 @@ public interface MvccEntitySerializationStrategy
      * @return A list of entities up to max size ordered from max(UUID)=> min(UUID).  The return value should be null safe
      * and return an empty list when there are no matches
      */
-    public List<MvccEntity> load( CollectionContext context, UUID entityId, UUID version, int maxSize )
-            throws ConnectionException;
+    public List<MvccEntity> load( CollectionContext context, UUID entityId, UUID version, int maxSize );
 
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategyImpl.java
deleted file mode 100644
index afec2f8..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccEntitySerializationStrategyImpl.java
+++ /dev/null
@@ -1,227 +0,0 @@
-package org.apache.usergrid.persistence.collection.serialization;
-
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.cassandra.db.marshal.ReversedType;
-import org.apache.cassandra.db.marshal.UUIDType;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.collection.migration.CollectionColumnFamily;
-import org.apache.usergrid.persistence.collection.migration.Migration;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntityImpl;
-import org.apache.usergrid.persistence.model.entity.Entity;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.netflix.astyanax.ColumnListMutation;
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.MutationBatch;
-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.ColumnFamily;
-import com.netflix.astyanax.model.ColumnList;
-import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.ObjectSerializer;
-import com.netflix.astyanax.serializers.UUIDSerializer;
-
-
-/** @author tnine */
-@Singleton
-public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializationStrategy, Migration {
-
-
-    private static final EntitySerializer SER = new EntitySerializer();
-
-
-    private static final ColumnFamily<UUID, UUID> CF_ENTITY_DATA =
-            new ColumnFamily<UUID, UUID>( "Entity_Version_Data", UUIDSerializer.get(), UUIDSerializer.get() );
-
-
-    protected final Keyspace keyspace;
-
-
-    @Inject
-    public MvccEntitySerializationStrategyImpl( final Keyspace keyspace ) {
-        this.keyspace = keyspace;
-    }
-
-
-    @Override
-    public MutationBatch write( final MvccEntity entity ) {
-        Preconditions.checkNotNull( entity, "entity is required" );
-
-        final UUID colName = entity.getVersion();
-        final UUID entityId = entity.getUuid();
-
-        final Optional<Entity> colValue = entity.getEntity();
-
-        return doWrite( entityId, new RowOp() {
-            @Override
-            public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.putColumn( colName, SER.toByteBuffer( colValue ) );
-            }
-        } );
-    }
-
-
-    @Override
-    public MvccEntity load( final CollectionContext context, final UUID entityId, final UUID version )
-            throws ConnectionException {
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-
-
-        Column<UUID> column;
-
-        try {
-            column = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( entityId ).getColumn( version ).execute()
-                             .getResult();
-        }
-
-        catch ( NotFoundException e ) {
-            //swallow, there's just no column
-            return null;
-        }
-
-
-        return new MvccEntityImpl( context, entityId, version, column.getValue( SER ) );
-    }
-
-
-    @Override
-    public List<MvccEntity> load( final CollectionContext context, final UUID entityId, final UUID version,
-                                  final int maxSize ) throws ConnectionException {
-
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-        Preconditions.checkArgument( maxSize > 0, "max Size must be greater than 0" );
-
-
-        ColumnList<UUID> columns = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( entityId )
-                                           .withColumnRange( version, null, false, maxSize ).execute().getResult();
-
-
-        List<MvccEntity> results = new ArrayList<MvccEntity>( columns.size() );
-
-        for ( Column<UUID> col : columns ) {
-            results.add( new MvccEntityImpl( context, entityId, col.getName(), col.getValue( SER ) ) );
-        }
-
-        return results;
-    }
-
-
-    @Override
-    public MutationBatch clear( final CollectionContext context, final UUID entityId, final UUID version ) {
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-
-        final Optional<Entity> value = Optional.absent();
-
-        return doWrite( entityId, new RowOp() {
-            @Override
-            public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.putColumn( version, SER.toByteBuffer( value ) );
-            }
-        } );
-    }
-
-
-    @Override
-    public MutationBatch delete( final CollectionContext context, final UUID entityId, final UUID version ) {
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-
-
-        return doWrite( entityId, new RowOp() {
-            @Override
-            public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.deleteColumn( version );
-            }
-        } );
-    }
-
-
-    @Override
-    public Collection<CollectionColumnFamily> getColumnFamilies() {
-
-        //create the CF entity data.  We want it reversed b/c we want the most recent version at the top of the
-        //row for fast seeks
-        CollectionColumnFamily cf = new CollectionColumnFamily( CF_ENTITY_DATA,
-                ReversedType.class.getName() + "(" + UUIDType.class.getName() + ")", true );
-
-
-        return Collections.singleton( cf );
-    }
-
-
-    /** Do the write on the correct row for the entity id with the operation */
-    private MutationBatch doWrite( UUID entityId, RowOp op ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch();
-
-            op.doOp( batch.withRow( CF_ENTITY_DATA, entityId ) );
-
-        return batch;
-    }
-
-
-    /** Simple callback to perform puts and deletes with a common row setup code */
-    private static interface RowOp {
-
-        /** The operation to perform on the row */
-        void doOp( ColumnListMutation<UUID> colMutation );
-    }
-
-
-    /**
-     * 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 final ObjectSerializer SER = ObjectSerializer.get();
-
-        //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 ) {
-
-            //mark this version as empty
-            if ( !obj.isPresent() ) {
-                return ByteBuffer.wrap( EMPTY );
-            }
-
-            return SER.toByteBuffer( obj.get() );
-        }
-
-
-        @Override
-        public Optional<Entity> fromByteBuffer( final ByteBuffer byteBuffer ) {
-
-            final ByteBuffer check = byteBuffer.duplicate();
-
-            if ( check.remaining() == 1 && check.get() == EMPTY[0] ) {
-                return Optional.absent();
-            }
-
-            return Optional.of( ( Entity ) SER.fromByteBuffer( byteBuffer ) );
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategy.java
index 3206e60..e79e95f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategy.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategy.java
@@ -21,7 +21,7 @@ public interface MvccLogEntrySerializationStrategy
      * @param entry the entry to write
      * @return The mutation batch with the mutation operations for this write.
      */
-    public MutationBatch write( MvccLogEntry entry );
+    public MutationBatch write( final CollectionContext context, MvccLogEntry entry );
 
     /**
      * Load and return the stage with the given id and a version that is <= the version provided

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategyImpl.java
deleted file mode 100644
index a418ecc..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/MvccLogEntrySerializationStrategyImpl.java
+++ /dev/null
@@ -1,238 +0,0 @@
-package org.apache.usergrid.persistence.collection.serialization;
-
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.cassandra.db.marshal.ReversedType;
-import org.apache.cassandra.db.marshal.UUIDType;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.collection.migration.CollectionColumnFamily;
-import org.apache.usergrid.persistence.collection.migration.Migration;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntryImpl;
-import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
-
-import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-import com.netflix.astyanax.ColumnListMutation;
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.MutationBatch;
-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.ColumnFamily;
-import com.netflix.astyanax.model.ColumnList;
-import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.UUIDSerializer;
-
-
-/**
- * Simple implementation for reading and writing log entries
- *
- * @author tnine
- */
-@Singleton
-public class MvccLogEntrySerializationStrategyImpl implements MvccLogEntrySerializationStrategy, Migration {
-
-    public static final String TIMEOUT_PROP = "collection.stage.transient.timeout";
-
-    private static final StageSerializer SER = new StageSerializer();
-
-    private static final ColumnFamily<UUID, UUID> CF_ENTITY_LOG =
-            new ColumnFamily<UUID, UUID>( "Entity_Log", UUIDSerializer.get(), UUIDSerializer.get() );
-
-
-    protected final Keyspace keyspace;
-    protected final int timeout;
-
-
-    @Inject
-    public MvccLogEntrySerializationStrategyImpl( final Keyspace keyspace, @Named( TIMEOUT_PROP ) final int timeout ) {
-        this.keyspace = keyspace;
-        this.timeout = timeout;
-    }
-
-
-    @Override
-    public MutationBatch write( final MvccLogEntry entry ) {
-
-        Preconditions.checkNotNull( entry, "entry is required" );
-
-
-        final Stage stage = entry.getStage();
-        final UUID colName = entry.getVersion();
-
-        return doWrite( entry.getContext(), entry.getEntityId(), new RowOp() {
-            @Override
-            public void doOp( final ColumnListMutation<UUID> colMutation ) {
-
-                //Write the stage with a timeout, it's set as transient
-                if ( stage.isTransient() ) {
-                    colMutation.putColumn( colName, stage, SER, timeout );
-                    return;
-                }
-
-                //otherwise it's persistent, write it with no expiration
-                colMutation.putColumn( colName, stage, SER, null );
-            }
-        } );
-    }
-
-
-    @Override
-    public MvccLogEntry load( final CollectionContext context, final UUID entityId, final UUID version )
-            throws ConnectionException {
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-
-
-        Column<UUID> result;
-
-        try {
-            result = keyspace.prepareQuery( CF_ENTITY_LOG ).getKey( entityId ).getColumn( version ).execute()
-                             .getResult();
-        }
-        catch ( NotFoundException nfe ) {
-            return null;
-        }
-
-
-        final Stage stage = result.getValue( SER );
-
-        return new MvccLogEntryImpl( context, entityId, version, stage );
-    }
-
-
-    @Override
-    public List<MvccLogEntry> load( final CollectionContext context, final UUID entityId, final UUID version,
-                                    final int maxSize ) throws ConnectionException {
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version is required" );
-        Preconditions.checkArgument( maxSize > 0, "max Size must be greater than 0" );
-
-
-        ColumnList<UUID> columns = keyspace.prepareQuery( CF_ENTITY_LOG ).getKey( entityId )
-                                           .withColumnRange( version, null, false, maxSize ).execute().getResult();
-
-
-        List<MvccLogEntry> results = new ArrayList<MvccLogEntry>( columns.size() );
-
-        for ( Column<UUID> col : columns ) {
-            final UUID storedVersion = col.getName();
-            final Stage stage = col.getValue( SER );
-
-            results.add( new MvccLogEntryImpl( context, entityId, storedVersion, stage ) );
-        }
-
-        return results;
-    }
-
-
-    @Override
-    public MutationBatch delete( final CollectionContext context, final UUID entityId, final UUID version ) {
-
-        Preconditions.checkNotNull( context, "context is required" );
-        Preconditions.checkNotNull( entityId, "entityId is required" );
-        Preconditions.checkNotNull( version, "version context is required" );
-
-        return doWrite( context, entityId, new RowOp() {
-            @Override
-            public void doOp( final ColumnListMutation<UUID> colMutation ) {
-                colMutation.deleteColumn( version );
-            }
-        } );
-    }
-
-
-    @Override
-    public Collection<CollectionColumnFamily> getColumnFamilies() {
-        //create the CF entity data.  We want it reversed b/c we want the most recent version at the top of the
-        //row for fast seeks
-        CollectionColumnFamily cf = new CollectionColumnFamily( CF_ENTITY_LOG,
-                ReversedType.class.getName() + "(" + UUIDType.class.getName() + ")", true );
-
-
-        return Collections.singleton( cf );
-    }
-
-
-    /** Simple callback to perform puts and deletes with a common row setup code */
-    private static interface RowOp {
-
-        /** The operation to perform on the row */
-        void doOp( ColumnListMutation<UUID> colMutation );
-    }
-
-
-    /**
-     * Do the column update or delete for the given column and row key
-     *
-     * @param context We need to use this when getting the keyspace
-     */
-    private MutationBatch doWrite( CollectionContext context, UUID entityId, RowOp op ) {
-
-        final MutationBatch batch = keyspace.prepareMutationBatch();
-
-        op.doOp( batch.withRow( CF_ENTITY_LOG, entityId ) );
-
-        return batch;
-    }
-
-
-    /** Internal stage cache */
-    private static class StageCache {
-        private Map<Byte, Stage> values = new HashMap<Byte, Stage>( Stage.values().length );
-
-
-        private StageCache() {
-            for ( Stage stage : Stage.values() ) {
-
-                final byte stageValue = stage.getId();
-
-                values.put( stageValue, stage );
-            }
-        }
-
-
-        /** Get the stage with the byte value */
-        private Stage getStage( final byte value ) {
-            return values.get( value );
-        }
-    }
-
-
-    public static class StageSerializer extends AbstractSerializer<Stage> {
-
-        /** Used for caching the byte => stage mapping */
-        private static final StageCache CACHE = new StageCache();
-
-
-        @Override
-        public ByteBuffer toByteBuffer( final Stage obj ) {
-            ByteBuffer buff = ByteBuffer.allocate( 1 );
-            buff.put( obj.getId() );
-            buff.rewind();
-            return buff;
-        }
-
-
-        @Override
-        public Stage fromByteBuffer( final ByteBuffer byteBuffer ) {
-            final byte value  = byteBuffer.get();
-
-            return CACHE.getStage(value);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/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
new file mode 100644
index 0000000..7a5c5c5
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
@@ -0,0 +1,238 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.cassandra.db.marshal.ReversedType;
+import org.apache.cassandra.db.marshal.UUIDType;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
+import org.apache.usergrid.persistence.collection.migration.CollectionColumnFamily;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
+import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.netflix.astyanax.ColumnListMutation;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+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.ColumnFamily;
+import com.netflix.astyanax.model.ColumnList;
+import com.netflix.astyanax.serializers.AbstractSerializer;
+import com.netflix.astyanax.serializers.ObjectSerializer;
+import com.netflix.astyanax.serializers.UUIDSerializer;
+
+
+/** @author tnine */
+@Singleton
+public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializationStrategy, Migration {
+
+
+
+    private static final EntitySerializer SER = new EntitySerializer();
+
+
+    private static final ColumnFamily<UUID, UUID> CF_ENTITY_DATA =
+            new ColumnFamily<UUID, UUID>( "Entity_Version_Data", UUIDSerializer.get(), UUIDSerializer.get() );
+
+
+    protected final Keyspace keyspace;
+
+
+    @Inject
+    public MvccEntitySerializationStrategyImpl( final Keyspace keyspace ) {
+        this.keyspace = keyspace;
+    }
+
+
+    @Override
+    public MutationBatch write(final CollectionContext context, final MvccEntity entity ) {
+        Preconditions.checkNotNull( entity, "entity is required" );
+
+        final UUID colName = entity.getVersion();
+        final UUID entityId = entity.getUuid();
+
+        final Optional<Entity> colValue = entity.getEntity();
+
+        return doWrite( entityId, new RowOp() {
+            @Override
+            public void doOp( final ColumnListMutation<UUID> colMutation ) {
+                colMutation.putColumn( colName, SER.toByteBuffer( colValue ) );
+            }
+        } );
+    }
+
+
+    @Override
+    public MvccEntity load( final CollectionContext context, final UUID entityId, final UUID version ) {
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+
+
+        Column<UUID> column;
+
+        try {
+            column = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( entityId ).getColumn( version ).execute()
+                             .getResult();
+        }
+
+        catch ( NotFoundException e ) {
+            //swallow, there's just no column
+            return null;
+        }
+        catch ( ConnectionException e ) {
+            throw new CollectionRuntimeException( "An error occurred connecting to cassandra", e );
+        }
+
+
+        return new MvccEntityImpl( entityId, version, column.getValue( SER ) );
+    }
+
+
+    @Override
+    public List<MvccEntity> load( final CollectionContext context, final UUID entityId, final UUID version,
+                                  final int maxSize ) {
+
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+        Preconditions.checkArgument( maxSize > 0, "max Size must be greater than 0" );
+
+
+        ColumnList<UUID> columns = null;
+        try {
+            columns = keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( entityId )
+                                               .withColumnRange( version, null, false, maxSize ).execute().getResult();
+        }
+        catch ( ConnectionException e ) {
+            throw new CollectionRuntimeException( "An error occurred connecting to cassandra", e );
+        }
+
+
+        List<MvccEntity> results = new ArrayList<MvccEntity>( columns.size() );
+
+        for ( Column<UUID> col : columns ) {
+            results.add( new MvccEntityImpl( entityId, col.getName(), col.getValue( SER ) ) );
+        }
+
+        return results;
+    }
+
+
+    @Override
+    public MutationBatch clear( final CollectionContext context, final UUID entityId, final UUID version ) {
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+
+        final Optional<Entity> value = Optional.absent();
+
+        return doWrite( entityId, new RowOp() {
+            @Override
+            public void doOp( final ColumnListMutation<UUID> colMutation ) {
+                colMutation.putColumn( version, SER.toByteBuffer( value ) );
+            }
+        } );
+    }
+
+
+    @Override
+    public MutationBatch delete( final CollectionContext context, final UUID entityId, final UUID version ) {
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+
+
+        return doWrite( entityId, new RowOp() {
+            @Override
+            public void doOp( final ColumnListMutation<UUID> colMutation ) {
+                colMutation.deleteColumn( version );
+            }
+        } );
+    }
+
+
+    @Override
+    public Collection<CollectionColumnFamily> getColumnFamilies() {
+
+        //create the CF entity data.  We want it reversed b/c we want the most recent version at the top of the
+        //row for fast seeks
+        CollectionColumnFamily cf = new CollectionColumnFamily( CF_ENTITY_DATA,
+                ReversedType.class.getName() + "(" + UUIDType.class.getName() + ")", true );
+
+
+        return Collections.singleton( cf );
+    }
+
+
+    /** Do the write on the correct row for the entity id with the operation */
+    private MutationBatch doWrite( UUID entityId, RowOp op ) {
+        final MutationBatch batch = keyspace.prepareMutationBatch();
+
+            op.doOp( batch.withRow( CF_ENTITY_DATA, entityId ) );
+
+        return batch;
+    }
+
+
+    /** Simple callback to perform puts and deletes with a common row setup code */
+    private static interface RowOp {
+
+        /** The operation to perform on the row */
+        void doOp( ColumnListMutation<UUID> colMutation );
+    }
+
+
+    /**
+     * 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 final ObjectSerializer SER = ObjectSerializer.get();
+
+        //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 ) {
+
+            //mark this version as empty
+            if ( !obj.isPresent() ) {
+                return ByteBuffer.wrap( EMPTY );
+            }
+
+            return SER.toByteBuffer( obj.get() );
+        }
+
+
+        @Override
+        public Optional<Entity> fromByteBuffer( final ByteBuffer byteBuffer ) {
+
+            final ByteBuffer check = byteBuffer.duplicate();
+
+            if ( check.remaining() == 1 && check.get() == EMPTY[0] ) {
+                return Optional.absent();
+            }
+
+            return Optional.of( ( Entity ) SER.fromByteBuffer( byteBuffer ) );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccLogEntrySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccLogEntrySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccLogEntrySerializationStrategyImpl.java
new file mode 100644
index 0000000..1ce64aa
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccLogEntrySerializationStrategyImpl.java
@@ -0,0 +1,239 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.cassandra.db.marshal.ReversedType;
+import org.apache.cassandra.db.marshal.UUIDType;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.migration.CollectionColumnFamily;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+
+import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+import com.netflix.astyanax.ColumnListMutation;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+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.ColumnFamily;
+import com.netflix.astyanax.model.ColumnList;
+import com.netflix.astyanax.serializers.AbstractSerializer;
+import com.netflix.astyanax.serializers.UUIDSerializer;
+
+
+/**
+ * Simple implementation for reading and writing log entries
+ *
+ * @author tnine
+ */
+@Singleton
+public class MvccLogEntrySerializationStrategyImpl implements MvccLogEntrySerializationStrategy, Migration {
+
+    public static final String TIMEOUT_PROP = "collection.stage.transient.timeout";
+
+    private static final StageSerializer SER = new StageSerializer();
+
+    private static final ColumnFamily<UUID, UUID> CF_ENTITY_LOG =
+            new ColumnFamily<UUID, UUID>( "Entity_Log", UUIDSerializer.get(), UUIDSerializer.get() );
+
+
+    protected final Keyspace keyspace;
+    protected final int timeout;
+
+
+    @Inject
+    public MvccLogEntrySerializationStrategyImpl( final Keyspace keyspace, @Named( TIMEOUT_PROP ) final int timeout ) {
+        this.keyspace = keyspace;
+        this.timeout = timeout;
+    }
+
+
+    @Override
+    public MutationBatch write( final CollectionContext context, final MvccLogEntry entry ) {
+
+        Preconditions.checkNotNull( entry, "entry is required" );
+
+
+        final Stage stage = entry.getStage();
+        final UUID colName = entry.getVersion();
+
+        return doWrite( context, entry.getEntityId(), new RowOp() {
+            @Override
+            public void doOp( final ColumnListMutation<UUID> colMutation ) {
+
+                //Write the stage with a timeout, it's set as transient
+                if ( stage.isTransient() ) {
+                    colMutation.putColumn( colName, stage, SER, timeout );
+                    return;
+                }
+
+                //otherwise it's persistent, write it with no expiration
+                colMutation.putColumn( colName, stage, SER, null );
+            }
+        } );
+    }
+
+
+    @Override
+    public MvccLogEntry load( final CollectionContext context, final UUID entityId, final UUID version )
+            throws ConnectionException {
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+
+
+        Column<UUID> result;
+
+        try {
+            result = keyspace.prepareQuery( CF_ENTITY_LOG ).getKey( entityId ).getColumn( version ).execute()
+                             .getResult();
+        }
+        catch ( NotFoundException nfe ) {
+            return null;
+        }
+
+
+        final Stage stage = result.getValue( SER );
+
+        return new MvccLogEntryImpl( entityId, version, stage );
+    }
+
+
+    @Override
+    public List<MvccLogEntry> load( final CollectionContext context, final UUID entityId, final UUID version,
+                                    final int maxSize ) throws ConnectionException {
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entity id is required" );
+        Preconditions.checkNotNull( version, "version is required" );
+        Preconditions.checkArgument( maxSize > 0, "max Size must be greater than 0" );
+
+
+        ColumnList<UUID> columns = keyspace.prepareQuery( CF_ENTITY_LOG ).getKey( entityId )
+                                           .withColumnRange( version, null, false, maxSize ).execute().getResult();
+
+
+        List<MvccLogEntry> results = new ArrayList<MvccLogEntry>( columns.size() );
+
+        for ( Column<UUID> col : columns ) {
+            final UUID storedVersion = col.getName();
+            final Stage stage = col.getValue( SER );
+
+            results.add( new MvccLogEntryImpl( entityId, storedVersion, stage ) );
+        }
+
+        return results;
+    }
+
+
+    @Override
+    public MutationBatch delete( final CollectionContext context, final UUID entityId, final UUID version ) {
+
+        Preconditions.checkNotNull( context, "context is required" );
+        Preconditions.checkNotNull( entityId, "entityId is required" );
+        Preconditions.checkNotNull( version, "version context is required" );
+
+        return doWrite( context, entityId, new RowOp() {
+            @Override
+            public void doOp( final ColumnListMutation<UUID> colMutation ) {
+                colMutation.deleteColumn( version );
+            }
+        } );
+    }
+
+
+    @Override
+    public Collection<CollectionColumnFamily> getColumnFamilies() {
+        //create the CF entity data.  We want it reversed b/c we want the most recent version at the top of the
+        //row for fast seeks
+        CollectionColumnFamily cf = new CollectionColumnFamily( CF_ENTITY_LOG,
+                ReversedType.class.getName() + "(" + UUIDType.class.getName() + ")", true );
+
+
+        return Collections.singleton( cf );
+    }
+
+
+    /** Simple callback to perform puts and deletes with a common row setup code */
+    private static interface RowOp {
+
+        /** The operation to perform on the row */
+        void doOp( ColumnListMutation<UUID> colMutation );
+    }
+
+
+    /**
+     * Do the column update or delete for the given column and row key
+     *
+     * @param context We need to use this when getting the keyspace
+     */
+    private MutationBatch doWrite( CollectionContext context, UUID entityId, RowOp op ) {
+
+        final MutationBatch batch = keyspace.prepareMutationBatch();
+
+        op.doOp( batch.withRow( CF_ENTITY_LOG, entityId ) );
+
+        return batch;
+    }
+
+
+    /** Internal stage cache */
+    private static class StageCache {
+        private Map<Byte, Stage> values = new HashMap<Byte, Stage>( Stage.values().length );
+
+
+        private StageCache() {
+            for ( Stage stage : Stage.values() ) {
+
+                final byte stageValue = stage.getId();
+
+                values.put( stageValue, stage );
+            }
+        }
+
+
+        /** Get the stage with the byte value */
+        private Stage getStage( final byte value ) {
+            return values.get( value );
+        }
+    }
+
+
+    public static class StageSerializer extends AbstractSerializer<Stage> {
+
+        /** Used for caching the byte => stage mapping */
+        private static final StageCache CACHE = new StageCache();
+
+
+        @Override
+        public ByteBuffer toByteBuffer( final Stage obj ) {
+            ByteBuffer buff = ByteBuffer.allocate( 1 );
+            buff.put( obj.getId() );
+            buff.rewind();
+            return buff;
+        }
+
+
+        @Override
+        public Stage fromByteBuffer( final ByteBuffer byteBuffer ) {
+            final byte value  = byteBuffer.get();
+
+            return CACHE.getStage(value);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
new file mode 100644
index 0000000..f27b6ad
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
@@ -0,0 +1,45 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import org.apache.usergrid.persistence.collection.astynax.AstynaxKeyspaceProvider;
+import org.apache.usergrid.persistence.collection.guice.PropertyUtils;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.migration.MigrationManager;
+import org.apache.usergrid.persistence.collection.migration.MigrationManagerImpl;
+import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
+import com.netflix.astyanax.Keyspace;
+
+
+/** @author tnine */
+public class SerializationModule extends AbstractModule{
+
+    @Override
+    protected void configure() {
+
+        //bind our keyspace to the AstynaxKeyspaceProvider
+        bind( Keyspace.class ).toProvider( AstynaxKeyspaceProvider.class );
+
+        //bind our migration manager
+        bind( MigrationManager.class ).to( MigrationManagerImpl.class );
+
+
+        //bind the serialization strategies
+
+        bind( MvccEntitySerializationStrategy.class ).to( MvccEntitySerializationStrategyImpl.class );
+
+
+        bind( MvccLogEntrySerializationStrategy.class ).to( MvccLogEntrySerializationStrategyImpl.class );
+
+
+        //do multibindings for migrations
+        Multibinder<Migration> uriBinder = Multibinder.newSetBinder( binder(), Migration.class );
+
+        uriBinder.addBinding().to( MvccEntitySerializationStrategyImpl.class );
+        uriBinder.addBinding().to( MvccLogEntrySerializationStrategyImpl.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/TimeService.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/TimeService.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/TimeService.java
new file mode 100644
index 0000000..410d2f5
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/TimeService.java
@@ -0,0 +1,12 @@
+package org.apache.usergrid.persistence.collection.service;
+
+
+/** @author tnine */
+public interface TimeService {
+
+    /**
+     * Get the current time in milliseconds since epoch
+     * @return
+     */
+    long getTime();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/UUIDService.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/UUIDService.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/UUIDService.java
new file mode 100644
index 0000000..31a3072
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/UUIDService.java
@@ -0,0 +1,15 @@
+package org.apache.usergrid.persistence.collection.service;
+
+
+import java.util.UUID;
+
+
+/** @author tnine */
+public interface UUIDService {
+
+    /**
+     * Generate a new time uuid
+     * @return
+     */
+    UUID newTimeUUID();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/ServiceModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/ServiceModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/ServiceModule.java
new file mode 100644
index 0000000..858aed7
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/ServiceModule.java
@@ -0,0 +1,34 @@
+package org.apache.usergrid.persistence.collection.service.impl;
+
+
+import org.apache.usergrid.persistence.collection.astynax.AstynaxKeyspaceProvider;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.migration.MigrationManager;
+import org.apache.usergrid.persistence.collection.migration.MigrationManagerImpl;
+import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.impl.MvccEntitySerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.serialization.impl.MvccLogEntrySerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.service.TimeService;
+import org.apache.usergrid.persistence.collection.service.UUIDService;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import com.netflix.astyanax.Keyspace;
+
+
+/** @author tnine */
+public class ServiceModule extends AbstractModule{
+
+    @Override
+    protected void configure() {
+
+        //bind our keyspace to the AstynaxKeyspaceProvider
+        bind( TimeService.class ).to( TimeServiceImpl.class );
+
+        //bind our migration manager
+        bind( UUIDService.class ).to( UUIDServiceImpl.class );
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/TimeServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/TimeServiceImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/TimeServiceImpl.java
new file mode 100644
index 0000000..ba49edd
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/TimeServiceImpl.java
@@ -0,0 +1,14 @@
+package org.apache.usergrid.persistence.collection.service.impl;
+
+
+import org.apache.usergrid.persistence.collection.service.TimeService;
+
+
+/** @author tnine */
+public class TimeServiceImpl implements TimeService {
+
+    @Override
+    public long getTime() {
+        return System.currentTimeMillis();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/UUIDServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/UUIDServiceImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/UUIDServiceImpl.java
new file mode 100644
index 0000000..223d13c
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/service/impl/UUIDServiceImpl.java
@@ -0,0 +1,17 @@
+package org.apache.usergrid.persistence.collection.service.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.service.UUIDService;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+
+/** @author tnine */
+public class UUIDServiceImpl implements UUIDService {
+
+    @Override
+    public UUID newTimeUUID() {
+        return UUIDGenerator.newTimeUUID();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/CollectionContextImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/CollectionContextImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/CollectionContextImplTest.java
index ed0a17b..dd7770a 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/CollectionContextImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/CollectionContextImplTest.java
@@ -5,6 +5,7 @@ import java.util.UUID;
 
 import org.junit.Test;
 
+import org.apache.usergrid.persistence.collection.impl.CollectionContextImpl;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
 import static junit.framework.TestCase.assertEquals;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
index 1d56a5d..e8a16bd 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/guice/TestCollectionModule.java
@@ -3,7 +3,6 @@ package org.apache.usergrid.persistence.collection.guice;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.cassandra.locator.SimpleStrategy;
 
@@ -11,7 +10,7 @@ import org.apache.usergrid.persistence.collection.astynax.AstynaxKeyspaceProvide
 import org.apache.usergrid.persistence.collection.migration.MigrationException;
 import org.apache.usergrid.persistence.collection.migration.MigrationManager;
 import org.apache.usergrid.persistence.collection.migration.MigrationManagerImpl;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.serialization.impl.MvccLogEntrySerializationStrategyImpl;
 import org.apache.usergrid.persistence.test.CassandraRule;
 
 import com.google.guiceberry.GuiceBerryEnvMain;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImplTest.java
deleted file mode 100644
index 324c931..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImplTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.entity;
-
-
-import java.util.UUID;
-
-import org.junit.Test;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.collection.CollectionContextImpl;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.google.common.base.Optional;
-
-import static org.junit.Assert.assertEquals;
-
-
-/** @author tnine */
-public class MvccEntityImplTest {
-
-    @Test( expected = NullPointerException.class )
-    public void contextRequired() {
-        new MvccEntityImpl( null, UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(),
-                Optional.of( new Entity() ) );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void entityIdRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccEntityImpl( context, null, UUIDGenerator.newTimeUUID(), Optional.of( new Entity() ) );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void versionRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccEntityImpl( context, UUIDGenerator.newTimeUUID(), null, Optional.of( new Entity() ) );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void entityRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccEntityImpl( context, UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), ( Entity ) null );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void optionalRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccEntityImpl( context, UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), ( Optional ) null );
-    }
-
-
-    @Test
-    public void correctValueEntity() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Entity entity = new Entity( entityId, "test" );
-
-        MvccEntityImpl logEntry = new MvccEntityImpl( context, entityId, version, entity );
-
-        assertEquals( context, logEntry.getContext() );
-        assertEquals( entityId, logEntry.getUuid() );
-        assertEquals( version, logEntry.getVersion() );
-        assertEquals( entity, logEntry.getEntity().get() );
-    }
-
-
-    @Test
-    public void correctValueOptional() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Entity entity = new Entity( entityId, "test" );
-
-        MvccEntityImpl logEntry = new MvccEntityImpl( context, entityId, version, Optional.of( entity ) );
-
-        assertEquals( context, logEntry.getContext() );
-        assertEquals( entityId, logEntry.getUuid() );
-        assertEquals( version, logEntry.getVersion() );
-        assertEquals( entity, logEntry.getEntity().get() );
-    }
-
-
-    @Test
-    public void equals() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Entity entity = new Entity( entityId, "test" );
-
-        MvccEntityImpl first = new MvccEntityImpl( context, entityId, version, Optional.of( entity ) );
-
-        MvccEntityImpl second = new MvccEntityImpl( context, entityId, version, Optional.of( entity ) );
-
-        assertEquals( first, second );
-    }
-
-
-    @Test
-    public void testHashCode() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Entity entity = new Entity( entityId, "test" );
-
-        MvccEntityImpl first = new MvccEntityImpl( context, entityId, version, Optional.of( entity ) );
-
-        MvccEntityImpl second = new MvccEntityImpl( context, entityId, version, Optional.of( entity ) );
-
-        assertEquals( first.hashCode(), second.hashCode() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImplTest.java
deleted file mode 100644
index 918498f..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImplTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.entity;
-
-
-import java.util.UUID;
-
-import org.junit.Test;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.collection.CollectionContextImpl;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import static org.junit.Assert.assertEquals;
-
-
-/** @author tnine */
-public class MvccLogEntryImplTest {
-
-    @Test( expected = NullPointerException.class )
-    public void contextRequired() {
-        new MvccLogEntryImpl( null, UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), Stage.ACTIVE );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void entityIdRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccLogEntryImpl( context, null, UUIDGenerator.newTimeUUID(), Stage.ACTIVE );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void versionRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccLogEntryImpl( context, UUIDGenerator.newTimeUUID(), null, Stage.ACTIVE );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void stageRequired() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        new MvccLogEntryImpl( context, UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), null );
-    }
-
-
-    @Test
-    public void correctValue() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Stage stage = Stage.COMPLETE;
-
-
-        MvccLogEntry logEntry = new MvccLogEntryImpl( context, entityId, version, stage );
-
-        assertEquals( context, logEntry.getContext() );
-        assertEquals( entityId, logEntry.getEntityId() );
-        assertEquals( version, logEntry.getVersion() );
-        assertEquals( stage, logEntry.getStage() );
-    }
-
-
-    @Test
-    public void equals() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Stage stage = Stage.COMPLETE;
-
-
-        MvccLogEntry first = new MvccLogEntryImpl( context, entityId, version, stage );
-
-        MvccLogEntry second = new MvccLogEntryImpl( context, entityId, version, stage );
-
-        assertEquals( first, second );
-    }
-
-
-    @Test
-    public void testHashCode() {
-        final CollectionContext context =
-                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-        final UUID version = UUIDGenerator.newTimeUUID();
-        final Stage stage = Stage.COMPLETE;
-
-
-        MvccLogEntry first = new MvccLogEntryImpl( context, entityId, version, stage );
-
-        MvccLogEntry second = new MvccLogEntryImpl( context, entityId, version, stage );
-
-        assertEquals( first.hashCode(), second.hashCode() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/StageTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/StageTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/StageTest.java
deleted file mode 100644
index 0090e64..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/StageTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.entity;
-
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * @author tnine
- */
-public class StageTest {
-
-    @Test
-    public void active() {
-
-        assertTrue( Stage.ACTIVE.isTransient() );
-
-        assertEquals( ( byte ) 0, Stage.ACTIVE.getId() );
-
-        testUnique( Stage.ACTIVE );
-    }
-
-
-    @Test
-    public void rollback() {
-
-        assertTrue( Stage.ROLLBACK.isTransient() );
-
-        assertEquals( ( byte ) 1, Stage.ROLLBACK.getId() );
-
-        testUnique( Stage.ROLLBACK );
-    }
-
-
-    @Test
-    public void comitted() {
-
-        assertFalse( Stage.COMMITTED.isTransient() );
-
-        assertEquals( ( byte ) 2, Stage.COMMITTED.getId() );
-
-        testUnique( Stage.COMMITTED );
-    }
-
-
-
-
-    @Test
-    public void postProcess() {
-
-        assertFalse( Stage.POSTPROCESS.isTransient() );
-
-        assertEquals( ( byte ) 6, Stage.POSTPROCESS.getId() );
-
-        testUnique( Stage.POSTPROCESS );
-    }
-
-
-    @Test
-    public void complete() {
-
-        assertFalse( Stage.COMPLETE.isTransient() );
-
-        assertEquals( ( byte ) 14, Stage.COMPLETE.getId() );
-
-        testUnique( Stage.COMPLETE );
-    }
-
-
-    /**
-     * Test we don't have dups in the byte value
-     * @param test
-     */
-    private void testUnique( Stage test ) {
-
-        for ( Stage stage : Stage.values() ) {
-
-            //skip self
-            if ( stage == test ) {
-                continue;
-            }
-
-            assertFalse( stage.getId() == test.getId() );
-        }
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/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
new file mode 100644
index 0000000..1b80318
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImplTest.java
@@ -0,0 +1,107 @@
+package org.apache.usergrid.persistence.collection.mvcc.entity.impl;
+
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.base.Optional;
+
+import static org.junit.Assert.assertEquals;
+
+
+/** @author tnine */
+public class MvccEntityImplTest {
+
+
+    @Test( expected = NullPointerException.class )
+    public void entityIdRequired() {
+
+        new MvccEntityImpl( null, UUIDGenerator.newTimeUUID(), Optional.of( new Entity() ) );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void versionRequired() {
+
+        new MvccEntityImpl( UUIDGenerator.newTimeUUID(), null, Optional.of( new Entity() ) );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void entityRequired() {
+
+        new MvccEntityImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), ( Entity ) null );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void optionalRequired() {
+
+        new MvccEntityImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), ( Optional ) null );
+    }
+
+
+    @Test
+    public void correctValueEntity() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Entity entity = new Entity( entityId, "test" );
+
+        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, entity );
+
+        assertEquals( entityId, logEntry.getUuid() );
+        assertEquals( version, logEntry.getVersion() );
+        assertEquals( entity, logEntry.getEntity().get() );
+    }
+
+
+    @Test
+    public void correctValueOptional() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Entity entity = new Entity( entityId, "test" );
+
+        MvccEntityImpl logEntry = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+
+        assertEquals( entityId, logEntry.getUuid() );
+        assertEquals( version, logEntry.getVersion() );
+        assertEquals( entity, logEntry.getEntity().get() );
+    }
+
+
+    @Test
+    public void equals() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Entity entity = new Entity( entityId, "test" );
+
+        MvccEntityImpl first = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+
+        MvccEntityImpl second = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+
+        assertEquals( first, second );
+    }
+
+
+    @Test
+    public void testHashCode() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Entity entity = new Entity( entityId, "test" );
+
+        MvccEntityImpl first = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+
+        MvccEntityImpl second = new MvccEntityImpl( entityId, version, Optional.of( entity ) );
+
+        assertEquals( first.hashCode(), second.hashCode() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImplTest.java
new file mode 100644
index 0000000..947541f
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImplTest.java
@@ -0,0 +1,95 @@
+package org.apache.usergrid.persistence.collection.mvcc.entity.impl;
+
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.impl.CollectionContextImpl;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import static org.junit.Assert.assertEquals;
+
+
+/** @author tnine */
+public class MvccLogEntryImplTest {
+
+
+    @Test( expected = NullPointerException.class )
+    public void entityIdRequired() {
+        final CollectionContext context =
+                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
+
+        new MvccLogEntryImpl( null, UUIDGenerator.newTimeUUID(), Stage.ACTIVE );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void versionRequired() {
+        final CollectionContext context =
+                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
+
+        new MvccLogEntryImpl( UUIDGenerator.newTimeUUID(), null, Stage.ACTIVE );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void stageRequired() {
+        final CollectionContext context =
+                new CollectionContextImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), "test" );
+
+        new MvccLogEntryImpl( UUIDGenerator.newTimeUUID(), UUIDGenerator.newTimeUUID(), null );
+    }
+
+
+    @Test
+    public void correctValue() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Stage stage = Stage.COMPLETE;
+
+
+        MvccLogEntry logEntry = new MvccLogEntryImpl( entityId, version, stage );
+
+        assertEquals( entityId, logEntry.getEntityId() );
+        assertEquals( version, logEntry.getVersion() );
+        assertEquals( stage, logEntry.getStage() );
+    }
+
+
+    @Test
+    public void equals() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Stage stage = Stage.COMPLETE;
+
+
+        MvccLogEntry first = new MvccLogEntryImpl( entityId, version, stage );
+
+        MvccLogEntry second = new MvccLogEntryImpl( entityId, version, stage );
+
+        assertEquals( first, second );
+    }
+
+
+    @Test
+    public void testHashCode() {
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final Stage stage = Stage.COMPLETE;
+
+
+        MvccLogEntry first = new MvccLogEntryImpl( entityId, version, stage );
+
+        MvccLogEntry second = new MvccLogEntryImpl( entityId, version, stage );
+
+        assertEquals( first.hashCode(), second.hashCode() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/StageTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/StageTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/StageTest.java
new file mode 100644
index 0000000..51fe34b
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/StageTest.java
@@ -0,0 +1,93 @@
+package org.apache.usergrid.persistence.collection.mvcc.entity.impl;
+
+
+import org.junit.Test;
+
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * @author tnine
+ */
+public class StageTest {
+
+    @Test
+    public void active() {
+
+        assertTrue( Stage.ACTIVE.isTransient() );
+
+        assertEquals( ( byte ) 0, Stage.ACTIVE.getId() );
+
+        testUnique( Stage.ACTIVE );
+    }
+
+
+    @Test
+    public void rollback() {
+
+        assertTrue( Stage.ROLLBACK.isTransient() );
+
+        assertEquals( ( byte ) 1, Stage.ROLLBACK.getId() );
+
+        testUnique( Stage.ROLLBACK );
+    }
+
+
+    @Test
+    public void comitted() {
+
+        assertFalse( Stage.COMMITTED.isTransient() );
+
+        assertEquals( ( byte ) 2, Stage.COMMITTED.getId() );
+
+        testUnique( Stage.COMMITTED );
+    }
+
+
+
+
+    @Test
+    public void postProcess() {
+
+        assertFalse( Stage.POSTPROCESS.isTransient() );
+
+        assertEquals( ( byte ) 6, Stage.POSTPROCESS.getId() );
+
+        testUnique( Stage.POSTPROCESS );
+    }
+
+
+    @Test
+    public void complete() {
+
+        assertFalse( Stage.COMPLETE.isTransient() );
+
+        assertEquals( ( byte ) 14, Stage.COMPLETE.getId() );
+
+        testUnique( Stage.COMPLETE );
+    }
+
+
+    /**
+     * Test we don't have dups in the byte value
+     * @param test
+     */
+    private void testUnique( Stage test ) {
+
+        for ( Stage stage : Stage.values() ) {
+
+            //skip self
+            if ( stage == test ) {
+                continue;
+            }
+
+            assertFalse( stage.getId() == test.getId() );
+        }
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/StartTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/StartTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/StartTest.java
deleted file mode 100644
index aa79a70..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/StartTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage;
-
-
-import java.util.UUID;
-
-import org.junit.Test;
-
-import org.apache.usergrid.persistence.collection.CollectionContextImpl;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntityImpl;
-import org.apache.usergrid.persistence.collection.mvcc.stage.impl.Start;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import static org.mockito.Mockito.mock;
-
-
-/** @author tnine */
-public class StartTest {
-
-    @Test
-    public void testStartStage(){
-
-        final MvccLogEntrySerializationStrategy logStrategy = mock(MvccLogEntrySerializationStrategy.class);
-
-        Start start = new Start( logStrategy );
-
-        //set up the data
-
-        final UUID applicationId = UUIDGenerator.newTimeUUID();
-
-        final UUID ownerId = UUIDGenerator.newTimeUUID();
-
-        final UUID entityId = UUIDGenerator.newTimeUUID();
-
-        final UUID version = UUIDGenerator.newTimeUUID();
-
-        final String name = "tests";
-
-
-        CollectionContextImpl collection = new CollectionContextImpl( applicationId, ownerId, name );
-
-
-        Entity entity = new Entity();
-
-        MvccEntityImpl mvccEntity = new MvccEntityImpl(collection, entityId, version, entity  );
-
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNewTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNewTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNewTest.java
new file mode 100644
index 0000000..05e9460
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNewTest.java
@@ -0,0 +1,136 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.impl.MvccEntityNew;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.service.TimeService;
+import org.apache.usergrid.persistence.collection.service.UUIDService;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.OperationResult;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.same;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+/** @author tnine */
+public class MvccEntityNewTest {
+
+    /**
+     * Test the start stage for happy path
+     * TODO throw junk at it
+     * TODO refactor a lot of this mock setup.  It's common across a lot of tests
+     */
+    @Test
+    public void testStartStage() throws ConnectionException, ExecutionException, InterruptedException {
+
+        final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
+
+        final ArgumentCaptor<MvccLogEntry> logEntry = ArgumentCaptor.forClass( MvccLogEntry.class );
+
+
+        final WriteContext writeContext = mock( WriteContext.class );
+        final CollectionContext context = mock( CollectionContext.class );
+
+
+        //mock returning the context
+        when( writeContext.getCollectionContext() ).thenReturn( context );
+
+
+        final MutationBatch mutation = mock( MutationBatch.class );
+
+
+        //mock returning a mock mutation when we do a log entry write
+        when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( mutation );
+
+
+        //mock the listenable future
+        final ListenableFuture<OperationResult<Void>> future = mock( ListenableFuture.class);
+        final OperationResult<Void> result = mock(OperationResult.class);
+
+        when(mutation.executeAsync()).thenReturn( future );
+
+        //mock the "get" on the future
+        when(future.get()).thenReturn( result  );
+
+
+        //set up the mock to return the entity from the start phase
+        final Entity entity = new Entity();
+
+        when( writeContext.getMessage( Entity.class ) ).thenReturn( entity );
+
+
+        //mock returning the time
+        final TimeService timeService = mock( TimeService.class );
+
+        final long time = System.currentTimeMillis();
+
+        when( timeService.getTime() ).thenReturn( time );
+
+
+        //mock the uuid service
+        final UUIDService uuidService = mock( UUIDService.class );
+
+        final UUID newEntityId = UUIDGenerator.newTimeUUID();
+        final UUID newVersion = newEntityId;
+
+
+        //mock the uuid service
+        when( uuidService.newTimeUUID() ).thenReturn( newEntityId );
+
+
+        //run the stage
+        MvccEntityNew newStage = new MvccEntityNew( logStrategy, timeService, uuidService );
+
+        newStage.performStage( writeContext );
+
+
+        //now verify our output was correct
+        ArgumentCaptor<MvccEntity> mvccEntity = ArgumentCaptor.forClass( MvccEntity.class );
+
+
+        verify( writeContext).setMessage( mvccEntity.capture() );
+
+        MvccEntity created = mvccEntity.getValue();
+
+        //verify uuid and version in both the MvccEntity and the entity itself
+        assertEquals( "entity id did not match generator", newEntityId, created.getUuid() );
+        assertEquals( "entity id did not match generator", newEntityId, created.getEntity().get().getUuid() );
+        assertEquals( "version did not not match entityId", newVersion, created.getVersion() );
+        assertEquals( "version did not not match entityId", newVersion, created.getEntity().get().getVersion() );
+
+        //check the time
+        assertEquals( "created time matches generator", time, created.getEntity().get().getCreated() );
+        assertEquals( "updated time matches generator", time, created.getEntity().get().getUpdated() );
+
+        //now  verify we invoked the mvcc log operation correctly
+
+        MvccLogEntry entry = logEntry.getValue();
+
+        assertEquals("Log entry has correct uuid", newEntityId,  entry.getEntityId());
+        assertEquals("Log entry has correct version", newVersion,  entry.getEntityId());
+        assertEquals( "Stage was correct", Stage.ACTIVE, entry.getStage() );
+
+        //now verify the proceed was called
+        verify(writeContext).proceed();
+
+    }
+}


Mime
View raw message