You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/27 18:20:48 UTC

[01/27] git commit: Added hystrix integration. Not working as expected

Repository: incubator-usergrid
Updated Branches:
  refs/heads/entity-manager 8adbe29c9 -> c66283827
  refs/heads/two-dot-o 17c2ac42f -> 9caf38bde


Added hystrix integration.  Not working as expected


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

Branch: refs/heads/entity-manager
Commit: 5cadb9f58b9936580373c1db5fe72ce800a7d017
Parents: 803096e
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Mar 19 14:52:28 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Mar 19 14:52:28 2014 -0700

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml        |    6 +
 .../usergrid/persistence/graph/GraphFig.java    |   42 +-
 .../graph/consistency/TimeoutTask.java          |    2 +-
 .../graph/impl/EdgeDeleteListener.java          |    6 +-
 .../persistence/graph/impl/EdgeManagerImpl.java |   18 +-
 .../graph/impl/EdgeWriteListener.java           |    2 +-
 .../graph/impl/NodeDeleteListener.java          |   22 +-
 .../graph/impl/stage/AbstractEdgeRepair.java    |   10 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |    9 +-
 .../impl/parse/ObservableIterator.java          |   48 +-
 .../persistence/graph/EdgeManagerTimeoutIT.java | 1491 ++++++++++++++++++
 stack/corepersistence/pom.xml                   |    1 +
 12 files changed, 1594 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/collection/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml
index 7b34b0b..808347e 100644
--- a/stack/corepersistence/collection/pom.xml
+++ b/stack/corepersistence/collection/pom.xml
@@ -203,5 +203,11 @@
             <version>${log4j.version}</version>
         </dependency>
 
+      <dependency>
+          <groupId>com.netflix.hystrix</groupId>
+          <artifactId>hystrix-core</artifactId>
+          <version>${hystrix.version}</version>
+      </dependency>
+
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
index 64ca397..de7f72f 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
@@ -17,6 +17,8 @@ public interface GraphFig extends GuicyFig {
 
     public static final String REPAIR_CONCURRENT_SIZE = "usergrid.graph.repair.concurrent.size";
 
+    public static final String REPAIR_TIMEOUT = "usergrid.graph.repair.timeout";
+
 
     public static final String TIMEOUT_SIZE = "usergrid.graph.timeout.page.size";
 
@@ -26,37 +28,47 @@ public interface GraphFig extends GuicyFig {
 
     public static final String WRITE_CL = "usergrid.graph.write.cl";
 
-    public static final String WRITE_TIMEOUT  = "usergrid.graph.write.timeout";
+    public static final String WRITE_TIMEOUT = "usergrid.graph.write.timeout";
+
+    public static final String READ_TIMEOUT = "usergrid.graph.read.timeout";
 
-    @Default( "1000" )
-    @Key( SCAN_PAGE_SIZE )
+    @Default("1000")
+    @Key(SCAN_PAGE_SIZE)
     int getScanPageSize();
 
-    @Default( "CL_ONE" )
-    @Key( READ_CL )
+    @Default("CL_ONE")
+    @Key(READ_CL)
     String getReadCL();
 
-    @Default( "CL_QUORUM" )
-    @Key( WRITE_CL )
+    @Default("CL_QUORUM")
+    @Key(WRITE_CL)
     String getWriteCL();
 
-    @Default("10000")
-    @Key( WRITE_TIMEOUT )
-    long getWriteTimeout();
+//    @Default("10000")
+//    @Key(WRITE_TIMEOUT)
+//    int getWriteTimeout();
+
+    /**
+     * Get the read timeout (in milliseconds) that we should allow when reading from the data source
+     */
+    @Default( "10000" )
+    @Key( READ_TIMEOUT )
+    int getReadTimeout();
 
     @Default( "100" )
     @Key( TIMEOUT_SIZE )
     int getTimeoutReadSize();
 
-    @Default("500")
+    @Default( "500" )
     @Key( TIMEOUT_TASK_TIME )
     long getTaskLoopTime();
 
-    @Default("10")
-    @Key(REPAIR_CONCURRENT_SIZE)
+    @Default( "10" )
+    @Key( REPAIR_CONCURRENT_SIZE )
     int getRepairConcurrentSize();
 
-
-
+    @Default("10000")
+      @Key(WRITE_TIMEOUT)
+      int getRepairTimeout();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/TimeoutTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/TimeoutTask.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/TimeoutTask.java
index fbfad3e..7555ce2 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/TimeoutTask.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/TimeoutTask.java
@@ -56,6 +56,6 @@ public class TimeoutTask<T> implements Action1<Scheduler.Inner> {
      * @return
      */
     private Iterator<AsynchronousMessage<T>> getTimeouts() {
-        return processor.getTimeouts( graphFig.getTimeoutReadSize(), graphFig.getWriteTimeout() * 2 ).iterator();
+        return processor.getTimeouts( graphFig.getTimeoutReadSize(), graphFig.getRepairTimeout() * 2 ).iterator();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
index e0ceafc..d377882 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
@@ -8,6 +8,7 @@ import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.EdgeManager;
 import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
+import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.MessageListener;
@@ -39,17 +40,20 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
     private final EdgeMetadataSerialization edgeMetadataSerialization;
     private final EdgeManagerFactory edgeManagerFactory;
     private final Keyspace keyspace;
+    private final GraphFig graphFig;
 
 
     @Inject
     public EdgeDeleteListener( final EdgeSerialization edgeSerialization,
                                final EdgeMetadataSerialization edgeMetadataSerialization,
                                final EdgeManagerFactory edgeManagerFactory, final Keyspace keyspace,
+                               final GraphFig graphFig,
                                @EdgeDelete final AsyncProcessor edgeDelete ) {
         this.edgeSerialization = edgeSerialization;
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeManagerFactory = edgeManagerFactory;
         this.keyspace = keyspace;
+        this.graphFig = graphFig;
 
         edgeDelete.addListener( this );
     }
@@ -72,7 +76,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
 
 
                 //go through every version of this edge <= the current version and remove it
-                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>() {
+                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
                     @Override
                     protected Iterator<MarkedEdge> getIterator() {
                         return edgeSerialization.getEdgeToTarget( scope,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
index fe23222..9e529c5 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
@@ -201,7 +201,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
@@ -220,7 +220,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
@@ -240,7 +240,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
@@ -258,7 +258,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
@@ -276,7 +276,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -287,7 +287,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
@@ -299,7 +299,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -310,7 +310,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesToTarget( scope, search );
@@ -323,7 +323,7 @@ public class EdgeManagerImpl implements EdgeManager {
      * Get our timeout for write consistency
      */
     private long getTimeout() {
-        return graphFig.getWriteTimeout() * 2;
+        return graphFig.getRepairTimeout() * 2;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
index 271375a..ed8e861 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
@@ -52,7 +52,7 @@ public class EdgeWriteListener implements MessageListener<EdgeEvent<Edge>, EdgeE
         final OrganizationScope scope = write.getOrganizationScope();
         final UUID maxVersion = edge.getVersion();
 
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index 9fcd3a9..631ac50 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.SearchEdgeType;
@@ -31,7 +32,6 @@ import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Action0;
 import rx.functions.Func1;
-import rx.observables.MathObservable;
 
 
 /**
@@ -47,6 +47,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     private final EdgeMetadataSerialization edgeMetadataSerialization;
     private final EdgeDeleteRepair edgeDeleteRepair;
     private final EdgeMetaRepair edgeMetaRepair;
+    private final GraphFig graphFig;
 
     private final Scheduler scheduler;
 
@@ -55,11 +56,11 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      * Wire the serialization dependencies
      */
     @Inject
-    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,final Scheduler scheduler,
-                               @NodeDelete final AsyncProcessor nodeDelete,
-                               final EdgeMetadataSerialization edgeMetadataSerialization, final EdgeDeleteRepair
-            edgeDeleteRepair,
-                               final EdgeMetaRepair edgeMetaRepair ) {
+    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,
+                               final Scheduler scheduler, @NodeDelete final AsyncProcessor nodeDelete,
+                               final EdgeMetadataSerialization edgeMetadataSerialization,
+                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair,
+                               final GraphFig graphFig ) {
 
 
         this.nodeSerialization = nodeSerialization;
@@ -68,6 +69,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeDeleteRepair = edgeDeleteRepair;
         this.edgeMetaRepair = edgeMetaRepair;
+        this.graphFig = graphFig;
 
         nodeDelete.addListener( this );
     }
@@ -208,7 +210,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesToTarget( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -222,7 +224,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesFromSource( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -236,7 +238,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesToTarget( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
@@ -250,7 +252,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesFromSource( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index 28d0622..e09d884 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -20,10 +20,8 @@
 package org.apache.usergrid.persistence.graph.impl.stage;
 
 
-import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
-import java.util.PriorityQueue;
 import java.util.UUID;
 
 import org.slf4j.Logger;
@@ -36,10 +34,7 @@ import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
 import org.apache.usergrid.persistence.graph.serialization.impl.parse.ObservableIterator;
-import org.apache.usergrid.persistence.model.entity.Id;
 
-import com.fasterxml.uuid.UUIDComparator;
-import com.fasterxml.uuid.impl.UUIDUtil;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.netflix.astyanax.Keyspace;
@@ -49,7 +44,6 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Func1;
-import rx.functions.Func2;
 
 
 /**
@@ -131,7 +125,7 @@ public abstract class AbstractEdgeRepair  {
      */
     private Observable<MarkedEdge> getEdgeVersionsFromSource( final OrganizationScope scope, final Edge edge ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 
@@ -148,7 +142,7 @@ public abstract class AbstractEdgeRepair  {
      */
     private Observable<MarkedEdge> getEdgeVersionsToTarget( final OrganizationScope scope, final Edge edge ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
index 5c497a5..c54f485 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
@@ -48,7 +48,6 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
 import rx.Scheduler;
-import rx.functions.Action0;
 import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.observables.MathObservable;
@@ -252,7 +251,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>() {
+            return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
@@ -265,7 +264,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>() {
+            return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesToTargetBySourceType( scope,
@@ -297,7 +296,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>() {
+            return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
@@ -310,7 +309,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>() {
+            return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesFromSourceByTargetType( scope,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
index 2274868..c70dc4c 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
@@ -3,43 +3,65 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 
 import java.util.Iterator;
 
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommandProperties;
+
 import rx.Observable;
-import rx.Observer;
 import rx.Subscriber;
-import rx.Subscription;
-import rx.subscriptions.Subscriptions;
 
 
 /**
  * Converts an iterator to an observable.  Subclasses need to only implement getting the iterator from the data source.
- * This is used in favor of "Observable.just" when the initial fetch of the iterator will require I/O.  This allows
- * us to wrap the iterator in a deferred invocation to avoid the blocking on construction.
+ * This is used in favor of "Observable.just" when the initial fetch of the iterator will require I/O.  This allows us
+ * to wrap the iterator in a deferred invocation to avoid the blocking on construction.
  */
 public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T> {
 
+    private static final HystrixCommandGroupKey GROUP_KEY = HystrixCommandGroupKey.Factory.asKey( "CassRead" );
+
+    private final int executionTimeout;
+
+
+    protected ObservableIterator( final int executionTimeout ) {
+        this.executionTimeout = executionTimeout;
+    }
+
 
     @Override
     public void call( final Subscriber<? super T> subscriber ) {
 
 
         try {
-            //get our iterator and push data to the observer
-            Iterator<T> itr = getIterator();
+            //run producing the values within a hystrix command.  This way we'll time out if the read takes too long
+            new HystrixCommand<Void>( HystrixCommand.Setter.withGroupKey( GROUP_KEY ).andCommandPropertiesDefaults(
+                    HystrixCommandProperties.Setter()
+                                            .withExecutionIsolationThreadTimeoutInMilliseconds( executionTimeout ) ) ) {
 
 
-            //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
-            while ( itr.hasNext() && !subscriber.isUnsubscribed()) {
-                subscriber.onNext( itr.next() );
-            }
+                @Override
+                protected Void run() throws Exception {
+                    //get our iterator and push data to the observer
+                    final Iterator<T> itr = getIterator();
 
-            subscriber.onCompleted();
+
+                    //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
+                    while ( itr.hasNext() && !subscriber.isUnsubscribed() ) {
+                        subscriber.onNext( itr.next() );
+                    }
+
+
+                    subscriber.onCompleted();
+
+                    return null;
+                }
+            }.execute();
         }
 
         //if any error occurs, we need to notify the observer so it can perform it's own error handling
         catch ( Throwable t ) {
             subscriber.onError( t );
         }
-
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
new file mode 100644
index 0000000..e4591cd
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
@@ -0,0 +1,1491 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph;
+
+
+import java.util.Iterator;
+import java.util.UUID;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeoutException;
+
+import org.jukito.All;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.safehaus.guicyfig.GuicyFig;
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Inject;
+
+import rx.Observable;
+import rx.functions.Action1;
+
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
+//@UseModules( { TestGraphModule.class, EdgeManagerIT.InvalidInput.class } )
+public class EdgeManagerTimeoutIT {
+
+    /**
+     * Test timeout in millis
+     */
+    private static final long TIMEOUT = 30000;
+
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
+
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+
+    @Inject
+    protected EdgeManagerFactory emf;
+
+    @Inject
+    protected GraphFig graphFig;
+
+    protected OrganizationScope scope;
+
+
+    @Before
+    public void setup() {
+        scope = mock( OrganizationScope.class );
+
+        Id orgId = mock( Id.class );
+
+        when( orgId.getType() ).thenReturn( "organization" );
+        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
+
+        when( scope.getOrganization() ).thenReturn( orgId );
+
+        if(graphFig.getReadTimeout() > TIMEOUT){
+            fail("Graph read timeout must be <= " + TIMEOUT + ".  Otherwise tests are invalid");
+        }
+    }
+
+
+    @Test(timeout = TIMEOUT, expected = TimeoutException.class)
+    public void testWriteReadEdgeTypeSource() throws InterruptedException {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //retrieve the edge, ensure that if we block indefinitely, it times out
+
+        final Semaphore blocker = new Semaphore(0);
+
+        edges.subscribe( new Action1<Edge>() {
+            @Override
+            public void call( final Edge edge ) {
+                //block indefinitely, we want to ensure we timeout
+                try {
+                    blocker.acquire();
+                }
+                catch ( InterruptedException e ) {
+                    throw new RuntimeException(e);
+                }
+            }
+        } );
+
+        blocker.acquire();
+
+    }
+
+
+
+    @Test
+    public void testWriteReadEdgeTypeTarget() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionSource() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTarget() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    /**
+     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
+     */
+    @Test
+    public void testWriteReadEdgeTypeVersionSourceDistinct() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTargetDistinct() {
+
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingSource() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+        final Id sourceId = createId( "source" );
+
+
+        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge3, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingTarget() {
+
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        final Id targetId = createId( "target" );
+
+        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge3, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeSource() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeTarget() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteSource() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        em.deleteEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteTarget() {
+
+        EdgeManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        em.deleteEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypes() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        Observable<String> edges =
+                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+
+        //now get types for test2
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypes() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId1 = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get types for test2
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypesPaging() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
+
+        edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get the next page
+
+        edges = em.getIdTypesFromSource(
+                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypesPaging() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
+
+        edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now get the next page
+
+        edges = em.getIdTypesToTarget(
+                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testMarkSourceEdges() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdges() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges =
+                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkSourceEdgesType() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdgesType() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
+                        null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void markSourceNode() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( sourceId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+
+
+    @Test
+    public void markTargetNode() {
+
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( targetId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+
+    @Test(expected = NullPointerException.class)
+    public void invalidEdgeTypesWrite( @All Edge edge ) {
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        em.writeEdge( edge );
+    }
+
+
+    @Test(expected = NullPointerException.class)
+    public void invalidEdgeTypesDelete( @All Edge edge ) {
+        final EdgeManager em = emf.createEdgeManager( scope );
+
+        em.deleteEdge( edge );
+    }
+
+    //
+    //    public static class InvalidInput extends JukitoModule {
+    //
+    //        @Override
+    //        protected void configureTest() {
+    //create all edge types of junk input
+    //
+    //            final UUID version = UUIDGenerator.newTimeUUID();
+    //
+    //            Id nullUuid = mock( Id.class );
+    //            when( nullUuid.getUuid() ).thenReturn( null );
+    //
+    //
+    //            Id nullType = mock( Id.class );
+    //            when( nullType.getType() ).thenReturn( "type" );
+    //
+    //            Edge[] edges = new Edge[] {
+    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( nullType, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullType, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
+    //            };
+    //
+    //
+    //            bindManyInstances( Edge.class, edges );
+    //
+    //        }
+    //
+    //
+    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
+    //            Edge edge = mock( Edge.class );
+    //
+    //            when( edge.getSourceNode() ).thenReturn( sourceId );
+    //            when( edge.getType() ).thenReturn( type );
+    //            when( edge.getTargetNode() ).thenReturn( targetId );
+    //            when( edge.getVersion() ).thenReturn( version );
+    //
+    //            return edge;
+    //        }
+    //    }
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cadb9f5/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index f538d0e..5ffab73 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -39,6 +39,7 @@
         <slf4j.version>1.7.2</slf4j.version>
         <surefire.version>2.16</surefire.version>
         <rx.version>0.17.1</rx.version>
+        <hystrix.version>1.4.0-RC1</hystrix.version>
 
     </properties>
 


[14/27] Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
new file mode 100644
index 0000000..18c50ec
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
@@ -0,0 +1,329 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.io.File;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.index.exceptions.JsonReadException;
+import org.apache.usergrid.persistence.index.exceptions.JsonWriteException;
+//import org.apache.usergrid.persistence.Entity;
+
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.io.JsonStringEncoder;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig.Feature;
+import org.codehaus.jackson.smile.SmileFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.commons.lang.StringUtils.substringAfter;
+
+import static org.apache.usergrid.persistence.index.utils.StringUtils.stringOrSubstringBeforeFirst;
+
+
+public class JsonUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger( JsonUtils.class );
+
+    static ObjectMapper mapper = new ObjectMapper();
+
+    static SmileFactory smile = new SmileFactory();
+
+    static ObjectMapper smileMapper = new ObjectMapper( smile );
+
+    private static ObjectMapper indentObjectMapper = new ObjectMapper();
+
+
+    static {
+        indentObjectMapper.getSerializationConfig().set( Feature.INDENT_OUTPUT, true );
+    }
+
+
+    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
+    public static String mapToJsonString( Object obj ) {
+        try {
+            return mapper.writeValueAsString( obj );
+        }
+        catch ( Throwable t ) {
+            LOG.debug( "Error generating JSON", t );
+            throw new JsonWriteException( "Error generating JSON", t );
+        }
+    }
+
+
+    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
+    public static String mapToFormattedJsonString( Object obj ) {
+        try {
+            return indentObjectMapper.writeValueAsString( obj );
+        }
+        catch ( Throwable t ) {
+            LOG.debug( "Error generating JSON", t );
+            throw new JsonWriteException( "Error generating JSON", t );
+        }
+    }
+
+
+    /** Parses JSON string  and returns object, throws runtime exception JsonReadException on failure. */
+    public static Object parse( String json ) {
+        try {
+            return mapper.readValue( json, Object.class );
+        }
+        catch ( Throwable t ) {
+            LOG.debug( "Error parsing JSON", t );
+            throw new JsonReadException( "Error parsing JSON", t );
+        }
+    }
+
+
+    public static String quoteString( String s ) {
+        JsonStringEncoder encoder = new JsonStringEncoder();
+        return new String( encoder.quoteAsUTF8( s ) );
+    }
+
+
+    public static ByteBuffer toByteBuffer( Object obj ) {
+        if ( obj == null ) {
+            return null;
+        }
+
+        byte[] bytes = null;
+        try {
+            bytes = smileMapper.writeValueAsBytes( obj );
+        }
+        catch ( Exception e ) {
+            LOG.error( "Error getting SMILE bytes", e );
+        }
+        if ( bytes != null ) {
+            return ByteBuffer.wrap( bytes );
+        }
+        return null;
+    }
+
+
+    public static Object fromByteBuffer( ByteBuffer byteBuffer ) {
+        return fromByteBuffer( byteBuffer, Object.class );
+    }
+
+
+    public static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ) {
+        if ( ( byteBuffer == null ) || !byteBuffer.hasRemaining() ) {
+            return null;
+        }
+        if ( clazz == null ) {
+            clazz = Object.class;
+        }
+
+        Object obj = null;
+        try {
+            obj = smileMapper.readValue( byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
+                    byteBuffer.remaining(), clazz );
+        }
+        catch ( Exception e ) {
+            LOG.error( "Error parsing SMILE bytes", e );
+        }
+        return obj;
+    }
+
+
+    public static JsonNode toJsonNode( Object obj ) {
+        if ( obj == null ) {
+            return null;
+        }
+        return mapper.convertValue( obj, JsonNode.class );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static Map<String, Object> toJsonMap( Object obj ) {
+        if ( obj == null ) {
+            return null;
+        }
+
+        return ( Map<String, Object> ) mapper.convertValue( obj, Map.class );
+    }
+
+
+    private static UUID tryConvertToUUID( Object o ) {
+        if ( o instanceof String ) {
+            String s = ( String ) o;
+            if ( s.length() == 36 ) {
+                try {
+                    return UUID.fromString( s );
+                }
+                catch ( IllegalArgumentException e ) {
+                    LOG.warn( "Argument to UUID.fromString({}) was invalid.", s, e );
+                }
+            }
+        }
+        return null;
+    }
+
+
+    public static Object normalizeJsonTree( Object obj ) {
+        if ( obj instanceof Map ) {
+            @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj;
+            Object o;
+            UUID uuid;
+            for ( Object k : m.keySet() ) {
+                if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) {
+                    continue;
+                }
+
+                o = m.get( k );
+                uuid = tryConvertToUUID( o );
+                if ( uuid != null ) {
+                    m.put( k, uuid );
+                }
+                else if ( o instanceof Integer ) {
+                    m.put( k, ( ( Integer ) o ).longValue() );
+                }
+                else if ( o instanceof BigInteger ) {
+                    m.put( k, ( ( BigInteger ) o ).longValue() );
+                }
+            }
+        }
+        else if ( obj instanceof List ) {
+            @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj;
+            Object o;
+            UUID uuid;
+            for ( int i = 0; i < l.size(); i++ ) {
+                o = l.get( i );
+                uuid = tryConvertToUUID( o );
+                if ( uuid != null ) {
+                    l.set( i, uuid );
+                }
+                else if ( ( o instanceof Map ) || ( o instanceof List ) ) {
+                    normalizeJsonTree( o );
+                }
+                else if ( o instanceof Integer ) {
+                    l.set( i, ( ( Integer ) o ).longValue() );
+                }
+                else if ( o instanceof BigInteger ) {
+                    l.set( i, ( ( BigInteger ) o ).longValue() );
+                }
+            }
+        }
+        else if ( obj instanceof String ) {
+            UUID uuid = tryConvertToUUID( obj );
+            if ( uuid != null ) {
+                return uuid;
+            }
+        }
+        else if ( obj instanceof Integer ) {
+            return ( ( Integer ) obj ).longValue();
+        }
+        else if ( obj instanceof BigInteger ) {
+            return ( ( BigInteger ) obj ).longValue();
+        }
+        else if ( obj instanceof JsonNode ) {
+            return mapper.convertValue( obj, Object.class );
+        }
+        return obj;
+    }
+
+
+//    public static Object select( Object obj, String path ) {
+//        return select( obj, path, false );
+//    }
+//
+//
+//    public static Object select( Object obj, String path, boolean buildResultTree ) {
+//
+//        if ( obj == null ) {
+//            return null;
+//        }
+//
+//        if ( org.apache.commons.lang.StringUtils.isBlank( path ) ) {
+//            return obj;
+//        }
+//
+//        String segment = stringOrSubstringBeforeFirst( path, '.' );
+//        String remaining = substringAfter( path, "." );
+//
+//        if ( obj instanceof Map ) {
+//            Map<?, ?> map = ( Map<?, ?> ) obj;
+//            Object child = map.get( segment );
+//            Object result = select( child, remaining, buildResultTree );
+//            if ( result != null ) {
+//                if ( buildResultTree ) {
+//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
+//                    results.put( segment, result );
+//                    return results;
+//                }
+//                else {
+//                    return result;
+//                }
+//            }
+//            return null;
+//        }
+//        if ( obj instanceof List ) {
+//            List<Object> results = new ArrayList<Object>();
+//            List<?> list = ( List<?> ) obj;
+//            for ( Object i : list ) {
+//                Object result = select( i, path, buildResultTree );
+//                if ( result != null ) {
+//                    results.add( result );
+//                }
+//            }
+//            if ( !results.isEmpty() ) {
+//                return results;
+//            }
+//            return null;
+//        }
+//
+//        if ( obj instanceof Entity ) {
+//            Object child = ( ( Entity ) obj ).getProperty( segment );
+//            Object result = select( child, remaining, buildResultTree );
+//            if ( result != null ) {
+//                if ( buildResultTree ) {
+//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
+//                    results.put( segment, result );
+//                    return results;
+//                }
+//                else {
+//                    return result;
+//                }
+//            }
+//            else {
+//                return result;
+//            }
+//        }
+//
+//        return obj;
+//    }
+
+
+    public static Object loadFromFilesystem( String filename ) {
+        Object json = null;
+        try {
+            File file = new File( filename );
+            json = mapper.readValue( file, Object.class );
+        }
+        catch ( Exception e ) {
+            LOG.error( "Error loading JSON", e );
+        }
+        return json;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ListUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ListUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ListUtils.java
new file mode 100644
index 0000000..6c7b480
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ListUtils.java
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.usergrid.persistence.collection.util.EntityUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ListUtils extends org.apache.commons.collections.ListUtils {
+    private static final Logger LOG = LoggerFactory.getLogger( ListUtils.class );
+
+
+    public static <A> A first( List<A> list ) {
+        if ( list == null ) {
+            return null;
+        }
+        if ( list.size() == 0 ) {
+            return null;
+        }
+        return list.get( 0 );
+    }
+
+
+    public static <A> A last( List<A> list ) {
+        if ( list == null ) {
+            return null;
+        }
+        if ( list.size() == 0 ) {
+            return null;
+        }
+        return list.get( list.size() - 1 );
+    }
+
+
+    public static <A> Integer firstInteger( List<A> list ) {
+        A a = first( list );
+        if ( a == null ) {
+            return null;
+        }
+
+        if ( a instanceof Integer ) {
+            return ( Integer ) a;
+        }
+
+        try {
+            return NumberUtils.toInt( ( String ) a );
+        }
+        catch ( Exception e ) {
+            LOG.warn( "Could not convert list item {} to int", a, e );
+        }
+        return null;
+    }
+
+
+    public static <A> Long firstLong( List<A> list ) {
+        A a = first( list );
+        if ( a == null ) {
+            return null;
+        }
+
+        if ( a instanceof Long ) {
+            return ( Long ) a;
+        }
+
+        try {
+            return NumberUtils.toLong( ( String ) a );
+        }
+        catch ( Exception e ) {
+            LOG.warn( "Could not convert list item {} to long", a, e );
+        }
+        return null;
+    }
+
+
+    public static <A> Boolean firstBoolean( List<A> list ) {
+        A a = first( list );
+        if ( a == null ) {
+            return null;
+        }
+
+        if ( a instanceof Boolean ) {
+            return ( Boolean ) a;
+        }
+
+        try {
+            return Boolean.parseBoolean( ( String ) a );
+        }
+        catch ( Exception e ) {
+            LOG.warn( "Could not convert list item {} to boolean", a, e );
+        }
+        return null;
+    }
+
+
+    public static <A> UUID firstUuid( List<A> list ) {
+        A i = first( list );
+        if ( i == null ) {
+            return null;
+        }
+
+        if ( i instanceof UUID ) {
+            return ( UUID ) i;
+        }
+
+        try {
+            return UUIDUtils.tryGetUUID( ( String ) i );
+        }
+        catch ( Exception e ) {
+            LOG.warn( "Could not convert list item {} to UUID", i, e );
+        }
+        return null;
+    }
+
+
+    public static boolean isEmpty( List<?> list ) {
+        return ( list == null ) || ( list.size() == 0 );
+    }
+
+
+    public static <T> List<T> dequeueCopy( List<T> list ) {
+        if ( !isEmpty( list ) ) {
+            list = list.subList( 1, list.size() );
+        }
+        return list;
+    }
+
+
+    public static <T> List<T> initCopy( List<T> list ) {
+        if ( !isEmpty( list ) ) {
+            list = new ArrayList<T>( list );
+        }
+        else {
+            list = new ArrayList<T>();
+        }
+        return list;
+    }
+
+
+    public static <T> T dequeue( List<T> list ) {
+        if ( !isEmpty( list ) ) {
+            return list.remove( 0 );
+        }
+        return null;
+    }
+
+
+    public static <T> List<T> queue( List<T> list, T item ) {
+        if ( list == null ) {
+            list = new ArrayList<T>();
+        }
+        list.add( item );
+        return list;
+    }
+
+
+    public static <T> List<T> requeue( List<T> list, T item ) {
+        if ( list == null ) {
+            list = new ArrayList<T>();
+        }
+        list.add( 0, item );
+        return list;
+    }
+
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public static List<?> flatten( Collection<?> l ) {
+        boolean hasCollection = false;
+        for ( Object o : l ) {
+            if ( o instanceof Collection ) {
+                hasCollection = true;
+                break;
+            }
+        }
+        if ( !hasCollection && ( l instanceof List ) ) {
+            return ( List<?> ) l;
+        }
+        List newList = new ArrayList();
+        for ( Object o : l ) {
+            if ( o instanceof List ) {
+                newList.addAll( flatten( ( List ) o ) );
+            }
+            else {
+                newList.add( o );
+            }
+        }
+        return newList;
+    }
+
+
+    public static boolean anyNull( List<?> l ) {
+        for ( Object o : l ) {
+            if ( o == null ) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    public static boolean anyNull( Object... objects ) {
+        for ( Object o : objects ) {
+            if ( o == null ) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/MapUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/MapUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/MapUtils.java
new file mode 100644
index 0000000..a7c0b06
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/MapUtils.java
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
+import static org.apache.usergrid.persistence.index.utils.ClassUtils.cast;
+
+
+public class MapUtils extends org.apache.commons.collections.MapUtils {
+
+    public static <A, B> void addMapSet( Map<A, Set<B>> map, A a, B b ) {
+        addMapSet( map, false, a, b );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static <A, B> void addMapSet( Map<A, Set<B>> map, boolean ignoreCase, A a, B b ) {
+
+        Set<B> setB = map.get( a );
+        if ( setB == null ) {
+            if ( ignoreCase && ( b instanceof String ) ) {
+                setB = ( Set<B> ) new TreeSet<String>( String.CASE_INSENSITIVE_ORDER );
+            }
+            else {
+                setB = new LinkedHashSet<B>();
+            }
+            map.put( a, setB );
+        }
+        setB.add( b );
+    }
+
+
+    public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, A a, B b, C c ) {
+        addMapMapSet( map, false, a, b, c );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, boolean ignoreCase, A a, B b, C c ) {
+
+        Map<B, Set<C>> mapB = map.get( a );
+        if ( mapB == null ) {
+            if ( ignoreCase && ( b instanceof String ) ) {
+                mapB = ( Map<B, Set<C>> ) new TreeMap<String, Set<C>>( String.CASE_INSENSITIVE_ORDER );
+            }
+            else {
+                mapB = new LinkedHashMap<B, Set<C>>();
+            }
+            map.put( a, mapB );
+        }
+        addMapSet( mapB, ignoreCase, b, c );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static <A, B, C, D> void addMapMapMapSet( Map<A, Map<B, Map<C, Set<D>>>> map, boolean ignoreCase, A a, B b,
+                                                     C c, D d ) {
+        Map<B, Map<C, Set<D>>> mapB = map.get( a );
+        if ( mapB == null ) {
+            if ( ignoreCase && ( b instanceof String ) ) {
+                mapB = ( Map<B, Map<C, Set<D>>> ) new TreeMap<String, Map<C, Set<D>>>( String.CASE_INSENSITIVE_ORDER );
+            }
+            else {
+                mapB = new LinkedHashMap<B, Map<C, Set<D>>>();
+            }
+            map.put( a, mapB );
+        }
+        addMapMapSet( mapB, ignoreCase, b, c, d );
+    }
+
+
+    public static <A, B, C> C getMapMap( Map<A, Map<B, C>> map, A a, B b ) {
+
+        Map<B, C> mapB = map.get( a );
+        if ( mapB == null ) {
+            return null;
+        }
+        return mapB.get( b );
+    }
+
+
+    public static <A, B> void addMapList( Map<A, List<B>> map, A a, B b ) {
+
+        List<B> listB = map.get( a );
+        if ( listB == null ) {
+            listB = new ArrayList<B>();
+            map.put( a, listB );
+        }
+        listB.add( b );
+    }
+
+
+    public static <A, B> void addListToMapList( Map<A, List<B>> map, A a, List<B> b ) {
+
+        List<B> listB = map.get( a );
+        if ( listB == null ) {
+            listB = new ArrayList<B>();
+            map.put( a, listB );
+        }
+        listB.addAll( b );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static <K, V> V getValue( Map<K, ?> map, K k ) {
+        V v = null;
+        try {
+            v = ( V ) map.get( k );
+        }
+        catch ( ClassCastException e ) {
+            //LOG.war( "Map value {} was not the expected class", map.get( k ), e );
+        }
+
+        return v;
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static <K, V> Map<?, ?> map( Object... objects ) {
+        Map<K, V> map = new LinkedHashMap<K, V>();
+        int i = 0;
+        while ( i < objects.length ) {
+            if ( objects[i] instanceof Map.Entry ) {
+                Map.Entry<K, V> entry = ( Entry<K, V> ) objects[i];
+                map.put( entry.getKey(), entry.getValue() );
+                i++;
+            }
+            else if ( objects[i] instanceof Map ) {
+                map.putAll( ( Map<? extends K, ? extends V> ) objects[i] );
+                i++;
+            }
+            else if ( i < ( objects.length - 1 ) ) {
+                K k = ( K ) objects[i];
+                V v = ( V ) objects[i + 1];
+                map.put( k, v );
+                i += 2;
+            }
+            else {
+                break;
+            }
+        }
+        return map;
+    }
+
+
+    private static class SimpleMapEntry<K, V> implements Map.Entry<K, V> {
+
+        private final K k;
+        private V v;
+
+
+        public SimpleMapEntry( K k, V v ) {
+            this.k = k;
+            this.v = v;
+        }
+
+
+        @Override
+        public K getKey() {
+            return k;
+        }
+
+
+        @Override
+        public V getValue() {
+            return v;
+        }
+
+
+        @Override
+        public V setValue( V v ) {
+            V oldV = this.v;
+            this.v = v;
+            return oldV;
+        }
+    }
+
+
+    public static <K, V> Map.Entry<K, V> entry( K k, V v ) {
+        return new SimpleMapEntry<K, V>( k, v );
+    }
+
+
+    public static <K, V> K getFirstKey( Map<K, V> map ) {
+        if ( map == null ) {
+            return null;
+        }
+        Entry<K, V> e = map.entrySet().iterator().next();
+        if ( e != null ) {
+            return e.getKey();
+        }
+        return null;
+    }
+
+
+    public static <V> Map<String, V> filter( Map<String, V> map, String prefix, boolean removePrefix ) {
+        Map<String, V> filteredMap = new LinkedHashMap<String, V>();
+        for ( Entry<String, V> entry : map.entrySet() ) {
+            if ( entry.getKey().startsWith( prefix ) ) {
+                if ( removePrefix ) {
+                    filteredMap.put( entry.getKey().substring( prefix.length() ), entry.getValue() );
+                }
+                else {
+                    filteredMap.put( entry.getKey(), entry.getValue() );
+                }
+            }
+        }
+        return filteredMap;
+    }
+
+
+    public static <V> Map<String, V> filter( Map<String, V> map, String prefix ) {
+        return filter( map, prefix, false );
+    }
+
+
+    public static Properties filter( Properties properties, String prefix, boolean removePrefix ) {
+        Properties filteredProperties = new Properties();
+        for ( Entry<String, String> entry : asMap( properties ).entrySet() ) {
+            if ( entry.getKey().startsWith( prefix ) ) {
+                if ( removePrefix ) {
+                    filteredProperties.put( entry.getKey().substring( prefix.length() ), entry.getValue() );
+                }
+                else {
+                    filteredProperties.put( entry.getKey(), entry.getValue() );
+                }
+            }
+        }
+        return filteredProperties;
+    }
+
+
+    public static Properties filter( Properties properties, String prefix ) {
+        return filter( properties, prefix, false );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static Map<String, String> asMap( Properties properties ) {
+        return cast( properties );
+    }
+
+
+    public static <S, T> HashMapBuilder<S, T> hashMap( S key, T value ) {
+        return new HashMapBuilder<S, T>().map( key, value );
+    }
+
+
+    public static class HashMapBuilder<S, T> extends HashMap<S, T> {
+        private static final long serialVersionUID = 1L;
+
+
+        public HashMapBuilder() {
+        }
+
+
+        public HashMapBuilder<S, T> map( S key, T value ) {
+            put( key, value );
+            return this;
+        }
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static Map<String, List<?>> toMapList( Map<String, ?> m ) {
+        Map<String, List<Object>> mapList = new LinkedHashMap<String, List<Object>>();
+
+        for ( Entry<String, ?> e : m.entrySet() ) {
+            if ( e.getValue() instanceof List ) {
+                addListToMapList( mapList, e.getKey(), ( List<Object> ) e.getValue() );
+            }
+            else {
+                addMapList( mapList, e.getKey(), e.getValue() );
+            }
+        }
+
+        return cast( mapList );
+    }
+
+
+    public static Map<String, ?> putPath( String path, Object value ) {
+        return putPath( null, path, value );
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public static Map<String, ?> putPath( Map<String, ?> map, String path, Object value ) {
+
+        if ( map == null ) {
+            map = new HashMap<String, Object>();
+        }
+
+        int i = path.indexOf( '.' );
+        if ( i < 0 ) {
+            ( ( Map<String, Object> ) map ).put( path, value );
+            return map;
+        }
+        String segment = path.substring( 0, i ).trim();
+        if ( isNotBlank( segment ) ) {
+            Object o = map.get( segment );
+            if ( ( o != null ) && ( !( o instanceof Map ) ) ) {
+                return map;
+            }
+            Map<String, Object> subMap = ( Map<String, Object> ) o;
+            if ( subMap == null ) {
+                subMap = new HashMap<String, Object>();
+                ( ( Map<String, Object> ) map ).put( segment, subMap );
+            }
+            String subPath = path.substring( i + 1 );
+            if ( isNotBlank( subPath ) ) {
+                putPath( subMap, subPath, value );
+            }
+        }
+
+        return map;
+    }
+
+
+    public static <K, V> Map<K, V> emptyMapWithKeys( Map<K, V> map ) {
+        Map<K, V> newMap = new HashMap<K, V>();
+
+        for ( K k : map.keySet() ) {
+            newMap.put( k, null );
+        }
+
+        return newMap;
+    }
+
+
+    public static boolean hasKeys( Map<?, ?> map, String... keys ) {
+        if ( map == null ) {
+            return false;
+        }
+        for ( String key : keys ) {
+            if ( !map.containsKey( key ) ) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+
+    public static boolean hasKeys( Map<?, ?> map, Set<String> keys ) {
+        if ( map == null ) {
+            return false;
+        }
+        return map.keySet().containsAll( keys );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/StringUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/StringUtils.java
new file mode 100644
index 0000000..8aabbbf
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/StringUtils.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.util.Arrays;
+
+import org.apache.commons.io.IOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.usergrid.persistence.index.utils.ConversionUtils.string;
+
+
+public class StringUtils extends org.apache.commons.lang.StringUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger( StringUtils.class );
+
+
+    public static Object lower( Object obj ) {
+        if ( !( obj instanceof String ) ) {
+            return obj;
+        }
+        return ( ( String ) obj ).toLowerCase();
+    }
+
+
+    public static String stringOrSubstringAfterLast( String str, char c ) {
+        if ( str == null ) {
+            return null;
+        }
+        int i = str.lastIndexOf( c );
+        if ( i != -1 ) {
+            return str.substring( i + 1 );
+        }
+        return str;
+    }
+
+
+    public static String stringOrSubstringBeforeLast( String str, char c ) {
+        if ( str == null ) {
+            return null;
+        }
+        int i = str.lastIndexOf( c );
+        if ( i != -1 ) {
+            return str.substring( 0, i );
+        }
+        return str;
+    }
+
+
+    public static String stringOrSubstringBeforeFirst( String str, char c ) {
+        if ( str == null ) {
+            return null;
+        }
+        int i = str.indexOf( c );
+        if ( i != -1 ) {
+            return str.substring( 0, i );
+        }
+        return str;
+    }
+
+
+    public static String stringOrSubstringAfterFirst( String str, char c ) {
+        if ( str == null ) {
+            return null;
+        }
+        int i = str.indexOf( c );
+        if ( i != -1 ) {
+            return str.substring( i + 1 );
+        }
+        return str;
+    }
+
+
+    public static String compactWhitespace( String str ) {
+        if ( str == null ) {
+            return null;
+        }
+        boolean prevWS = false;
+        StringBuilder builder = new StringBuilder();
+        for ( int i = 0; i < str.length(); i++ ) {
+            char c = str.charAt( i );
+            if ( Character.isWhitespace( c ) ) {
+                if ( !prevWS ) {
+                    builder.append( ' ' );
+                }
+                prevWS = true;
+            }
+            else {
+                prevWS = false;
+                builder.append( c );
+            }
+        }
+        return builder.toString().trim();
+    }
+
+
+    /** @return new string with replace applied */
+    public static String replaceAll( String source, String find, String replace ) {
+        if ( source == null ) {
+            return null;
+        }
+        while ( true ) {
+            String old = source;
+            source = source.replaceAll( find, replace );
+            if ( source.equals( old ) ) {
+                return source;
+            }
+        }
+    }
+
+
+    public static String toString( Object obj ) {
+        return string( obj );
+    }
+
+
+    public static String toStringFormat( Object obj, String format ) {
+        if ( obj != null ) {
+            if ( format != null ) {
+                if ( obj.getClass().isArray() ) {
+                    return String.format( format, Arrays.toString( ( Object[] ) obj ) );
+                }
+                return String.format( format, string( obj ) );
+            }
+            else {
+                return string( obj );
+            }
+        }
+        return "";
+    }
+
+
+    public static boolean isString( Object obj ) {
+        return obj instanceof String;
+    }
+
+
+    public static boolean isStringOrNull( Object obj ) {
+        if ( obj == null ) {
+            return true;
+        }
+        return obj instanceof String;
+    }
+
+
+    public static String readClasspathFileAsString( String filePath ) {
+        try {
+            return IOUtils.toString( StringUtils.class.getResourceAsStream( filePath ) );
+        }
+        catch ( Exception e ) {
+            LOG.error( "Error getting file from classpath: " + filePath, e );
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/UUIDUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/UUIDUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/UUIDUtils.java
new file mode 100644
index 0000000..fdffaef
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/UUIDUtils.java
@@ -0,0 +1,412 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.ReentrantLock;
+
+import com.fasterxml.uuid.EthernetAddress;
+import com.fasterxml.uuid.UUIDComparator;
+
+import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_HI;
+import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_LO;
+import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_MID;
+import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.commons.codec.binary.Base64.decodeBase64;
+import static org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString;
+
+import static org.apache.usergrid.persistence.index.utils.ConversionUtils.bytes;
+import static org.apache.usergrid.persistence.index.utils.ConversionUtils.uuid;
+
+
+public class UUIDUtils {
+    private static final Logger LOG = LoggerFactory.getLogger( UUIDUtils.class );
+    private static final int[] MICROS = new int[1000];
+
+
+    static {
+        for ( int x = 0; x < 1000; x++ ) {
+            MICROS[x] = x * 10;
+        }
+    }
+
+
+    private static ReentrantLock tsLock = new ReentrantLock( true );
+
+    public static final UUID MIN_TIME_UUID = UUID.fromString( "00000000-0000-1000-8000-000000000000" );
+
+    public static final UUID MAX_TIME_UUID = UUID.fromString( "ffffffff-ffff-1fff-bfff-ffffffffffff" );
+
+    public static final UUID ZERO_UUID = new UUID( 0, 0 );
+
+    private static long timestampMillisNow = System.currentTimeMillis();
+
+    private static AtomicInteger currentMicrosPoint = new AtomicInteger( 0 );
+    private static AtomicInteger customMicrosPointer = new AtomicInteger( 0 );
+
+
+    /**
+     * Return the "next" UUID in micro second resolution. <b>WARNING</b>: this is designed to return the next unique
+     * timestamped UUID for this JVM. Depending on velocity of the call, this method may block internally to insure that
+     * "now" is kept in sync with the UUIDs being generated by this call.
+     * <p/>
+     * In other words, we will intentionally burn CPU insuring that this method is not executed more than 10k -1 times
+     * per millisecond and guarantee that those microseconds held within are sequential.
+     * <p/>
+     * If we did not do this, you would get <b>timestamp collision</b> even though the UUIDs will technically be
+     * 'unique.'
+     */
+    public static java.util.UUID newTimeUUID() {
+        // get & inc counter, but roll on 1k (because we divide by 10 on retrieval)
+        // if count + currentMicro > 1k, block and roll
+        tsLock.lock();
+        long ts = System.currentTimeMillis();
+        if ( ts > timestampMillisNow ) {
+            timestampMillisNow = ts;
+            currentMicrosPoint.set( 0 );
+        }
+        int pointer = currentMicrosPoint.getAndIncrement();
+        try {
+            if ( pointer > 990 ) {
+                TimeUnit.MILLISECONDS.sleep( 1L );
+            }
+        }
+        catch ( Exception ex ) {
+            ex.printStackTrace();
+        }
+        finally {
+            tsLock.unlock();
+        }
+        return newTimeUUID( ts, MICROS[pointer] );
+    }
+
+
+    private static final long KCLOCK_OFFSET = 0x01b21dd213814000L;
+    private static final long KCLOCK_MULTIPLIER_L = 10000L;
+
+    private static final Random CLOCK_SEQ_RANDOM = new Random();
+
+
+    // 14 bits of randomness
+    private static int getRandomClockSequence() {
+        return CLOCK_SEQ_RANDOM.nextInt() & 0x3FFF;
+    }
+
+
+    private static void setTimestamp( long timestamp, byte[] uuidBytes, int clockSeq, int timeOffset ) {
+
+        timestamp *= KCLOCK_MULTIPLIER_L;
+        timestamp += KCLOCK_OFFSET;
+        timestamp += timeOffset;
+
+        // Set random clock sequence
+        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] = ( byte ) ( clockSeq >> 8 );
+        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE + 1] = ( byte ) clockSeq;
+
+        // Set variant
+        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] &= 0x3F;
+        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] |= 0x80;
+        setTime( uuidBytes, timestamp );
+    }
+
+
+    @SuppressWarnings("all")
+    private static void setTime( byte[] uuidBytes, long timestamp ) {
+
+        // Time fields aren't nicely split across the UUID, so can't just
+        // linearly dump the stamp:
+        int clockHi = ( int ) ( timestamp >>> 32 );
+        int clockLo = ( int ) timestamp;
+
+        uuidBytes[BYTE_OFFSET_CLOCK_HI] = ( byte ) ( clockHi >>> 24 );
+        uuidBytes[BYTE_OFFSET_CLOCK_HI + 1] = ( byte ) ( clockHi >>> 16 );
+        uuidBytes[BYTE_OFFSET_CLOCK_MID] = ( byte ) ( clockHi >>> 8 );
+        uuidBytes[BYTE_OFFSET_CLOCK_MID + 1] = ( byte ) clockHi;
+
+        uuidBytes[BYTE_OFFSET_CLOCK_LO] = ( byte ) ( clockLo >>> 24 );
+        uuidBytes[BYTE_OFFSET_CLOCK_LO + 1] = ( byte ) ( clockLo >>> 16 );
+        uuidBytes[BYTE_OFFSET_CLOCK_LO + 2] = ( byte ) ( clockLo >>> 8 );
+        uuidBytes[BYTE_OFFSET_CLOCK_LO + 3] = ( byte ) clockLo;
+
+        // Set version
+        uuidBytes[BYTE_OFFSET_CLOCK_HI] &= 0x0F;
+        uuidBytes[BYTE_OFFSET_CLOCK_HI] |= 0x10;
+    }
+
+
+    /**
+     * Generate a timeuuid with the given timestamp in milliseconds and the time offset. Useful when you need to
+     * generate sequential UUIDs for the same period in time. I.E
+     * <p/>
+     * newTimeUUID(1000, 0) <br/> newTimeUUID(1000, 1) <br /> newTimeUUID(1000, 2) <br />
+     * <p/>
+     * etc.
+     * <p/>
+     * Only use this method if you are absolutely sure you need it. When it doubt use the method without the timestamp
+     * offset
+     *
+     * @param ts The timestamp in milliseconds
+     * @param timeoffset The offset, which should always be <= 10000. If you go beyond this range, the millisecond will
+     * be incremented since this is beyond the possible values when coverrting from millis to 1/10 microseconds stored
+     * in the time uuid.
+     */
+    public static UUID newTimeUUID( long ts, int timeoffset ) {
+        if ( ts == 0 ) {
+            return newTimeUUID();
+        }
+
+        byte[] uuidBytes = new byte[16];
+        // 47 bits of randomness
+        EthernetAddress eth = EthernetAddress.constructMulticastAddress();
+        eth.toByteArray( uuidBytes, 10 );
+        setTimestamp( ts, uuidBytes, getRandomClockSequence(), timeoffset );
+
+        return uuid( uuidBytes );
+    }
+
+
+    /**
+     * Generate a new UUID with the given time stamp in milliseconds. This method guarantees that subsequent calls will
+     * be of increasing value chronologically. If a large number of subsequent calls are made to this method (>1000)
+     * with the same timestamp, you will have non-unique temporal values stored in your UUID.
+     */
+    public static UUID newTimeUUID( long ts ) {
+        tsLock.lock();
+        int pointer = customMicrosPointer.getAndIncrement();
+        try {
+            if ( pointer > 990 ) {
+                customMicrosPointer.set( 0 );
+            }
+        }
+        finally {
+            tsLock.unlock();
+        }
+        return newTimeUUID( ts, MICROS[pointer] );
+    }
+
+
+    public static UUID minTimeUUID( long ts ) {
+        byte[] uuidBytes = new byte[16];
+        setTimestamp( ts, uuidBytes, 0, 0 );
+
+        return uuid( uuidBytes );
+    }
+
+
+    public static UUID maxTimeUUID( long ts ) {
+        byte[] uuidBytes = new byte[16];
+        uuidBytes[10] = ( byte ) 0xFF;
+        uuidBytes[11] = ( byte ) 0xFF;
+        uuidBytes[12] = ( byte ) 0xFF;
+        uuidBytes[13] = ( byte ) 0xFF;
+        uuidBytes[14] = ( byte ) 0xFF;
+        uuidBytes[15] = ( byte ) 0xFF;
+        setTimestamp( ts, uuidBytes, 0x3FFF, 0x1FFF );
+
+        return uuid( uuidBytes );
+    }
+
+
+    /** Returns the minimum UUID */
+    public static UUID min( UUID first, UUID second ) {
+        if ( first == null ) {
+            if ( second == null ) {
+                return null;
+            }
+            return second;
+        }
+
+        if ( second == null ) {
+            return first;
+        }
+
+        if ( compare( first, second ) < 0 ) {
+            return first;
+        }
+        return second;
+    }
+
+
+    /** Returns the minimum UUID */
+    public static UUID max( UUID first, UUID second ) {
+        if ( first == null ) {
+            if ( second == null ) {
+                return null;
+            }
+            return second;
+        }
+
+        if ( second == null ) {
+            return first;
+        }
+
+        if ( compare( first, second ) < 0 ) {
+            return second;
+        }
+        return first;
+    }
+
+
+    /** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */
+    public static UUID decrement( UUID uuid ) {
+        if ( !isTimeBased( uuid ) ) {
+            throw new IllegalArgumentException( "The uuid must be a time type" );
+        }
+
+
+        //timestamp is in the 60 bit timestamp
+        long timestamp = uuid.timestamp();
+        timestamp--;
+
+        if ( timestamp < 0 ) {
+            throw new IllegalArgumentException( "You must specify a time uuid with a timestamp > 0" );
+        }
+
+        //get our bytes, then set the smaller timestamp into it
+        byte[] uuidBytes = bytes( uuid );
+
+        setTime( uuidBytes, timestamp );
+
+        return uuid( uuidBytes );
+    }
+
+
+    public static boolean isTimeBased( UUID uuid ) {
+        if ( uuid == null ) {
+            return false;
+        }
+        return uuid.version() == 1;
+    }
+
+
+    public static long getTimestampInMillis( UUID uuid ) {
+        if ( uuid == null ) {
+            return 0;
+        }
+        long t = uuid.timestamp();
+        return ( t - KCLOCK_OFFSET ) / KCLOCK_MULTIPLIER_L;
+    }
+
+
+    public static long getTimestampInMicros( UUID uuid ) {
+        if ( uuid == null ) {
+            return 0;
+        }
+        long t = uuid.timestamp();
+        return ( t - KCLOCK_OFFSET ) / 10;
+    }
+
+
+    public static UUID tryGetUUID( String s ) {
+        if ( s == null ) {
+            return null;
+        }
+        if ( s.length() != 36 ) {
+            return null;
+        }
+        // 8-4-4-4-12
+        // 0-7,8,9-12,13,14-17,18,19-22,23,24-35
+        if ( s.charAt( 8 ) != '-' ) {
+            return null;
+        }
+        if ( s.charAt( 13 ) != '-' ) {
+            return null;
+        }
+        if ( s.charAt( 18 ) != '-' ) {
+            return null;
+        }
+        if ( s.charAt( 23 ) != '-' ) {
+            return null;
+        }
+        UUID uuid = null;
+        try {
+            uuid = UUID.fromString( s );
+        }
+        catch ( Exception e ) {
+            LOG.info( "Could not convert String {} into a UUID", s, e );
+        }
+        return uuid;
+    }
+
+
+    public static boolean isUUID( String s ) {
+        return tryGetUUID( s ) != null;
+    }
+
+
+    public static UUID tryExtractUUID( String s ) {
+        if ( s == null ) {
+            return null;
+        }
+        if ( s.length() < 36 ) {
+            return null;
+        }
+        return tryGetUUID( s.substring( 0, 36 ) );
+    }
+
+
+    public static UUID tryExtractUUID( String s, int offset ) {
+        if ( s == null ) {
+            return null;
+        }
+        if ( ( s.length() - offset ) < 36 ) {
+            return null;
+        }
+        return tryGetUUID( s.substring( offset, offset + 36 ) );
+    }
+
+
+    public static String toBase64( UUID id ) {
+        if ( id == null ) {
+            return null;
+        }
+        return encodeBase64URLSafeString( bytes( id ) );
+    }
+
+
+    public static UUID fromBase64( String str ) {
+        if ( str == null ) {
+            return null;
+        }
+        byte[] bytes = decodeBase64( str );
+        if ( bytes.length != 16 ) {
+            return null;
+        }
+        return uuid( bytes );
+    }
+
+
+    public static int compare( UUID u1, UUID u2 ) {
+        return UUIDComparator.staticCompare( u1, u2 );
+    }
+
+
+    public static List<UUID> sort( List<UUID> uuids ) {
+        Collections.sort( uuids, new UUIDComparator() );
+        return uuids;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
index 9feeaf6..187259d 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
@@ -41,11 +41,11 @@ import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.utils.JsonUtils;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
-import org.apache.usergrid.utils.UUIDUtils;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
+import org.apache.usergrid.persistence.index.utils.JsonUtils;
+import static org.apache.usergrid.persistence.index.utils.MapUtils.hashMap;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
index 827e917..2627298 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
@@ -42,8 +42,8 @@ import org.apache.usergrid.persistence.model.field.DoubleField;
 import org.apache.usergrid.persistence.model.field.LongField;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
index 605c44c..a3e38fc 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
@@ -34,8 +34,8 @@ import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import static org.junit.Assert.assertNotNull;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
index 423780c..f0c42f2 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
@@ -41,9 +41,9 @@ import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.utils.EntityBuilder;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
+import org.apache.usergrid.persistence.index.utils.EntityBuilder;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import static org.junit.Assert.assertEquals;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
index 054dadd..4795783 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
@@ -37,11 +37,11 @@ import org.apache.usergrid.persistence.index.legacy.Point;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.query.EntityRef;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.persistence.query.SimpleEntityRef;
-import org.apache.usergrid.utils.MapUtils;
+import org.apache.usergrid.persistence.index.query.EntityRef;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
+import org.apache.usergrid.persistence.index.query.SimpleEntityRef;
+import org.apache.usergrid.persistence.index.utils.MapUtils;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import static org.junit.Assert.assertEquals;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
index 9bfae05..cd05605 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
@@ -33,9 +33,9 @@ import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.utils.JsonUtils;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
+import org.apache.usergrid.persistence.index.utils.JsonUtils;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import static org.junit.Assert.assertEquals;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
index a7d461f..ba19b86 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
@@ -22,8 +22,8 @@ import java.util.Map;
 import java.util.UUID;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 
 import org.junit.rules.TestRule;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
index fdb23c7..2160527 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
@@ -31,8 +31,8 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 
 
 public class CoreApplication implements Application, TestRule {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
index 56ba256..4c49627 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.persistence.index.legacy;
 
 
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.utils.JsonUtils;
+import org.apache.usergrid.persistence.index.utils.JsonUtils;
 
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
index 4113394..02bad1a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
@@ -16,6 +16,8 @@
 package org.apache.usergrid.persistence.query;
 
 
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import com.google.inject.Inject;
 import java.util.ArrayList;
 import java.util.Comparator;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
index 8f0286f..4761448 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
@@ -16,6 +16,8 @@
 package org.apache.usergrid.persistence.query;
 
 
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import org.apache.usergrid.persistence.index.legacy.CoreApplication;
 import org.junit.Ignore;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/IntersectionUnionPagingIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/IntersectionUnionPagingIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/IntersectionUnionPagingIT.java
index 8199c79..46ba6c3 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/IntersectionUnionPagingIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/IntersectionUnionPagingIT.java
@@ -16,6 +16,8 @@
 package org.apache.usergrid.persistence.query;
 
 
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/QueryTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/QueryTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/QueryTest.java
index 3b09c86..35e50de 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/QueryTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/QueryTest.java
@@ -19,28 +19,29 @@
 package org.apache.usergrid.persistence.query;
 
 
+import org.apache.usergrid.persistence.index.query.Query;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
-import org.apache.usergrid.persistence.exceptions.QueryParseException;
+import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
 
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.query.Query.SortDirection;
-import org.apache.usergrid.persistence.query.Query.SortPredicate;
-import org.apache.usergrid.persistence.query.tree.AndOperand;
-import org.apache.usergrid.persistence.query.tree.ContainsOperand;
-import org.apache.usergrid.persistence.query.tree.Equal;
-import org.apache.usergrid.persistence.query.tree.FloatLiteral;
-import org.apache.usergrid.persistence.query.tree.GreaterThan;
-import org.apache.usergrid.persistence.query.tree.GreaterThanEqual;
-import org.apache.usergrid.persistence.query.tree.LessThan;
-import org.apache.usergrid.persistence.query.tree.LessThanEqual;
-import org.apache.usergrid.persistence.query.tree.LongLiteral;
-import org.apache.usergrid.persistence.query.tree.NotOperand;
-import org.apache.usergrid.persistence.query.tree.StringLiteral;
-import org.apache.usergrid.persistence.query.tree.WithinOperand;
+import org.apache.usergrid.persistence.index.query.Query.SortDirection;
+import org.apache.usergrid.persistence.index.query.Query.SortPredicate;
+import org.apache.usergrid.persistence.index.query.tree.AndOperand;
+import org.apache.usergrid.persistence.index.query.tree.ContainsOperand;
+import org.apache.usergrid.persistence.index.query.tree.Equal;
+import org.apache.usergrid.persistence.index.query.tree.FloatLiteral;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThan;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.LessThan;
+import org.apache.usergrid.persistence.index.query.tree.LessThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.LongLiteral;
+import org.apache.usergrid.persistence.index.query.tree.NotOperand;
+import org.apache.usergrid.persistence.index.query.tree.StringLiteral;
+import org.apache.usergrid.persistence.index.query.tree.WithinOperand;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
index 345bfea..e032855 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
@@ -19,6 +19,22 @@
 package org.apache.usergrid.persistence.query.tree;
 
 
+import org.apache.usergrid.persistence.index.query.tree.LongLiteral;
+import org.apache.usergrid.persistence.index.query.tree.QueryFilterLexer;
+import org.apache.usergrid.persistence.index.query.tree.QueryFilterParser;
+import org.apache.usergrid.persistence.index.query.tree.ContainsOperand;
+import org.apache.usergrid.persistence.index.query.tree.NotOperand;
+import org.apache.usergrid.persistence.index.query.tree.LessThan;
+import org.apache.usergrid.persistence.index.query.tree.AndOperand;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThan;
+import org.apache.usergrid.persistence.index.query.tree.LessThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.UUIDLiteral;
+import org.apache.usergrid.persistence.index.query.tree.Operand;
+import org.apache.usergrid.persistence.index.query.tree.WithinOperand;
+import org.apache.usergrid.persistence.index.query.tree.OrOperand;
+import org.apache.usergrid.persistence.index.query.tree.StringLiteral;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.Equal;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
@@ -26,9 +42,9 @@ import java.util.UUID;
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.RecognitionException;
 import org.antlr.runtime.TokenRewriteStream;
-import org.apache.usergrid.persistence.exceptions.QueryParseException;
+import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
 import org.junit.Test;
-import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.index.query.Query;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/LongLiteralTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/LongLiteralTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/LongLiteralTest.java
index 67039e7..3813268 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/LongLiteralTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/LongLiteralTest.java
@@ -19,6 +19,7 @@
 package org.apache.usergrid.persistence.query.tree;
 
 
+import org.apache.usergrid.persistence.index.query.tree.LongLiteral;
 import org.antlr.runtime.CommonToken;
 import org.junit.Test;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
index 56ef54d..480b6c0 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
@@ -17,7 +17,7 @@ package org.apache.usergrid.persistence.query.tree;
 
 
 import org.antlr.runtime.CommonToken;
-import org.apache.usergrid.persistence.query.tree.StringLiteral;
+import org.apache.usergrid.persistence.index.query.tree.StringLiteral;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;


[13/27] git commit: Merge with hystrix. Added debug logging

Posted by sn...@apache.org.
Merge with hystrix.  Added debug logging


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

Branch: refs/heads/entity-manager
Commit: 029c06502c7359117a49638a7a198375dc0bb868
Parents: 136edab
Author: Todd Nine <tn...@apigee.com>
Authored: Tue Mar 25 17:32:31 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Tue Mar 25 17:32:31 2014 -0700

----------------------------------------------------------------------
 .../graph/impl/NodeDeleteListener.java          |  35 +++---
 .../impl/EdgeSerializationImpl.java             |  16 +--
 .../impl/parse/ObservableIterator.java          |  12 +-
 .../graph/GraphManagerTimeoutIT.java            |  48 ++++----
 .../graph/impl/NodeDeleteListenerTest.java      |  41 ++++---
 .../serialization/EdgeSerializationTest.java    |  93 ++++++++++-----
 .../graph/serialization/TestCount.java          | 117 +++++++++++++++++++
 .../graph/test/util/EdgeTestUtils.java          |  12 +-
 stack/corepersistence/pom.xml                   |   2 +-
 9 files changed, 271 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index 4ba0142..d0c0bec 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -53,30 +53,20 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     private final EdgeMetadataSerialization edgeMetadataSerialization;
     private final EdgeDeleteRepair edgeDeleteRepair;
     private final EdgeMetaRepair edgeMetaRepair;
-<<<<<<< Updated upstream
-=======
     private final GraphFig graphFig;
     protected final Keyspace keyspace;
->>>>>>> Stashed changes
 
 
     /**
      * Wire the serialization dependencies
      */
     @Inject
-<<<<<<< Updated upstream
-    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization, @NodeDelete final AsyncProcessor nodeDelete,
-                               final EdgeMetadataSerialization edgeMetadataSerialization,
-                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair
-                                ) {
-=======
     public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,
 
                                final EdgeMetadataSerialization edgeMetadataSerialization,
                                final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair,
                                final GraphFig graphFig, @NodeDelete final AsyncProcessor nodeDelete,
                                final Keyspace keyspace ) {
->>>>>>> Stashed changes
 
 
         this.nodeSerialization = nodeSerialization;
@@ -163,11 +153,13 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                             @Override
                             public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
 
+                                LOG.debug( "Batching {} edges for deletion" , markedEdges.size());
+
                                 final MutationBatch batch = keyspace.prepareMutationBatch();
 
                                 for(MarkedEdge edge: markedEdges){
 
-                                //delete the newest edge <= the version on the node delete
+                                    //delete the newest edge <= the version on the node delete
                                     LOG.debug( "Deleting edge {}", edge );
                                     final MutationBatch delete = edgeSerialization.deleteEdge( scope,  edge );
 
@@ -184,12 +176,17 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                                 return Observable.from(markedEdges);
                             }
                         } )
-        .flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
-            @Override
-            public Observable<MarkedEdge> call( final MarkedEdge edge ) {
+                        //TODO Fix this
+//        .flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
+//            @Override
+//            public Observable<MarkedEdge> call( final MarkedEdge edge ) {
+//
+//
+//                return Observable.just( edge );
+
+
 
 
-                return Observable.just( edge );
 //                //delete both the source and target meta data in parallel for the edge we deleted in the previous step
 //                //if nothing else is using them
 //                Observable<Integer> sourceMetaRepaired =
@@ -209,8 +206,12 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
 //                                         return edge;
 //                                     }
 //                                 } );
-            }
-        } ).count()
+
+
+//            }
+//        })
+
+    .count()
                 //if nothing is ever emitted, emit 0 so that we know no operations took place. Finally remove the
                 // target node in the mark
                 .defaultIfEmpty( 0 ).doOnCompleted( new Action0() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
index d255929..0341cac 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
@@ -156,8 +156,8 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
         doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public <R extends RowKey> void doWrite(
-                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+            public  void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge> columnFamily, final RowKey rowKey,
                     final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( edge, false );
             }
@@ -182,8 +182,8 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
         doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public <R extends RowKey> void doWrite(
-                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+            public void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge> columnFamily, final RowKey rowKey,
                     final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( edge, true );
             }
@@ -208,8 +208,8 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
         doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public <R extends RowKey> void doWrite(
-                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+            public void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge> columnFamily, final RowKey rowKey,
                     final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).deleteColumn( edge );
             }
@@ -493,7 +493,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
                         .autoPaginate( true ).withColumnRange( rangeBuilder.build() );
 
 
-        return new ColumnNameIterator<DirectedEdge, MarkedEdge>( query, searcher, searcher.hasPage() );
+        return new ColumnNameIterator<DirectedEdge, MarkedEdge>( query, searcher, searcher.hasPage(), graphFig.getReadTimeout() );
     }
 
 
@@ -837,7 +837,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         /**
          * Write the edge with the given data
          */
-        <R extends RowKey> void doWrite(
+        void doWrite(
                 final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, R rowKey,
                 DirectedEdge edge );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
index 2274868..2d2456b 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
@@ -3,6 +3,10 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 
 import java.util.Iterator;
 
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import rx.Observable;
 import rx.Observer;
 import rx.Subscriber;
@@ -17,6 +21,8 @@ import rx.subscriptions.Subscriptions;
  */
 public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T> {
 
+    private static final Logger log = LoggerFactory.getLogger( ObservableIterator.class );
+
 
     @Override
     public void call( final Subscriber<? super T> subscriber ) {
@@ -29,7 +35,11 @@ public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T>
 
             //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
             while ( itr.hasNext() && !subscriber.isUnsubscribed()) {
-                subscriber.onNext( itr.next() );
+                final T next = itr.next();
+
+                log.debug( "Emitting {}", next );
+
+                subscriber.onNext( next );
             }
 
             subscriber.onCompleted();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
index 509fe6a..ed8c1b8 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
@@ -119,7 +119,7 @@ public class GraphManagerTimeoutIT {
     public void testWriteReadEdgeTypeSource( EdgeSerialization serialization ) throws InterruptedException {
 
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
 
         final MarkedEdge edge = createEdge( "source", "edge", "target" );
@@ -223,7 +223,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeTarget() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -256,7 +256,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeVersionSource() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -291,7 +291,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeVersionTarget() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
@@ -330,7 +330,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeVersionSourceDistinct() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -399,7 +399,7 @@ public class GraphManagerTimeoutIT {
     public void testWriteReadEdgeTypeVersionTargetDistinct() {
 
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -467,7 +467,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypePagingSource() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final Id sourceId = createId( "source" );
 
@@ -518,7 +518,7 @@ public class GraphManagerTimeoutIT {
     public void testWriteReadEdgeTypePagingTarget() {
 
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         final Id targetId = createId( "target" );
@@ -569,7 +569,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeTargetTypeSource() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -605,7 +605,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypeTargetTypeTarget() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -641,7 +641,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeDeleteSource() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -697,7 +697,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeDeleteTarget() {
 
-        GraphManager em = emf.createGraphManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -753,7 +753,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypesSourceTypes() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -815,7 +815,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypesTargetTypes() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -880,7 +880,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypesSourceTypesPaging() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -958,7 +958,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testWriteReadEdgeTypesTargetTypesPaging() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1039,7 +1039,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testMarkSourceEdges() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -1108,7 +1108,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testMarkTargetEdges() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1175,7 +1175,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testMarkSourceEdgesType() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -1253,7 +1253,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void testMarkTargetEdgesType() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1331,7 +1331,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void markSourceNode() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -1413,7 +1413,7 @@ public class GraphManagerTimeoutIT {
     @Test
     public void markTargetNode() {
 
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1494,7 +1494,7 @@ public class GraphManagerTimeoutIT {
 
     @Test( expected = NullPointerException.class )
     public void invalidEdgeTypesWrite( @All Edge edge ) {
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         em.writeEdge( edge );
     }
@@ -1502,7 +1502,7 @@ public class GraphManagerTimeoutIT {
 
     @Test( expected = NullPointerException.class )
     public void invalidEdgeTypesDelete( @All Edge edge ) {
-        final GraphManager em = emf.createGraphManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         em.deleteEdge( edge );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
index e735aea..48890ca 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
@@ -11,6 +11,8 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
@@ -50,6 +52,8 @@ import static org.mockito.Mockito.when;
 @UseModules( { TestGraphModule.class } )
 public class NodeDeleteListenerTest {
 
+    private static final Logger log = LoggerFactory.getLogger( NodeDeleteListenerTest.class );
+
     @ClassRule
     public static CassandraRule rule = new CassandraRule();
 
@@ -309,8 +313,8 @@ public class NodeDeleteListenerTest {
 
 
     /**
-     * Simple test case that tests a single edge and removing the node.  The other target node should be removed as
-     * well since it has no other targets
+     * Simple test case that tests a single edge and removing the node.  The other target node should be removed as well
+     * since it has no other targets
      */
     @Test
     public void testMultiDelete() throws ConnectionException {
@@ -324,17 +328,21 @@ public class NodeDeleteListenerTest {
         final String edgeType = "test";
 
         int countSaved = 0;
+        int sourceCount = 0;
+        int targetCount = 0;
 
 
         for ( int i = 0; i < edgeCount; i++ ) {
-            Edge edge ;
+            Edge edge;
 
             //mix up source vs target, good for testing as well as create a lot of sub types to ensure they're removed
             if ( i % 2 == 0 ) {
-                edge = createEdge( toDelete, edgeType, createId( "target"+Math.random() ) );
+                edge = createEdge( toDelete, edgeType, createId( "target" + Math.random() ) );
+                sourceCount++;
             }
             else {
-                edge = createEdge( createId( "source"+Math.random() ), edgeType, toDelete );
+                edge = createEdge( createId( "source" + Math.random() ), edgeType, toDelete );
+                targetCount++;
             }
 
             //write the edge
@@ -346,13 +354,15 @@ public class NodeDeleteListenerTest {
             countSaved++;
         }
 
-        assertEquals(edgeCount, countSaved);
+        assertEquals( edgeCount, countSaved );
+
+        log.info( "Saved {} source edges", sourceCount );
+        log.info( "Saved {} target edges", targetCount );
 
 
         //mark the node so
-//        UUID deleteVersion = UUIDGenerator.newTimeUUID();
+        UUID deleteVersion = UUIDGenerator.newTimeUUID();
 
-        UUID deleteVersion = UUID.fromString( "ffffffff-ffff-1fff-bfff-ffffffffffff" );
 
         nodeSerialization.mark( scope, toDelete, deleteVersion ).execute();
 
@@ -368,21 +378,19 @@ public class NodeDeleteListenerTest {
         UUID now = UUIDGenerator.newTimeUUID();
 
 
-        Iterator<MarkedEdge> returned = edgeSerialization
-                .getEdgesFromSource( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
+        Iterator<MarkedEdge> returned =
+                edgeSerialization.getEdgesFromSource( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
 
         //no edge from source node should be returned
         assertFalse( "No source should be returned", returned.hasNext() );
 
         //validate it's not returned by the
 
-        returned = edgeSerialization
-                .getEdgesToTarget( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
+        returned = edgeSerialization.getEdgesToTarget( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
 
         assertFalse( "No target should be returned", returned.hasNext() );
 
 
-
         //no types from source
 
         Iterator<String> types =
@@ -400,14 +408,13 @@ public class NodeDeleteListenerTest {
 
         //no target types from source
 
-        Iterator<String> idTypes = edgeMetadataSerialization
-                .getIdTypesFromSource( scope, createSearchIdType( toDelete, edgeType, null ) );
+        Iterator<String> idTypes =
+                edgeMetadataSerialization.getIdTypesFromSource( scope, createSearchIdType( toDelete, edgeType, null ) );
 
         assertFalse( idTypes.hasNext() );
 
         //no source types to target
-        idTypes = edgeMetadataSerialization
-                .getIdTypesToTarget( scope, createSearchIdType( toDelete, edgeType, null ) );
+        idTypes = edgeMetadataSerialization.getIdTypesToTarget( scope, createSearchIdType( toDelete, edgeType, null ) );
 
         assertFalse( idTypes.hasNext() );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
index 776b9df..9e016b2 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
@@ -13,6 +13,8 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
@@ -27,6 +29,8 @@ import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
 import com.fasterxml.uuid.UUIDComparator;
 import com.google.inject.Inject;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
@@ -45,10 +49,12 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith(JukitoRunner.class)
-@UseModules({ TestGraphModule.class })
+@RunWith( JukitoRunner.class )
+@UseModules( { TestGraphModule.class } )
 public class EdgeSerializationTest {
 
+    private static final Logger log = LoggerFactory.getLogger( EdgeSerializationTest.class );
+
     @ClassRule
     public static CassandraRule rule = new CassandraRule();
 
@@ -64,6 +70,9 @@ public class EdgeSerializationTest {
     @Inject
     protected GraphFig graphFig;
 
+    @Inject
+    protected Keyspace keyspace;
+
     protected OrganizationScope scope;
 
 
@@ -617,51 +626,83 @@ public class EdgeSerializationTest {
     }
 
 
-
     /**
      * Tests mixing 2 edge types between 2 nodes.  We should get results for the same source->destination with the 2
      * edge types
      */
     @Test
     public void testIteratorPaging() throws ConnectionException {
-        final Edge edgev1 = createEdge( "source", "edge1", "target" );
 
-        final Id sourceId = edgev1.getSourceNode();
-        final Id targetId = edgev1.getTargetNode();
 
+        final Id sourceId = createId( "source" );
+        final String edgeType = "edge";
+        final Id targetId = createId( "target" );
 
-        final Edge edgev2 = createEdge( sourceId, "edge1", targetId );
 
-        assertTrue( "Edge version 1 has lower time uuid",
-                UUIDComparator.staticCompare( edgev1.getVersion(), edgev2.getVersion() ) < 0 );
+        int writeCount = graphFig.getScanPageSize() * 3;
 
-        //create edge type 2 to ensure we don't get it in results
-        final Edge edgeType2V1 = createEdge( sourceId, "edge2", targetId );
 
-        serialization.writeEdge( scope, edgev1 ).execute();
-        serialization.writeEdge( scope, edgev2 ).execute();
-        serialization.writeEdge( scope, edgeType2V1 ).execute();
+        final MutationBatch batch = keyspace.prepareMutationBatch();
 
-        final UUID now = UUIDGenerator.newTimeUUID();
+        UUID lastMax = null;
 
+        for ( int i = 0; i < writeCount; i++ ) {
 
-        SearchByEdge search = createGetByEdge( sourceId, "edge1", targetId, now, null );
+            final Edge edge = createEdge( sourceId, edgeType, targetId );
 
-        Iterator<MarkedEdge> results = serialization.getEdgeVersions( scope, search );
+            lastMax = edge.getVersion();
 
-        assertEquals( edgev2, results.next() );
-        assertEquals( edgev1, results.next() );
-        assertFalse( "No results should be returned", results.hasNext() );
+            batch.mergeShallow( serialization.writeEdge( scope, edge ) );
+        }
 
-        //max version test
+        log.info( "Flushing edges" );
+        batch.execute();
 
-        //test max version
-        search = createGetByEdge( sourceId, "edge1", targetId, edgev1.getVersion(), null );
 
-        results = serialization.getEdgeVersions( scope, search );
+        Iterator<MarkedEdge> results =
+                serialization.getEdgeVersions( scope, createGetByEdge( sourceId, edgeType, targetId, lastMax, null ) );
 
-        assertEquals( edgev1, results.next() );
-        assertFalse( "Max version was honored", results.hasNext() );
+        verify( results, writeCount );
+
+
+
+        //get them all from source
+        results = serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, edgeType, lastMax, null ) );
+
+        verify( results, writeCount );
+
+
+
+        results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, edgeType, lastMax, targetId.getType(), null ) );
+
+        verify( results, writeCount );
+
+
+
+        results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId, edgeType, lastMax, null ) );
+
+        verify( results, writeCount );
+
+
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId, edgeType, lastMax, sourceId.getType(), null ) );
+
+        verify( results, writeCount );
+    }
+
+
+    private void verify( Iterator<MarkedEdge> results, int expectedCount ) {
+        int count = 0;
+
+        while ( results.hasNext() ) {
+            count++;
+            results.next();
+        }
+
+
+        assertEquals( "All versions returned", expectedCount, count );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
new file mode 100644
index 0000000..7af55da
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
@@ -0,0 +1,117 @@
+package org.apache.usergrid.persistence.graph.serialization;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Test;
+
+import rx.Observable;
+import rx.Subscriber;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ *
+ *
+ */
+public class TestCount {
+
+
+    @Test
+    public void mergeTest(){
+
+        final int sizePerObservable = 2000;
+
+        Observable<Integer> input1 = getObservables( sizePerObservable );
+        Observable<Integer> input2 = getObservables( sizePerObservable );
+
+       int returned =  Observable.merge(input1, input2).buffer( 1000 ).flatMap(
+               new Func1<List<Integer>, Observable<Integer>>() {
+                   @Override
+                   public Observable<Integer> call( final List<Integer> integers ) {
+
+                       //simulates batching a network operation from buffer, then re-emitting the values passed
+
+                       try {
+                           Thread.sleep( 100 );
+                       }
+                       catch ( InterruptedException e ) {
+                           throw new RuntimeException( e );
+                       }
+
+
+                       return Observable.from( integers );
+                   }
+               } ).count().defaultIfEmpty( 0 ).toBlockingObservable().last();
+
+
+        assertEquals("Count was correct", sizePerObservable*2, returned);
+    }
+
+
+    /**
+     * Get observables from the sets
+     * @param size
+     * @return
+     */
+    private Observable<Integer> getObservables( int size ){
+
+        final List<Integer> values = new ArrayList<Integer>(size);
+
+        for(int i = 0; i <size; i ++ ) {
+            values.add( i );
+        }
+
+
+        /**
+         * Simulates occasional sleeps while we fetch something over the network
+         */
+        return Observable.create( new Observable.OnSubscribe<Integer>() {
+            @Override
+            public void call( final Subscriber<? super Integer> subscriber ) {
+
+                final int size = values.size();
+
+                for(int i = 0; i < size; i ++){
+
+
+
+                    if(i%1000 == 0){
+                        //simulate network fetch
+                        try {
+                            Thread.sleep( 250 );
+                        }
+                        catch ( InterruptedException e ) {
+                            subscriber.onError( e );
+                            return;
+                        }
+                    }
+
+                    //Sleep for a very long time before emitting the last value
+                    if(i == size -1){
+                        try {
+                            Thread.sleep(5000);
+                        }
+                        catch ( InterruptedException e ) {
+                            subscriber.onError( e );
+                            return;
+                        }
+                    }
+
+
+                    subscriber.onNext( values.get( i ) );
+                }
+
+                subscriber.onCompleted();
+
+                //purposefully no error handling here
+            }
+        } ).subscribeOn( Schedulers.io() );
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
index 68a67d2..27b9a38 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
@@ -70,22 +70,12 @@ public class EdgeTestUtils {
     /**
      * Create an edge with the specified params
      */
-    public static MarkedEdge createEdge( final Id sourceId, final String edgeType, final Id targetId,
-                                         final UUID version ) {
+    public static MarkedEdge createEdge( final Id sourceId, final String edgeType, final Id targetId, final UUID version ) {
         return new SimpleMarkedEdge( sourceId, edgeType, targetId, version, false );
     }
 
 
     /**
-     * Create an edge with the specified params
-     */
-    public static MarkedEdge createEdge( final String sourceType, final String edgeType, final String targetType,
-                                         final UUID version ) {
-        return new SimpleMarkedEdge( createId( sourceType ), edgeType, createId( targetType ), version, false );
-    }
-
-
-    /**
      * Create the id
      */
     public static Id createId( String type ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/029c0650/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 2beddd5..9b7b1e1 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -75,7 +75,7 @@
                     <systemPropertyVariables>
                         <archaius.deployment.environment>UNIT</archaius.deployment.environment>
                     </systemPropertyVariables>
-                    <argLine>-Xms2G -Xmx2G</argLine>
+                    <argLine>-Xms2G -Xmx4G</argLine>
                 </configuration>
             </plugin>
 


[11/27] Merged hystrix into asyncqueue

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
index 548d821..9344e70 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
@@ -65,12 +65,12 @@ public interface EdgeSerialization {
 
 
     /**
-     * Search for specific versions of the edge from source->target. Will return all versions.
+     * Search for all versions of this edge < the search version.  Returns all versions
      * @param scope
      * @param search
      * @return
      */
-    Iterator<MarkedEdge> getEdgeFromSource( OrganizationScope scope, SearchByEdge search );
+    Iterator<MarkedEdge> getEdgeVersions( OrganizationScope scope, SearchByEdge search );
 
     /**
      * Get an iterator of all edges by edge type originating from source node
@@ -97,14 +97,6 @@ public interface EdgeSerialization {
      */
     Iterator<MarkedEdge> getEdgesToTarget( OrganizationScope scope, SearchByEdgeType edgeType );
 
-    /**
-     * Search for specific versions of the edge from source->target. Will return all versions
-     * @param scope
-     * @param search
-     * @return
-     */
-    Iterator<MarkedEdge> getEdgeToTarget( OrganizationScope scope, SearchByEdge search );
-
 
     /**
      * Get an iterator of all edges by edge type pointing to the target node.  Also uses the source id type to limit the

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
index 7e11206..d255929 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
@@ -85,6 +85,8 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
     //row key with target id type
     private static final RowTypeSerializer ROW_TYPE_SERIALIZER = new RowTypeSerializer();
 
+    private static final EdgeRowKeySerializer EDGE_ROW_KEY_SERIALIZER = new EdgeRowKeySerializer();
+
     //Edge serializers
     private static final EdgeSerializer EDGE_SERIALIZER = new EdgeSerializer();
 
@@ -124,6 +126,15 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
                     new OrganizationScopedRowKeySerializer<RowKeyType>( ROW_TYPE_SERIALIZER ), EDGE_SERIALIZER );
 
 
+    /**
+     * Get all graph edge versions
+     */
+    private static final MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID> GRAPH_EDGE_VERSIONS =
+            new MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID>( "Graph_Edge_Versions",
+                    new OrganizationScopedRowKeySerializer<EdgeRowKey>( EDGE_ROW_KEY_SERIALIZER ),
+                    UUIDSerializer.get() );
+
+
     protected final Keyspace keyspace;
     protected final CassandraConfig cassandraConfig;
     protected final GraphFig graphFig;
@@ -140,16 +151,23 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     @Override
     public MutationBatch writeEdge( final OrganizationScope scope, final Edge edge ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );;
+        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL());
 
 
-        doWrite( scope, edge, new RowOp() {
+        doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public void doWrite( final MultiTennantColumnFamily columnFamily, final Object rowKey,
-                                 final DirectedEdge edge ) {
-
+            public <R extends RowKey> void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+                    final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( edge, false );
             }
+
+
+            @Override
+            public void doWrite( final MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID> columnFamily,
+                                 final EdgeRowKey rowKey, final UUID version ) {
+                batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( version, false );
+            }
         } );
 
 
@@ -159,16 +177,23 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     @Override
     public MutationBatch markEdge( final OrganizationScope scope, final Edge edge ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );;
+        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );
 
 
-        doWrite( scope, edge, new RowOp() {
+        doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public void doWrite( final MultiTennantColumnFamily columnFamily, final Object rowKey,
-                                 final DirectedEdge edge ) {
-
+            public <R extends RowKey> void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+                    final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( edge, true );
             }
+
+
+            @Override
+            public void doWrite( final MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID> columnFamily,
+                                 final EdgeRowKey rowKey, final UUID version ) {
+                batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( version, true );
+            }
         } );
 
 
@@ -181,13 +206,20 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );
 
 
-        doWrite( scope, edge, new RowOp() {
+        doWrite( scope, edge, new RowOp<RowKey>() {
             @Override
-            public void doWrite( final MultiTennantColumnFamily columnFamily, final Object rowKey,
-                                 final DirectedEdge edge ) {
-
+            public <R extends RowKey> void doWrite(
+                    final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, final R rowKey,
+                    final DirectedEdge edge ) {
                 batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).deleteColumn( edge );
             }
+
+
+            @Override
+            public void doWrite( final MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID> columnFamily,
+                                 final EdgeRowKey rowKey, final UUID version ) {
+                batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).deleteColumn( version );
+            }
         } );
 
 
@@ -197,7 +229,8 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     /**
      * EdgeWrite the edges internally
-     * @param scope  The scope to encapsulate
+     *
+     * @param scope The scope to encapsulate
      * @param edge The edge to write
      * @param op The row operation to invoke
      */
@@ -229,23 +262,35 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         final DirectedEdge targetEdge = new DirectedEdge( sourceNodeId, version );
 
 
+        final EdgeRowKey edgeRowKey = new EdgeRowKey( sourceNodeId, type, targetNodeId );
+
+
         /**
-         * EdgeWrite edges from target<-source
+         * write edges from source->target
          */
 
-
         op.doWrite( GRAPH_SOURCE_NODE_EDGES, sourceRowKey, sourceEdge );
 
         op.doWrite( GRAPH_SOURCE_NODE_TARGET_TYPE, sourceRowKeyType, sourceEdge );
 
+
+        /**
+         * write edges from target<-source
+         */
         op.doWrite( GRAPH_TARGET_NODE_EDGES, targetRowKey, targetEdge );
 
         op.doWrite( GRAPH_TARGET_NODE_SOURCE_TYPE, targetRowKeyType, targetEdge );
+
+
+        /**
+         * Write this in the version log for this edge of source->target
+         */
+        op.doWrite( GRAPH_EDGE_VERSIONS, edgeRowKey, version );
     }
 
 
     @Override
-    public Iterator<MarkedEdge> getEdgeFromSource( final OrganizationScope scope, final SearchByEdge search ) {
+    public Iterator<MarkedEdge> getEdgeVersions( final OrganizationScope scope, final SearchByEdge search ) {
         ValidationUtils.validateOrganizationScope( scope );
         EdgeUtils.validateSearchByEdge( search );
 
@@ -387,52 +432,6 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
     @Override
-    public Iterator<MarkedEdge> getEdgeToTarget( final OrganizationScope scope, final SearchByEdge search ) {
-        ValidationUtils.validateOrganizationScope( scope );
-        EdgeUtils.validateSearchByEdge( search );
-
-        final Id sourceId = search.sourceNode();
-        final Id targetId = search.targetNode();
-        final UUID maxVersion = search.getMaxVersion();
-        final String type = search.getType();
-
-        return getEdges( GRAPH_TARGET_NODE_EDGES, new EdgeSearcher<RowKey>( scope, search.last() ) {
-
-
-            @Override
-            public void setRange( final RangeBuilder builder ) {
-                if ( last.isPresent() ) {
-                    super.setRange( builder );
-                    return;
-                }
-
-                //set the last value in the range based on the max version
-                final DirectedEdge colValue = new DirectedEdge( sourceId, maxVersion );
-                builder.setStart( colValue, EDGE_SERIALIZER );
-            }
-
-
-            @Override
-            protected RowKey generateRowKey() {
-                return new RowKey( targetId, type );
-            }
-
-
-            @Override
-            protected DirectedEdge getStartColumn( final Edge last ) {
-                return new DirectedEdge( last.getSourceNode(), last.getVersion() );
-            }
-
-
-            @Override
-            protected MarkedEdge createEdge( final DirectedEdge edge, final boolean marked ) {
-                return new SimpleMarkedEdge( edge.id, type, targetId, edge.version, marked );
-            }
-        } );
-    }
-
-
-    @Override
     public Iterator<MarkedEdge> getEdgesToTargetBySourceType( final OrganizationScope scope,
                                                               final SearchByIdType edgeType ) {
 
@@ -490,20 +489,21 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
         RowQuery<ScopedRowKey<OrganizationScope, R>, DirectedEdge> query =
-                keyspace.prepareQuery( cf ).setConsistencyLevel( cassandraConfig.getReadCL() ).getKey( rowKey ).autoPaginate( true )
-                        .withColumnRange( rangeBuilder.build() );
-
+                keyspace.prepareQuery( cf ).setConsistencyLevel( cassandraConfig.getReadCL() ).getKey( rowKey )
+                        .autoPaginate( true ).withColumnRange( rangeBuilder.build() );
 
-        return new ColumnNameIterator<DirectedEdge, MarkedEdge>( query, searcher,
-                    searcher.hasPage(), graphFig.getReadTimeout() );
 
+        return new ColumnNameIterator<DirectedEdge, MarkedEdge>( query, searcher, searcher.hasPage() );
     }
 
 
     @Override
     public Collection<MultiTennantColumnFamilyDefinition> getColumnFamilies() {
         return Arrays.asList( graphCf( GRAPH_SOURCE_NODE_EDGES ), graphCf( GRAPH_TARGET_NODE_EDGES ),
-                graphCf( GRAPH_SOURCE_NODE_TARGET_TYPE ), graphCf( GRAPH_TARGET_NODE_SOURCE_TYPE ) );
+                graphCf( GRAPH_SOURCE_NODE_TARGET_TYPE ), graphCf( GRAPH_TARGET_NODE_SOURCE_TYPE ),
+                new MultiTennantColumnFamilyDefinition( GRAPH_EDGE_VERSIONS, BytesType.class.getSimpleName(),
+                        ColumnTypes.UUID_TYPE_REVERSED, BytesType.class.getSimpleName(),
+                        MultiTennantColumnFamilyDefinition.CacheOption.KEYS ) );
     }
 
 
@@ -511,8 +511,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
      * Helper to generate an edge definition by the type
      */
     private MultiTennantColumnFamilyDefinition graphCf( MultiTennantColumnFamily cf ) {
-        return new MultiTennantColumnFamilyDefinition( cf,
-                BytesType.class.getSimpleName(), ColumnTypes.DYNAMIC_COMPOSITE_TYPE, BytesType.class.getSimpleName() , MultiTennantColumnFamilyDefinition.CacheOption.KEYS);
+        return new MultiTennantColumnFamilyDefinition( cf, BytesType.class.getSimpleName(),
+                ColumnTypes.DYNAMIC_COMPOSITE_TYPE, BytesType.class.getSimpleName(),
+                MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
     }
 
 
@@ -558,11 +559,12 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
             Preconditions.checkArgument( composite.size() == 3, "Composite should have 3 elements" );
 
 
-            //parse our id
-            final Id id = ID_COL_SERIALIZER.fromComposite( composite, 0 );
-
             //return the version
-            final UUID version = composite.get( 2, UUID_SERIALIZER );
+            final UUID version = composite.get( 0, UUID_SERIALIZER );
+
+
+            //parse our id
+            final Id id = ID_COL_SERIALIZER.fromComposite( composite, 1 );
 
 
             return new DirectedEdge( id, version );
@@ -575,11 +577,13 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         private DynamicComposite createComposite( DirectedEdge edge, AbstractComposite.ComponentEquality equality ) {
             DynamicComposite composite = new DynamicComposite();
 
-            ID_COL_SERIALIZER.toComposite( composite, edge.id );
-
             //add our edge
             composite.addComponent( edge.version, UUID_SERIALIZER, ColumnTypes.UUID_TYPE_REVERSED, equality );
 
+
+            ID_COL_SERIALIZER.toComposite( composite, edge.id );
+
+
             return composite;
         }
     }
@@ -646,6 +650,23 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
     /**
+     * Used to store row keys by sourceId, targetId and edgeType
+     */
+    private static class EdgeRowKey {
+        public final Id sourceId;
+        public final Id targetId;
+        public final String edgeType;
+
+
+        private EdgeRowKey( final Id sourceId, final String edgeType, final Id targetId ) {
+            this.sourceId = sourceId;
+            this.targetId = targetId;
+            this.edgeType = edgeType;
+        }
+    }
+
+
+    /**
      * Searcher to be used when performing the search.  Performs I/O transformation as well as parsing for the iterator
      */
     private static abstract class EdgeSearcher<R> implements ColumnParser<DirectedEdge, MarkedEdge> {
@@ -779,11 +800,51 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
     /**
+     * Class to perform serialization for row keys from edges
+     */
+    private static class EdgeRowKeySerializer implements CompositeFieldSerializer<EdgeRowKey> {
+
+        private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
+
+
+        @Override
+        public void toComposite( final CompositeBuilder builder, final EdgeRowKey key ) {
+
+            //add the row id to the composite
+            ID_SER.toComposite( builder, key.sourceId );
+            builder.addString( key.edgeType );
+            ID_SER.toComposite( builder, key.targetId );
+        }
+
+
+        @Override
+        public EdgeRowKey fromComposite( final CompositeParser composite ) {
+
+            final Id sourceId = ID_SER.fromComposite( composite );
+            final String edgeType = composite.readString();
+            final Id targetId = ID_SER.fromComposite( composite );
+
+            return new EdgeRowKey( sourceId, edgeType, targetId );
+        }
+    }
+
+
+    /**
      * Simple callback to perform puts and deletes with a common row setup code
      */
     private static interface RowOp<R> {
 
-        void doWrite( final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, R rowKey,
-                      DirectedEdge edge );
+        /**
+         * Write the edge with the given data
+         */
+        <R extends RowKey> void doWrite(
+                final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, R rowKey,
+                DirectedEdge edge );
+
+        /**
+         * Write the edge into the version cf
+         */
+        void doWrite( final MultiTennantColumnFamily<OrganizationScope, EdgeRowKey, UUID> columnFamily,
+                      EdgeRowKey rowKey, UUID version );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
index 17a5f5a..379f56a 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
@@ -46,6 +46,7 @@ import com.google.inject.Inject;
 import rx.Observable;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
@@ -72,7 +73,7 @@ public class EdgeManagerIT {
 
 
     @Inject
-    protected EdgeManagerFactory emf;
+    protected GraphManagerFactory emf;
 
     protected OrganizationScope scope;
 
@@ -93,7 +94,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeSource() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -126,7 +127,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeTarget() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -159,7 +160,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeVersionSource() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -194,7 +195,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeVersionTarget() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
@@ -233,7 +234,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeVersionSourceDistinct() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -266,6 +267,8 @@ public class EdgeManagerIT {
         Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
 
         assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
         assertFalse( "No more edges", returned.hasNext() );
 
         //now test with an earlier version, we shouldn't get the edge back
@@ -276,6 +279,7 @@ public class EdgeManagerIT {
         returned = edges.toBlockingObservable().getIterator();
 
         assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
         assertFalse( "No more edges", returned.hasNext() );
 
         search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
@@ -302,7 +306,7 @@ public class EdgeManagerIT {
     public void testWriteReadEdgeTypeVersionTargetDistinct() {
 
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final UUID earlyVersion = UUIDGenerator.newTimeUUID();
 
@@ -335,6 +339,8 @@ public class EdgeManagerIT {
         Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
 
         assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
         assertFalse( "No more edges", returned.hasNext() );
 
         //now test with an earlier version, we shouldn't get the edge back
@@ -345,6 +351,7 @@ public class EdgeManagerIT {
         returned = edges.toBlockingObservable().getIterator();
 
         assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
         assertFalse( "No more edges", returned.hasNext() );
 
         search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
@@ -370,7 +377,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypePagingSource() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         final Id sourceId = createId( "source" );
 
@@ -391,7 +398,7 @@ public class EdgeManagerIT {
         //now test retrieving it
 
         SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
 
         Observable<Edge> edges = em.loadEdgesFromSource( search );
 
@@ -400,10 +407,15 @@ public class EdgeManagerIT {
 
 
         //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+
         assertEquals( "Correct edge returned", edge1, returned.next() );
 
         assertFalse( "No more edges", returned.hasNext() );
 
+        //still edge 3 is our max version, but we start with edge 2 as our last read
         search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
 
         edges = em.loadEdgesFromSource( search );
@@ -411,7 +423,7 @@ public class EdgeManagerIT {
         //implicitly blows up if more than 1 is returned from "single"
         returned = edges.toBlockingObservable().getIterator();
 
-        assertEquals( "Paged correctly", edge3, returned.next() );
+        assertEquals( "Paged correctly", edge1, returned.next() );
 
         assertFalse( "End of stream", returned.hasNext() );
     }
@@ -421,7 +433,7 @@ public class EdgeManagerIT {
     public void testWriteReadEdgeTypePagingTarget() {
 
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         final Id targetId = createId( "target" );
@@ -442,7 +454,7 @@ public class EdgeManagerIT {
         //now test retrieving it
 
         SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
 
         Observable<Edge> edges = em.loadEdgesToTarget( search );
 
@@ -451,6 +463,10 @@ public class EdgeManagerIT {
 
 
         //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+
         assertEquals( "Correct edge returned", edge1, returned.next() );
 
 
@@ -463,7 +479,7 @@ public class EdgeManagerIT {
         //implicitly blows up if more than 1 is returned from "single"
         returned = edges.toBlockingObservable().getIterator();
 
-        assertEquals( "Paged correctly", edge3, returned.next() );
+        assertEquals( "Paged correctly", edge1, returned.next() );
 
         assertFalse( "End of stream", returned.hasNext() );
     }
@@ -472,7 +488,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeTargetTypeSource() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -508,7 +524,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypeTargetTypeTarget() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -544,7 +560,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeDeleteSource() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -573,9 +589,20 @@ public class EdgeManagerIT {
 
         assertEquals( "Correct edge returned", edge, returned );
 
+        final SearchByEdge searchByEdge = createGetByEdge(edge.getSourceNode(), edge.getType(), edge.getTargetNode(), edge.getVersion(), null);
+
+        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().single();
+
+
+        assertEquals( "Correct edge returned", edge, returned );
+
 
         //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
+        returned = em.deleteEdge( edge ).toBlockingObservable().last();
+
+
+        assertEquals( "Correct edge returned", edge, returned );
+
 
         //now test retrieval, should be null
         edges = em.loadEdgesFromSource( search );
@@ -586,6 +613,7 @@ public class EdgeManagerIT {
         assertNull( "No edge returned", returned );
 
 
+
         //no search by type, should be null as well
 
         edges = em.loadEdgesFromSourceByType( searchById );
@@ -594,13 +622,17 @@ public class EdgeManagerIT {
         returned = edges.toBlockingObservable().singleOrDefault( null );
 
         assertNull( "No edge returned", returned );
+
+        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().singleOrDefault(null);
+
+        assertNull( "No edge returned", returned );
     }
 
 
     @Test
     public void testWriteReadEdgeDeleteTarget() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
 
         Edge edge = createEdge( "source", "test", "target" );
@@ -656,7 +688,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypesSourceTypes() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -718,7 +750,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypesTargetTypes() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -783,7 +815,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypesSourceTypesPaging() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -861,7 +893,7 @@ public class EdgeManagerIT {
     @Test
     public void testWriteReadEdgeTypesTargetTypesPaging() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -942,7 +974,7 @@ public class EdgeManagerIT {
     @Test
     public void testMarkSourceEdges() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -968,10 +1000,10 @@ public class EdgeManagerIT {
         Iterator<Edge> results = edges.toBlockingObservable().getIterator();
 
 
-        assertEquals( "Edges correct", edge1, results.next() );
-
         assertEquals( "Edges correct", edge2, results.next() );
 
+        assertEquals( "Edges correct", edge1, results.next() );
+
         assertFalse( "No more edges", results.hasNext() );
 
         //now delete one of the edges
@@ -1011,7 +1043,7 @@ public class EdgeManagerIT {
     @Test
     public void testMarkTargetEdges() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1037,9 +1069,10 @@ public class EdgeManagerIT {
         Iterator<Edge> results = edges.toBlockingObservable().getIterator();
 
 
+        assertEquals( "Edges correct", edge2, results.next() );
+
         assertEquals( "Edges correct", edge1, results.next() );
 
-        assertEquals( "Edges correct", edge2, results.next() );
 
         assertFalse( "No more edges", results.hasNext() );
 
@@ -1078,7 +1111,7 @@ public class EdgeManagerIT {
     @Test
     public void testMarkSourceEdgesType() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -1156,7 +1189,7 @@ public class EdgeManagerIT {
     @Test
     public void testMarkTargetEdgesType() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1234,7 +1267,7 @@ public class EdgeManagerIT {
     @Test
     public void markSourceNode() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId = new SimpleId( "source" );
         Id targetId1 = new SimpleId( "target" );
@@ -1256,10 +1289,10 @@ public class EdgeManagerIT {
                   .toBlockingObservable().getIterator();
 
 
-        assertEquals( "Edge found", edge1, results.next() );
-
         assertEquals( "Edge found", edge2, results.next() );
 
+        assertEquals( "Edge found", edge1, results.next() );
+
         assertFalse( "No more edges", results.hasNext() );
 
 
@@ -1313,12 +1346,10 @@ public class EdgeManagerIT {
     }
 
 
-
-
     @Test
     public void markTargetNode() {
 
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         Id sourceId1 = new SimpleId( "source" );
         Id sourceId2 = new SimpleId( "source2" );
@@ -1340,10 +1371,10 @@ public class EdgeManagerIT {
                   .toBlockingObservable().getIterator();
 
 
-        assertEquals( "Edge found", edge1, results.next() );
-
         assertEquals( "Edge found", edge2, results.next() );
 
+        assertEquals( "Edge found", edge1, results.next() );
+
         assertFalse( "No more edges", results.hasNext() );
 
 
@@ -1397,10 +1428,9 @@ public class EdgeManagerIT {
     }
 
 
-
     @Test(expected = NullPointerException.class)
     public void invalidEdgeTypesWrite( @All Edge edge ) {
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         em.writeEdge( edge );
     }
@@ -1408,7 +1438,7 @@ public class EdgeManagerIT {
 
     @Test(expected = NullPointerException.class)
     public void invalidEdgeTypesDelete( @All Edge edge ) {
-        final EdgeManager em = emf.createEdgeManager( scope );
+        final GraphManager em = emf.createEdgeManager( scope );
 
         em.deleteEdge( edge );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
index 773e3ee..9d8db6e 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
@@ -28,6 +28,7 @@ import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -58,13 +59,13 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 
-@RunWith( JukitoRunner.class )
-@UseModules( TestGraphModule.class )
+@RunWith(JukitoRunner.class)
+@UseModules(TestGraphModule.class)
 public class EdgeManagerStressTest {
     private static final Logger log = LoggerFactory.getLogger( EdgeManagerStressTest.class );
 
     @Inject
-    private EdgeManagerFactory factory;
+    private GraphManagerFactory factory;
 
     @ClassRule
     public static CassandraRule rule = new CassandraRule();
@@ -91,6 +92,7 @@ public class EdgeManagerStressTest {
 
 
     @Test
+    @Ignore
     public void writeThousands() throws InterruptedException {
         EdgeGenerator generator = new EdgeGenerator() {
 
@@ -108,7 +110,7 @@ public class EdgeManagerStressTest {
 
 
             @Override
-            public Observable<Edge> doSearch( final EdgeManager manager ) {
+            public Observable<Edge> doSearch( final GraphManager manager ) {
 
 
                 final UUID uuid = UUIDGenerator.newTimeUUID();
@@ -176,6 +178,8 @@ public class EdgeManagerStressTest {
         doTest( generator );
     }
 
+
+    @Ignore
     @Test
     public void writeThousandsSingleSource() throws InterruptedException {
         EdgeGenerator generator = new EdgeGenerator() {
@@ -193,7 +197,7 @@ public class EdgeManagerStressTest {
 
 
             @Override
-            public Observable<Edge> doSearch( final EdgeManager manager ) {
+            public Observable<Edge> doSearch( final GraphManager manager ) {
                 UUID uuid = UUIDGenerator.newTimeUUID();
 
                 return manager.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceId, "test", uuid, null ) );
@@ -203,41 +207,41 @@ public class EdgeManagerStressTest {
         doTest( generator );
     }
 
+
     @Test
-       public void writeThousandsSingleTarget() throws InterruptedException {
-           EdgeGenerator generator = new EdgeGenerator() {
+    @Ignore
+    public void writeThousandsSingleTarget() throws InterruptedException {
+        EdgeGenerator generator = new EdgeGenerator() {
 
-               private Id targetId = createId( "target" );
+            private Id targetId = createId( "target" );
 
 
-               @Override
-               public Edge newEdge() {
-                   Edge edge = createEdge( createId( "source" ), "test", targetId );
+            @Override
+            public Edge newEdge() {
+                Edge edge = createEdge( createId( "source" ), "test", targetId );
 
 
-                   return edge;
-               }
+                return edge;
+            }
 
 
-               @Override
-               public Observable<Edge> doSearch( final EdgeManager manager ) {
-                   UUID uuid = UUIDGenerator.newTimeUUID();
+            @Override
+            public Observable<Edge> doSearch( final GraphManager manager ) {
+                UUID uuid = UUIDGenerator.newTimeUUID();
 
-                   return manager.loadEdgesToTarget( new SimpleSearchByEdgeType( targetId, "test", uuid, null ) );
-               }
-           };
+                return manager.loadEdgesToTarget( new SimpleSearchByEdgeType( targetId, "test", uuid, null ) );
+            }
+        };
 
-           doTest( generator );
-       }
+        doTest( generator );
+    }
 
 
     /**
      * Execute the test with the generator
-     * @param generator
-     * @throws InterruptedException
      */
     private void doTest( EdgeGenerator generator ) throws InterruptedException {
-        EdgeManager manager = factory.createEdgeManager( scope );
+        GraphManager manager = factory.createEdgeManager( scope );
 
         int limit = 10000;
 
@@ -308,6 +312,6 @@ public class EdgeManagerStressTest {
          */
         public Edge newEdge();
 
-        public Observable<Edge> doSearch( final EdgeManager manager );
+        public Observable<Edge> doSearch( final GraphManager manager );
     }
 }


[04/27] git commit: Removed scheduler to instead use the default RX scheduler.

Posted by sn...@apache.org.
Removed scheduler to instead use the default RX scheduler.


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

Branch: refs/heads/entity-manager
Commit: 457528f50e26166a2c157897a128ef135d5a2991
Parents: df0091b
Author: Todd Nine <tn...@apigee.com>
Authored: Fri Mar 21 10:15:22 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Fri Mar 21 10:15:22 2014 -0700

----------------------------------------------------------------------
 .../collection/guice/CollectionModule.java      |   8 +-
 .../impl/EntityCollectionManagerImpl.java       |  19 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |  14 +-
 .../collection/rx/CassandraThreadScheduler.java | 107 -----
 .../persistence/collection/rx/RxFig.java        |  42 --
 .../stage/write/WriteUniqueVerifyStageTest.java |   3 +-
 .../mvcc/stage/write/WriteUniqueVerifyTest.java |   6 +-
 .../rx/CassandraThreadSchedulerTest.java        | 413 -------------------
 .../persistence/collection/rx/ParallelTest.java |   6 +-
 .../graph/consistency/AsyncProcessorImpl.java   |   6 +-
 .../graph/hystrix/HystrixGraphObservable.java   |  52 +++
 .../persistence/graph/impl/EdgeManagerImpl.java |  58 +--
 .../graph/impl/NodeDeleteListener.java          |  23 +-
 .../graph/impl/stage/AbstractEdgeRepair.java    |  11 +-
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |   4 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |  13 +-
 .../graph/impl/stage/EdgeWriteRepairImpl.java   |   4 +-
 .../persistence/graph/EdgeManagerTimeoutIT.java | 125 ++++--
 .../graph/consistency/AsyncProcessorTest.java   |   2 +-
 .../graph/test/util/EdgeTestUtils.java          |  17 +-
 20 files changed, 240 insertions(+), 693 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
index e0744c3..8f41a2b 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
@@ -29,8 +29,6 @@ import org.apache.usergrid.persistence.collection.impl.EntityCollectionManagerSy
 import org.apache.usergrid.persistence.collection.migration.MigrationManagerFig;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategyImpl;
-import org.apache.usergrid.persistence.collection.rx.CassandraThreadScheduler;
-import org.apache.usergrid.persistence.collection.rx.RxFig;
 import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
 import org.apache.usergrid.persistence.collection.serialization.impl.SerializationModule;
 import org.apache.usergrid.persistence.collection.service.impl.ServiceModule;
@@ -38,8 +36,6 @@ import org.apache.usergrid.persistence.collection.service.impl.ServiceModule;
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
 
-import rx.Scheduler;
-
 
 /**
  * Simple module for wiring our collection api
@@ -52,8 +48,7 @@ public class CollectionModule extends AbstractModule {
     @Override
     protected void configure() {
         //noinspection unchecked
-        install( new GuicyFigModule( 
-                RxFig.class, 
+        install( new GuicyFigModule(
                 MigrationManagerFig.class,
                 CassandraFig.class, 
                 SerializationFig.class ) );
@@ -67,7 +62,6 @@ public class CollectionModule extends AbstractModule {
                 .implement( EntityCollectionManagerSync.class, EntityCollectionManagerSyncImpl.class )
                 .build( EntityCollectionManagerFactory.class ) );
 
-        bind( Scheduler.class ).toProvider( CassandraThreadScheduler.class );
 
         bind( UniqueValueSerializationStrategy.class ).to( UniqueValueSerializationStrategyImpl.class );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index ef95a75..0a099e8 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -46,10 +46,10 @@ import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Func1;
 import rx.functions.Func2;
 import rx.functions.FuncN;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -65,7 +65,6 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
     private final CollectionScope collectionScope;
     private final UUIDService uuidService;
-    private final Scheduler scheduler;
 
 
     //start stages
@@ -87,7 +86,6 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
     public EntityCollectionManagerImpl( 
         final UUIDService uuidService, 
         final WriteStart writeStart,
-        final Scheduler scheduler, 
         final WriteUniqueVerify writeVerifyUnique,
         final WriteOptimisticVerify writeOptimisticVerify,
         final WriteCommit writeCommit, 
@@ -108,7 +106,6 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         this.markCommit = markCommit;
 
         this.uuidService = uuidService;
-        this.scheduler = scheduler;
         this.collectionScope = collectionScope;
     }
 
@@ -138,7 +135,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
 
         // fire the stages
-        // TODO use our own scheduler to help with multitenancy here.
+        // TODO use our own Schedulers.io() to help with multitenancy here.
         // TODO writeOptimisticVerify and writeVerifyUnique should be concurrent to reduce wait time
         // these 3 lines could be done in a single line, but they are on multiple lines for clarity
 
@@ -146,7 +143,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         CollectionIoEvent<Entity> writeData = new CollectionIoEvent<Entity>( collectionScope, entity );
 
         Observable<CollectionIoEvent<MvccEntity>> observable =
-            Observable.from( writeData ).subscribeOn( scheduler ).map( writeStart ).flatMap(
+            Observable.from( writeData ).subscribeOn( Schedulers.io() ).map( writeStart ).flatMap(
                 new Func1<CollectionIoEvent<MvccEntity>, Observable<CollectionIoEvent<MvccEntity>>>() {
 
                     @Override
@@ -163,13 +160,13 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
 
                         Observable<CollectionIoEvent<MvccEntity>> unique =
-                            Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
+                            Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( Schedulers.io() )
                                 .flatMap( writeVerifyUnique);
 
 
                         // optimistic verification
                         Observable<CollectionIoEvent<MvccEntity>> optimistic =
-                            Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
+                            Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( Schedulers.io() )
                                 .map( writeOptimisticVerify );
 
 
@@ -193,7 +190,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
         // execute all validation stages concurrently.  Needs refactored when this is done.  
         // https://github.com/Netflix/RxJava/issues/627
-        // observable = Concurrent.concurrent( observable, scheduler, new WaitZip(), 
+        // observable = Concurrent.concurrent( observable, Schedulers.io(), new WaitZip(), 
         //                  writeVerifyUnique, writeOptimisticVerify );
 
         //return the commit result.
@@ -209,7 +206,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         Preconditions.checkNotNull( entityId.getType(), "Entity type is required in this stage" );
 
         return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) )
-            .subscribeOn( scheduler ).map( markStart ).map( markCommit );
+            .subscribeOn( Schedulers.io() ).map( markStart ).map( markCommit );
     }
 
 
@@ -221,7 +218,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         Preconditions.checkNotNull( entityId.getType(), "Entity id type required in load stage");
 
         return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) )
-            .subscribeOn( scheduler ).map( load );
+            .subscribeOn( Schedulers.io() ).map( load );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
index fe53b13..d7733c2 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
@@ -39,9 +39,9 @@ import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Func1;
 import rx.functions.FuncN;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -54,22 +54,16 @@ public class WriteUniqueVerify implements Func1<CollectionIoEvent<MvccEntity>, O
 
     private final UniqueValueSerializationStrategy uniqueValueStrat;
 
-
-    private final Scheduler scheduler;
-
     protected final SerializationFig serializationFig;
 
 
     @Inject
-    public WriteUniqueVerify( final UniqueValueSerializationStrategy uniqueValueSerializiationStrategy,
-                              final Scheduler scheduler, final SerializationFig serializationFig ) {
+    public WriteUniqueVerify( final UniqueValueSerializationStrategy uniqueValueSerializiationStrategy, final SerializationFig serializationFig ) {
 
         Preconditions.checkNotNull( uniqueValueSerializiationStrategy, "uniqueValueSerializationStrategy is required" );
-        Preconditions.checkNotNull( scheduler, "scheduler is required" );
         Preconditions.checkNotNull( serializationFig, "serializationFig is required" );
 
         this.uniqueValueStrat = uniqueValueSerializiationStrategy;
-        this.scheduler = scheduler;
         this.serializationFig = serializationFig;
     }
 
@@ -101,7 +95,7 @@ public class WriteUniqueVerify implements Func1<CollectionIoEvent<MvccEntity>, O
             //if it's unique, create a function to validate it and add it to the list of concurrent validations
             if ( field.isUnique() ) {
 
-                Observable<FieldUniquenessResult> result =  Observable.from( field ).subscribeOn( scheduler ).map(new Func1<Field,  FieldUniquenessResult>() {
+                Observable<FieldUniquenessResult> result =  Observable.from( field ).subscribeOn( Schedulers.io() ).map(new Func1<Field,  FieldUniquenessResult>() {
                     @Override
                     public FieldUniquenessResult call(Field field ) {
 
@@ -139,7 +133,7 @@ public class WriteUniqueVerify implements Func1<CollectionIoEvent<MvccEntity>, O
 
         //short circuit.  If we zip up nothing, we block forever.
         if(fields.size() == 0){
-            return Observable.from(ioevent ).subscribeOn( scheduler );
+            return Observable.from(ioevent ).subscribeOn( Schedulers.io() );
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadScheduler.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadScheduler.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadScheduler.java
deleted file mode 100644
index b2f2584..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadScheduler.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.usergrid.persistence.collection.rx;
-
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.name.Named;
-
-import rx.Scheduler;
-import rx.schedulers.Schedulers;
-
-
-public class CassandraThreadScheduler implements Provider<Scheduler> {
-
-    private static final Logger LOG = LoggerFactory.getLogger(CassandraThreadScheduler.class);
-
-    private final RxFig rxFig;
-
-
-    @Inject
-    public CassandraThreadScheduler( final RxFig rxFig ) {
-        this.rxFig = rxFig;
-    }
-
-
-    @Override
-    @Named( "cassandraScheduler" )
-    public Scheduler get() {
-
-        //create our thread factory so we can label our threads in case we need to dump them
-        final ThreadFactory factory = new ThreadFactory() {
-
-            private final AtomicLong counter = new AtomicLong();
-
-            @Override
-            public Thread newThread( final Runnable r ) {
-
-               final String threadName = "RxCassandraIOThreadPool-" + counter.incrementAndGet();
-
-                LOG.debug( "Allocating new IO thread with name {}", threadName );
-
-                Thread t = new Thread( r, threadName );
-                t.setDaemon( true );
-                return t;
-            }
-        };
-
-
-        /**
-         * Create a threadpool that will reclaim unused threads after 60 seconds.  
-         * It uses the max thread count set here. It intentionally uses the 
-         * DynamicProperty, so that when it is updated, the listener updates the 
-         * pool size. Additional allocation is trivial.  Shrinking the size 
-         * will require all currently executing threads to run to completion, 
-         * without allowing additional tasks to be queued.
-         */
-        final ThreadPoolExecutor pool = new ThreadPoolExecutor( 
-                0, rxFig.getMaxThreadCount(), 60L, TimeUnit.SECONDS,
-                new SynchronousQueue<Runnable>(), factory, new ThreadPoolExecutor.AbortPolicy() );
-
-
-        // if our max thread count is updated, we want to immediately update the pool.  
-        // Per the javadoc if the size is smaller, existing threads will continue to run 
-        // until they become idle and time out
-        rxFig.addPropertyChangeListener( new PropertyChangeListener() {
-            @Override
-            public void propertyChange( final PropertyChangeEvent evt ) {
-                if ( evt.getPropertyName().equals( rxFig.getKeyByMethod( "getMaxThreadCount" ) ) ) {
-                    LOG.debug( "Getting update to property: rxFig.getMaxThreadCount() old = {}, new = {} ",
-                            evt.getOldValue(), evt.getNewValue() );
-                    pool.setMaximumPoolSize( ( Integer ) evt.getNewValue() );
-                }
-            }
-        } );
-
-        return Schedulers.executor( pool );
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/RxFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/RxFig.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/RxFig.java
deleted file mode 100644
index 54a5211..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/rx/RxFig.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.usergrid.persistence.collection.rx;
-
-
-import org.safehaus.guicyfig.Default;
-import org.safehaus.guicyfig.FigSingleton;
-import org.safehaus.guicyfig.GuicyFig;
-import org.safehaus.guicyfig.Key;
-
-
-/**
- * Configuration interface for RxJava classes.
- */
-@FigSingleton
-public interface RxFig extends GuicyFig {
-
-    public static final String PROP_THREAD = "rx.cassandra.io.threads";
-
-    /**
-     * Max number of threads a pool can allocate.  Can be dynamically changed after starting
-     */
-    @Key( PROP_THREAD )
-    @Default( "100" )
-    int getMaxThreadCount();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
index 78b7d13..863e3ce 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
@@ -40,9 +40,8 @@ public class WriteUniqueVerifyStageTest extends AbstractMvccEntityStageTest {
     @Override
     protected void validateStage( final CollectionIoEvent<MvccEntity> event ) {
         UniqueValueSerializationStrategy uvstrat = mock( UniqueValueSerializationStrategy.class );
-        Scheduler scheduler = mock( Scheduler.class );
         SerializationFig fig = mock( SerializationFig.class );
-        new WriteUniqueVerify( uvstrat, scheduler, fig ).call( event );
+        new WriteUniqueVerify( uvstrat, fig ).call( event );
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
index 20dfa91..1a12fef 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
@@ -81,8 +81,6 @@ public class WriteUniqueVerifyTest {
     public MigrationManagerRule migrationManagerRule;
 
 
-    @Inject
-    private Scheduler scheduler;
 
     @Inject
     private SerializationFig fig;
@@ -103,7 +101,7 @@ public class WriteUniqueVerifyTest {
         final MvccEntity mvccEntity = fromEntity( entity );
 
         // run the stage
-        WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, scheduler, fig );
+        WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, fig );
 
         CollectionIoEvent<MvccEntity> result = newStage.call( 
             new CollectionIoEvent<MvccEntity>( collectionScope, mvccEntity ) )
@@ -134,7 +132,7 @@ public class WriteUniqueVerifyTest {
         final MvccEntity mvccEntity = fromEntity( entity );
 
         // run the stage
-        WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, scheduler, fig );
+        WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, fig );
 
         CollectionIoEvent<MvccEntity> result = newStage.call( 
             new CollectionIoEvent<MvccEntity>( collectionScope, mvccEntity ) )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadSchedulerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadSchedulerTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadSchedulerTest.java
deleted file mode 100644
index c700e06..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/CassandraThreadSchedulerTest.java
+++ /dev/null
@@ -1,413 +0,0 @@
-package org.apache.usergrid.persistence.collection.rx;
-
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
-
-import com.google.inject.Inject;
-
-import rx.Scheduler;
-import rx.functions.Action1;
-import rx.schedulers.Schedulers;
-import rx.util.functions.Action0;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-
-/**
- * Test for our scheduler
- */
-@RunWith( JukitoRunner.class )
-@UseModules( TestCollectionModule.class )
-public class CassandraThreadSchedulerTest {
-
-
-    private static final Logger LOG = LoggerFactory.getLogger( CassandraThreadSchedulerTest.class );
-
-    /**
-     * Number of milliseconds to wait when trying to acquire the semaphore
-     */
-    private static final long TEST_TIMEOUT = 30000;
-
-    @Inject
-    private RxFig rxFig;
-
-
-    @Test
-    public void testMaxLimit() throws InterruptedException {
-
-        final int maxCount = 10;
-
-        rxFig.override( RxFig.PROP_THREAD, ""+ maxCount );
-
-        final CassandraThreadScheduler cassSchedulerSetup = new CassandraThreadScheduler( rxFig );
-
-        final Scheduler rxScheduler = cassSchedulerSetup.get();
-
-        //we want a fair semaphore so we can release in acquire order
-        final Semaphore semaphore = new Semaphore( 0, true );
-
-        //we should not have maxCount actions running in the scheduler
-        CountDownLatch result = schedule( rxScheduler, rxFig.getMaxThreadCount(), semaphore, TEST_TIMEOUT );
-
-        //schedule and we should fail
-
-        try {
-            rxScheduler.schedule( new Action1<Scheduler.Inner>() {
-                            @Override
-                            public void call( final Scheduler.Inner inner ) {
-                            }
-                            });
-
-            fail( "This should have thrown an exception" );
-        }
-        catch ( RejectedExecutionException ree ) {
-            //swallow, we just want to ensure we catch this to continue the test
-        }
-
-        //now release the semaphore so all 10 can run
-        semaphore.release( rxFig.getMaxThreadCount() );
-
-        //wait for completion
-        boolean completed = result.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-
-        //verify we can schedule and execute a new operation
-        result = schedule( rxScheduler, 1, semaphore, TEST_TIMEOUT );
-
-        semaphore.release( 1 );
-
-        completed = result.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-    }
-
-
-    /**
-     * Test running from a max limit to a lower limit and fails to schedule new threads
-     */
-    @Test
-    public void testMaxLimitShrink() throws InterruptedException {
-
-        final int maxCount = 10;
-
-        final int half = maxCount / 2;
-
-        //kind of a hack, but necessary with the way properties are singletons.  Otherwise you get side effects from
-        // other tests
-        rxFig.override( RxFig.PROP_THREAD, "" + maxCount );
-
-        final CassandraThreadScheduler cassSchedulerSetup = new CassandraThreadScheduler( rxFig );
-
-        final Scheduler rxScheduler = cassSchedulerSetup.get();
-
-        //we want a fair semaphore so we can release in acquire order
-        final Semaphore semaphore = new Semaphore( 0, true );
-
-        //we should not have maxCount actions running in the scheduler
-        CountDownLatch firstHalf = schedule( rxScheduler, half, semaphore, TEST_TIMEOUT );
-
-        //schedule the second half
-        CountDownLatch secondHalf = schedule( rxScheduler, half, semaphore, TEST_TIMEOUT );
-
-        //schedule and we should fail
-
-        try {
-
-            rxScheduler.schedule(  new Action1<Scheduler.Inner>() {
-                            @Override
-                            public void call( final Scheduler.Inner inner ) {
-                    //no op
-                }
-            } );
-
-            fail( "This should have thrown an exception" );
-        }
-        catch ( RejectedExecutionException ree ) {
-            //swallow, we just want to ensure we catch this to continue the test
-        }
-
-
-        //update the property to shrink the size
-        rxFig.override( RxFig.PROP_THREAD, "" + half );
-
-        //now release the first half of executors
-        semaphore.release( half );
-
-
-        //wait for completion
-        boolean completed = firstHalf.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-
-        //verify we can't schedule b/c we're still at capacity
-
-
-        try {
-
-            rxScheduler.schedule(  new Action1<Scheduler.Inner>() {
-                            @Override
-                            public void call( final Scheduler.Inner inner ) {
-                    //no op
-                }
-            } );
-
-            fail( "This should have thrown an exception.  We still don't have capacity for new threads" );
-        }
-        catch ( RejectedExecutionException ree ) {
-            //swallow, we just want to ensure we catch this to continue the test
-        }
-
-
-        //now release the rest of the semaphores
-        semaphore.release( maxCount - half );
-
-        completed = secondHalf.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-
-        //verify we can schedule and execute a new operation
-        CountDownLatch newJob = schedule( rxScheduler, 1, semaphore, TEST_TIMEOUT  );
-
-        semaphore.release( 1 );
-
-        completed = newJob.await( 20, TimeUnit.SECONDS );
-        assertTrue( "Completed executing actions", completed );
-    }
-
-
-    /**
-     * Test that when we're fully blocked, if we expand we have capacity
-     */
-    @Test
-    public void testExpandLimit() throws InterruptedException {
-
-        final int startCount = 10;
-
-        //kind of a hack, but necessary with the way properties are singletons.  Otherwise you get side effects from
-        // other tests
-        rxFig.override( RxFig.PROP_THREAD, "" + startCount );
-
-        final CassandraThreadScheduler cassSchedulerSetup = new CassandraThreadScheduler( rxFig );
-
-        final Scheduler rxScheduler = cassSchedulerSetup.get();
-
-        //we want a fair semaphore so we can release in acquire order
-        final Semaphore semaphore = new Semaphore( 0, true );
-
-        //we should not have maxCount actions running in the scheduler
-        CountDownLatch firstBatch = schedule( rxScheduler, rxFig.getMaxThreadCount(), semaphore, TEST_TIMEOUT  );
-
-        //schedule and we should fail
-
-        try {
-
-            rxScheduler.schedule(  new Action1<Scheduler.Inner>() {
-                            @Override
-                            public void call( final Scheduler.Inner inner ) {
-                    //no op
-                }
-            } );
-
-            fail( "This should have thrown an exception" );
-        }
-        catch ( RejectedExecutionException ree ) {
-            //swallow, we just want to ensure we catch this to continue the test
-        }
-
-
-        //now allocate more capacity
-        final int doubleMaxCount = startCount * 2;
-
-        //update the property to shrink the size
-        rxFig.override( RxFig.PROP_THREAD, "" + doubleMaxCount );
-
-
-        //now schedule 10 more
-
-        CountDownLatch secondBatch = schedule( rxScheduler, rxFig.getMaxThreadCount() - startCount, semaphore, TEST_TIMEOUT  );
-
-        //this should fail.  We're at capacity
-
-        try {
-
-            rxScheduler.schedule(  new Action1<Scheduler.Inner>() {
-                            @Override
-                            public void call( final Scheduler.Inner inner ) {
-                    //no op
-                }
-            } );
-
-            fail( "This should have thrown an exception" );
-        }
-        catch ( RejectedExecutionException ree ) {
-            //swallow, we just want to ensure we catch this to continue the test
-        }
-
-
-        //now release the semaphores so all
-        semaphore.release( rxFig.getMaxThreadCount() );
-
-        //wait for completion
-        boolean completed = firstBatch.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-
-        completed = secondBatch.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-
-        //verify we can schedule and execute a new operation
-        CountDownLatch result = schedule( rxScheduler, 1, semaphore, TEST_TIMEOUT  );
-
-        semaphore.release( 1 );
-
-        completed = result.await( 20, TimeUnit.SECONDS );
-
-        assertTrue( "Completed executing actions", completed );
-    }
-
-    @Test(expected = RejectedExecutionException.class)
-    public void schedulerPoc() throws InterruptedException {
-
-        final int size = 10;
-
-        //create our thread factory so we can label our threads in case we need to dump them
-        final ThreadFactory factory = new ThreadFactory() {
-
-            private final AtomicLong counter = new AtomicLong();
-
-            @Override
-            public Thread newThread( final Runnable r ) {
-
-               final String threadName = "RxCassandraIOThreadPool-" + counter.incrementAndGet();
-
-                LOG.debug( "Allocating new IO thread with name {}", threadName );
-
-                Thread t = new Thread( r, threadName );
-                t.setDaemon( true );
-                return t;
-            }
-        };
-
-
-        /**
-         * Create a threadpool that will reclaim unused threads after 60 seconds.
-         * It uses the max thread count set here. It intentionally uses the
-         * DynamicProperty, so that when it is updated, the listener updates the
-         * pool size. Additional allocation is trivial.  Shrinking the size
-         * will require all currently executing threads to run to completion,
-         * without allowing additional tasks to be queued.
-         */
-        final ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(10, factory, new ThreadPoolExecutor.AbortPolicy());
-        //set the max thread size
-        pool.setMaximumPoolSize( 10 );
-        pool.setKeepAliveTime( 60, TimeUnit.SECONDS );
-
-        final CountDownLatch latch = new CountDownLatch( size );
-        final Semaphore semaphore = new Semaphore( 0 );
-
-        for(int i = 0; i < size; i ++){
-            pool.schedule( new Callable<Object>() {
-                @Override
-                public Object call() throws Exception {
-
-                    latch.countDown();
-
-                    //block so this is still running in the scheduled execute
-                    semaphore.acquire();
-
-                    return null;  //To change body of implemented methods use File | Settings | File Templates.
-                }
-            }, 0, TimeUnit.MILLISECONDS );
-
-
-
-
-        }
-
-
-        //wait for all our threads to get to semaphore acquisition and block to ensure we're running at capacity
-        latch.await();
-
-        //now schedule 1 more, we should blow up
-
-        pool.schedule( new Callable<Object>() {
-            @Override
-            public Object call() throws Exception {
-                return null;  //To change body of implemented methods use File | Settings | File Templates.
-            }
-        }, 0, TimeUnit.MILLISECONDS );
-
-
-
-    }
-
-
-    /**
-     * Schedule actions into the semaphore.
-     *
-     * @param rxScheduler the Scheduler to use
-     * @param totalCount The total count of actions to invoke
-     * @param semaphore The semaphore to take on acquire
-     *
-     * @return The latch to block on.  When all jobs have been executed this will be tripped
-     */
-    private CountDownLatch schedule( Scheduler rxScheduler, final int totalCount, final Semaphore semaphore, final long timeout ) {
-
-        final CountDownLatch latch = new CountDownLatch( totalCount );
-
-        for ( int i = 0; i < totalCount; i++ ) {
-
-            final Action1<Scheduler.Inner> action = new  Action1<Scheduler.Inner>() {
-                                       @Override
-                                       public void call( final Scheduler.Inner inner ) {
-                    try {
-                        final String threadName = Thread.currentThread().getName();
-
-                        LOG.info( "{} trying to acquire semaphore", threadName );
-                        //get and release the lock
-                        semaphore.tryAcquire( timeout, TimeUnit.MILLISECONDS );
-
-                        LOG.info( "{} has acquired sempahore", threadName );
-
-                        //countdown the latch
-                        latch.countDown();
-                    }
-                    catch ( InterruptedException e ) {
-                        throw new RuntimeException( e );
-                    }
-                }
-            };
-
-            rxScheduler.schedule( action );
-        }
-
-
-        return latch;
-    }
-
-
-
-}
-
-
-

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/ParallelTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/ParallelTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/ParallelTest.java
index 5d72ae6..471fe1f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/ParallelTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/rx/ParallelTest.java
@@ -79,7 +79,7 @@ public class ParallelTest {
         //        final Scheduler scheduler = Schedulers.threadPoolForComputation();
 
         //use the I/O scheduler to allow enough thread, otherwise our pool will be the same size as the # of cores
-        final Scheduler scheduler = Schedulers.io();
+
 
         //set our size equal
 //        ConfigurationManager.getConfigInstance().setProperty( THREAD_POOL_SIZE, size );
@@ -102,7 +102,7 @@ public class ParallelTest {
          *  non blocking?
          */
 
-        final Observable<String> observable = Observable.from( input ).observeOn( scheduler );
+        final Observable<String> observable = Observable.from( input ).observeOn( Schedulers.io() );
 
 
         Observable<Integer> thing = observable.mapMany( new Func1<String, Observable<Integer>>() {
@@ -124,7 +124,7 @@ public class ParallelTest {
                     /**
                      * QUESTION: Should this again be the process thread, not the I/O
                      */
-                    Observable<String> newObservable = Observable.from( input ).subscribeOn( scheduler );
+                    Observable<String> newObservable = Observable.from( input ).subscribeOn( Schedulers.io() );
 
                     Observable<Integer> transformed = newObservable.map( new Func1<String, Integer>() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
index b949d55..2b00d1a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
@@ -36,7 +36,6 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
     private static final Logger LOG = LoggerFactory.getLogger( AsyncProcessor.class );
 
     protected final TimeoutQueue<T> queue;
-    protected final Scheduler scheduler;
     protected final GraphFig graphFig;
     protected final List<MessageListener<T, T>> listeners = new ArrayList<MessageListener<T, T>>();
 
@@ -46,9 +45,8 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
 
 
     @Inject
-    public AsyncProcessorImpl( final TimeoutQueue<T> queue, final Scheduler scheduler, final GraphFig graphFig ) {
+    public AsyncProcessorImpl( final TimeoutQueue<T> queue, final GraphFig graphFig ) {
         this.queue = queue;
-        this.scheduler = scheduler;
         this.graphFig = graphFig;
 
         //we purposefully use a new thread.  We don't want to use one of the I/O threads to run this task
@@ -72,7 +70,7 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
         List<Observable<?>> observables = new ArrayList<Observable<?>>( listeners.size() );
 
         for ( MessageListener<T, T> listener : listeners ) {
-            observables.add( listener.receive( data ).subscribeOn( scheduler ) );
+            observables.add( listener.receive( data ).subscribeOn( Schedulers.io() ) );
         }
 
         //run everything in parallel and zip it up

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
new file mode 100644
index 0000000..8a44389
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph.hystrix;
+
+
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixObservableCommand;
+
+import rx.Observable;
+import rx.schedulers.Schedulers;
+
+
+/**
+ *
+ *
+ */
+public class HystrixGraphObservable {
+
+    /**
+     * Wrap the observable in the timeout
+     * @param observable
+     * @param <T>
+     * @return
+     */
+    public static <T> Observable<T> wrap(final Observable<T> observable){
+            return new HystrixObservableCommand<T>( HystrixCommandGroupKey.Factory.asKey( "Graph" ) ){
+
+                @Override
+                protected Observable<T> run() {
+                    return observable;
+                }
+            }.toObservable( Schedulers.io() );
+        }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
index f825767..4e5746a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
@@ -57,6 +57,7 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Func1;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -68,8 +69,6 @@ public class EdgeManagerImpl implements EdgeManager {
 
     private final OrganizationScope scope;
 
-    private final Scheduler scheduler;
-
     private final EdgeMetadataSerialization edgeMetadataSerialization;
 
 
@@ -85,7 +84,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
 
     @Inject
-    public EdgeManagerImpl( final Scheduler scheduler, final EdgeMetadataSerialization edgeMetadataSerialization,
+    public EdgeManagerImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
                             final EdgeSerialization edgeSerialization, final NodeSerialization nodeSerialization,
                             final GraphFig graphFig, @EdgeWrite final AsyncProcessor edgeWrite,
                             @EdgeDelete final AsyncProcessor edgeDelete, @NodeDelete final AsyncProcessor nodeDelete,
@@ -95,7 +94,6 @@ public class EdgeManagerImpl implements EdgeManager {
 
 
         this.scope = scope;
-        this.scheduler = scheduler;
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeSerialization = edgeSerialization;
         this.nodeSerialization = nodeSerialization;
@@ -116,7 +114,7 @@ public class EdgeManagerImpl implements EdgeManager {
     public Observable<Edge> writeEdge( final Edge edge ) {
         EdgeUtils.validateEdge( edge );
 
-        return Observable.from( edge ).subscribeOn( scheduler ).map( new Func1<Edge, Edge>() {
+        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
             @Override
             public Edge call( final Edge edge ) {
                 final MutationBatch mutation = edgeMetadataSerialization.writeEdge( scope, edge );
@@ -146,7 +144,7 @@ public class EdgeManagerImpl implements EdgeManager {
     public Observable<Edge> deleteEdge( final Edge edge ) {
         EdgeUtils.validateEdge( edge );
 
-        return Observable.from( edge ).subscribeOn( scheduler ).map( new Func1<Edge, Edge>() {
+        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
             @Override
             public Edge call( final Edge edge ) {
                 final MutationBatch edgeMutation = edgeSerialization.markEdge( scope, edge );
@@ -172,7 +170,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Id> deleteNode( final Id node ) {
-        return Observable.from( node ).subscribeOn( scheduler ).map( new Func1<Id, Id>() {
+        return Observable.from( node ).subscribeOn(  Schedulers.io() ).map( new Func1<Id, Id>() {
             @Override
             public Id call( final Id id ) {
 
@@ -201,33 +199,37 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-                return edgeSerialization.getEdgesFromSource( scope, search );
-            }
-        } )//we intentionally use distinct until changed.  This way we won't store all the keys since this
-                //would hog far too much ram.
-                .distinctUntilChanged( new Func1<Edge, Id>() {
+
+
+        return
+
+                Observable.create( new ObservableIterator<MarkedEdge>() {
                     @Override
-                    public Id call( final Edge edge ) {
-                        return edge.getTargetNode();
+                    protected Iterator<MarkedEdge> getIterator() {
+                        return edgeSerialization.getEdgesFromSource( scope, search );
                     }
-                } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                .cast( Edge.class );
+                } )//we intentionally use distinct until changed.  This way we won't store all the keys since this
+                        //would hog far too much memory.
+                        .distinctUntilChanged( new Func1<Edge, Id>() {
+                            @Override
+                            public Id call( final Edge edge ) {
+                                return edge.getTargetNode();
+                            }
+                        } ).buffer( graphFig.getScanPageSize() )
+                        .flatMap( new EdgeBufferFilter( search.getMaxVersion() ) ).cast( Edge.class );
     }
 
 
     @Override
     public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
             }
         } )
                 //we intentionally use distinct until changed.  This way we won't store all the keys since this
-                //would hog far too much ram.
+                //would hog far too much memory.
                 .distinctUntilChanged( new Func1<Edge, Id>() {
                     @Override
                     public Id call( final Edge edge ) {
@@ -240,7 +242,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
@@ -258,7 +260,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
@@ -276,7 +278,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( ) {
+        return Observable.create( new ObservableIterator<String>() {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -287,7 +289,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( ) {
+        return Observable.create( new ObservableIterator<String>() {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
@@ -299,7 +301,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( ) {
+        return Observable.create( new ObservableIterator<String>() {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -310,7 +312,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( ) {
+        return Observable.create( new ObservableIterator<String>() {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesToTarget( scope, search );
@@ -351,7 +353,7 @@ public class EdgeManagerImpl implements EdgeManager {
         public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
 
             final Map<Id, UUID> markedVersions = nodeSerialization.getMaxVersions( scope, markedEdges );
-            return Observable.from( markedEdges ).subscribeOn( scheduler )
+            return Observable.from( markedEdges ).subscribeOn(  Schedulers.io() )
                              .filter( new EdgeFilter( this.maxVersion, markedVersions ) );
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index 0927ba8..190bbff 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -32,6 +32,7 @@ import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Action0;
 import rx.functions.Func1;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -47,29 +48,23 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     private final EdgeMetadataSerialization edgeMetadataSerialization;
     private final EdgeDeleteRepair edgeDeleteRepair;
     private final EdgeMetaRepair edgeMetaRepair;
-    private final GraphFig graphFig;
-
-    private final Scheduler scheduler;
 
 
     /**
      * Wire the serialization dependencies
      */
     @Inject
-    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,
-                               final Scheduler scheduler, @NodeDelete final AsyncProcessor nodeDelete,
+    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization, @NodeDelete final AsyncProcessor nodeDelete,
                                final EdgeMetadataSerialization edgeMetadataSerialization,
-                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair,
-                               final GraphFig graphFig ) {
+                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair
+                                ) {
 
 
         this.nodeSerialization = nodeSerialization;
         this.edgeSerialization = edgeSerialization;
-        this.scheduler = scheduler;
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeDeleteRepair = edgeDeleteRepair;
         this.edgeMetaRepair = edgeMetaRepair;
-        this.graphFig = graphFig;
 
         nodeDelete.addListener( this );
     }
@@ -88,7 +83,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
         final UUID version = edgeEvent.getVersion();
 
 
-        return Observable.from( node ).subscribeOn( scheduler ).map( new Func1<Id, Optional<UUID>>() {
+        return Observable.from( node ).subscribeOn( Schedulers.io() ).map( new Func1<Id, Optional<UUID>>() {
             @Override
             public Optional<UUID> call( final Id id ) {
                 return nodeSerialization.getMaxVersion( scope, node );
@@ -215,7 +210,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 
@@ -229,7 +224,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 
@@ -243,7 +238,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 
@@ -257,7 +252,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index fb31a33..3ff7178 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -44,6 +44,7 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Func1;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -59,16 +60,14 @@ public abstract class AbstractEdgeRepair  {
     protected final EdgeSerialization edgeSerialization;
     protected final GraphFig graphFig;
     protected final Keyspace keyspace;
-    protected final Scheduler scheduler;
 
 
     @Inject
     public AbstractEdgeRepair( final EdgeSerialization edgeSerialization, final GraphFig graphFig,
-                               final Keyspace keyspace, final Scheduler scheduler ) {
+                               final Keyspace keyspace) {
         this.edgeSerialization = edgeSerialization;
         this.graphFig = graphFig;
         this.keyspace = keyspace;
-        this.scheduler = scheduler;
     }
 
 
@@ -106,7 +105,7 @@ public abstract class AbstractEdgeRepair  {
                                      throw new RuntimeException( "Unable to issue write to cassandra", e );
                                  }
 
-                                 return Observable.from( markedEdges ).subscribeOn( scheduler );
+                                 return Observable.from( markedEdges ).subscribeOn( Schedulers.io() );
                              }
              } );
     }
@@ -133,7 +132,7 @@ public abstract class AbstractEdgeRepair  {
 
                 return edgeSerialization.getEdgeFromSource( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 
@@ -150,7 +149,7 @@ public abstract class AbstractEdgeRepair  {
 
                 return edgeSerialization.getEdgeToTarget( scope, search );
             }
-        } ).subscribeOn( scheduler );
+        } ).subscribeOn( Schedulers.io() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairImpl.java
index bf5d3d2..e900a1d 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairImpl.java
@@ -47,8 +47,8 @@ public class EdgeDeleteRepairImpl extends AbstractEdgeRepair implements EdgeDele
 
     @Inject
     public EdgeDeleteRepairImpl( final EdgeSerialization edgeSerialization, final GraphFig graphFig,
-                                 final Keyspace keyspace, final Scheduler scheduler ) {
-        super( edgeSerialization, graphFig, keyspace, scheduler );
+                                 final Keyspace keyspace) {
+        super( edgeSerialization, graphFig, keyspace );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
index 0bbc91a..8b81d0a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
@@ -51,6 +51,7 @@ import rx.Scheduler;
 import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.observables.MathObservable;
+import rx.schedulers.Schedulers;
 
 
 /**
@@ -65,18 +66,16 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
     private final EdgeSerialization edgeSerialization;
     private final Keyspace keyspace;
     private final GraphFig graphFig;
-    private final Scheduler scheduler;
 
 
     @Inject
     public EdgeMetaRepairImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
                                final EdgeSerialization edgeSerialization, final Keyspace keyspace,
-                               final GraphFig graphFig, final Scheduler scheduler ) {
+                               final GraphFig graphFig ) {
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeSerialization = edgeSerialization;
         this.keyspace = keyspace;
         this.graphFig = graphFig;
-        this.scheduler = scheduler;
     }
 
 
@@ -257,7 +256,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                     return edgeMetadataSerialization
                             .getIdTypesToTarget( scope, new SimpleSearchIdType( nodeId, edgeType, null ) );
                 }
-            } ).subscribeOn( scheduler );
+            } ).subscribeOn( Schedulers.io() );
         }
 
 
@@ -270,7 +269,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                     return edgeSerialization.getEdgesToTargetBySourceType( scope,
                             new SimpleSearchByIdType( nodeId, edgeType, version, subType, null ) );
                 }
-            } ).subscribeOn( scheduler );
+            } ).subscribeOn( Schedulers.io() );
         }
 
 
@@ -302,7 +301,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                     return edgeMetadataSerialization
                             .getIdTypesFromSource( scope, new SimpleSearchIdType( nodeId, edgeType, null ) );
                 }
-            } ).subscribeOn( scheduler );
+            } ).subscribeOn( Schedulers.io() );
         }
 
 
@@ -315,7 +314,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                     return edgeSerialization.getEdgesFromSourceByTargetType( scope,
                             new SimpleSearchByIdType( nodeId, edgeType, version, subType, null ) );
                 }
-            } ).subscribeOn( scheduler );
+            } ).subscribeOn( Schedulers.io() );
         }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
index e8420a8..f77ef95 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
@@ -47,8 +47,8 @@ public class EdgeWriteRepairImpl extends AbstractEdgeRepair implements EdgeWrite
 
     @Inject
     public EdgeWriteRepairImpl( final EdgeSerialization edgeSerialization, final GraphFig graphFig,
-                                final Keyspace keyspace, final Scheduler scheduler ) {
-        super( edgeSerialization, graphFig, keyspace, scheduler );
+                                final Keyspace keyspace) {
+        super( edgeSerialization, graphFig, keyspace );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
index e4591cd..6ee4183 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
@@ -20,10 +20,13 @@
 package org.apache.usergrid.persistence.graph;
 
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.jukito.All;
 import org.jukito.JukitoRunner;
@@ -33,7 +36,8 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.safehaus.guicyfig.GuicyFig;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
@@ -41,14 +45,16 @@ import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
+import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
 import com.google.inject.Inject;
+import com.netflix.hystrix.exception.HystrixRuntimeException;
 
 import rx.Observable;
-import rx.functions.Action1;
+import rx.Subscriber;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
@@ -57,13 +63,14 @@ import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.crea
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 
-@RunWith(JukitoRunner.class)
-@UseModules({ TestGraphModule.class })
+@RunWith( JukitoRunner.class )
+@UseModules( { TestGraphModule.class } )
 //@UseModules( { TestGraphModule.class, EdgeManagerIT.InvalidInput.class } )
 public class EdgeManagerTimeoutIT {
 
@@ -101,50 +108,117 @@ public class EdgeManagerTimeoutIT {
 
         when( scope.getOrganization() ).thenReturn( orgId );
 
-        if(graphFig.getReadTimeout() > TIMEOUT){
-            fail("Graph read timeout must be <= " + TIMEOUT + ".  Otherwise tests are invalid");
+        if ( graphFig.getReadTimeout() > TIMEOUT ) {
+            fail( "Graph read timeout must be <= " + TIMEOUT + ".  Otherwise tests are invalid" );
         }
     }
 
 
-    @Test(timeout = TIMEOUT, expected = TimeoutException.class)
-    public void testWriteReadEdgeTypeSource() throws InterruptedException {
+    //    @Test(timeout = TIMEOUT, expected = TimeoutException.class)
+    @Test
+    public void testWriteReadEdgeTypeSource( EdgeSerialization serialization ) throws InterruptedException {
 
-        EdgeManager em = emf.createEdgeManager( scope );
 
+        final EdgeManager em = emf.createEdgeManager( scope );
 
-        Edge edge = createEdge( "source", "test", "target" );
 
-        em.writeEdge( edge ).toBlockingObservable().last();
+        final MarkedEdge edge = createEdge( "source", "edge", "target" );
 
         //now test retrieving it
 
         SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
 
+
+        final MockingIterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
+
+
+        when( serialization.getEdgesFromSource( scope, search ) ).thenReturn( itr );
+
         Observable<Edge> edges = em.loadEdgesFromSource( search );
 
         //retrieve the edge, ensure that if we block indefinitely, it times out
 
-        final Semaphore blocker = new Semaphore(0);
+        final AtomicInteger onNextCounter = new AtomicInteger();
+        final CountDownLatch errorLatch = new CountDownLatch( 1 );
+
+        final Throwable[] thrown = new Throwable[1];
 
-        edges.subscribe( new Action1<Edge>() {
+
+
+        edges.subscribe( new Subscriber<Edge>() {
             @Override
-            public void call( final Edge edge ) {
-                //block indefinitely, we want to ensure we timeout
-                try {
-                    blocker.acquire();
-                }
-                catch ( InterruptedException e ) {
-                    throw new RuntimeException(e);
+            public void onCompleted() {
+
+            }
+
+
+            @Override
+            public void onError( final Throwable e ) {
+                thrown[0] = e;
+                errorLatch.countDown();
+            }
+
+
+            @Override
+            public void onNext( final Edge edge ) {
+                {
+                    onNextCounter.incrementAndGet();
                 }
             }
         } );
 
-        blocker.acquire();
+
+        errorLatch.await();
+
+
+        assertEquals( "One lement was produced", 1,onNextCounter.intValue() );
+        assertTrue(thrown[0] instanceof HystrixRuntimeException);
 
     }
 
 
+    private class MockingIterator<T> implements Iterator<T> {
+
+        private final Iterator<T> items;
+
+        private final Semaphore semaphore = new Semaphore( 0 );
+
+
+        private MockingIterator( final Collection<T> items ) {
+            this.items = items.iterator();
+        }
+
+
+        @Override
+        public boolean hasNext() {
+            return true;
+        }
+
+
+        @Override
+        public T next() {
+            if ( items.hasNext() ) {
+                return items.next();
+            }
+
+            //block indefinitely
+            try {
+                semaphore.acquire();
+            }
+            catch ( InterruptedException e ) {
+                throw new RuntimeException( e );
+            }
+
+            return null;
+        }
+
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException( "Cannot remove" );
+        }
+    }
+
 
     @Test
     public void testWriteReadEdgeTypeTarget() {
@@ -1336,8 +1410,6 @@ public class EdgeManagerTimeoutIT {
     }
 
 
-
-
     @Test
     public void markTargetNode() {
 
@@ -1420,8 +1492,7 @@ public class EdgeManagerTimeoutIT {
     }
 
 
-
-    @Test(expected = NullPointerException.class)
+    @Test( expected = NullPointerException.class )
     public void invalidEdgeTypesWrite( @All Edge edge ) {
         final EdgeManager em = emf.createEdgeManager( scope );
 
@@ -1429,7 +1500,7 @@ public class EdgeManagerTimeoutIT {
     }
 
 
-    @Test(expected = NullPointerException.class)
+    @Test( expected = NullPointerException.class )
     public void invalidEdgeTypesDelete( @All Edge edge ) {
         final EdgeManager em = emf.createEdgeManager( scope );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
index 3652757..eaade41 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
@@ -280,7 +280,7 @@ public class AsyncProcessorTest {
 
         when(fig.getScanPageSize()).thenReturn( 0 );
 
-        AsyncProcessorImpl<T> processor = new AsyncProcessorImpl( queue, Schedulers.io(), fig );
+        AsyncProcessorImpl<T> processor = new AsyncProcessorImpl( queue,  fig );
 
 
         return processor;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/457528f5/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
index e9f05e0..68a67d2 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
@@ -23,6 +23,7 @@ package org.apache.usergrid.persistence.graph.test.util;
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.SearchByIdType;
@@ -53,7 +54,7 @@ public class EdgeTestUtils {
      *
      * @return an Edge for testing
      */
-    public static Edge createEdge( final String sourceType, final String edgeType, final String targetType ) {
+    public static MarkedEdge createEdge( final String sourceType, final String edgeType, final String targetType ) {
         return createEdge( createId( sourceType ), edgeType, createId( targetType ), UUIDGenerator.newTimeUUID() );
     }
 
@@ -61,7 +62,7 @@ public class EdgeTestUtils {
     /**
      * Create an edge for testing
      */
-    public static Edge createEdge( final Id sourceId, final String edgeType, final Id targetId ) {
+    public static MarkedEdge createEdge( final Id sourceId, final String edgeType, final Id targetId ) {
         return createEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID() );
     }
 
@@ -69,12 +70,22 @@ public class EdgeTestUtils {
     /**
      * Create an edge with the specified params
      */
-    public static Edge createEdge( final Id sourceId, final String edgeType, final Id targetId, final UUID version ) {
+    public static MarkedEdge createEdge( final Id sourceId, final String edgeType, final Id targetId,
+                                         final UUID version ) {
         return new SimpleMarkedEdge( sourceId, edgeType, targetId, version, false );
     }
 
 
     /**
+     * Create an edge with the specified params
+     */
+    public static MarkedEdge createEdge( final String sourceType, final String edgeType, final String targetType,
+                                         final UUID version ) {
+        return new SimpleMarkedEdge( createId( sourceType ), edgeType, createId( targetType ), version, false );
+    }
+
+
+    /**
      * Create the id
      */
     public static Id createId( String type ) {


[05/27] git commit: Merge remote-tracking branch 'origin/two-dot-o' into hystrix-integration

Posted by sn...@apache.org.
Merge remote-tracking branch 'origin/two-dot-o' into hystrix-integration


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

Branch: refs/heads/entity-manager
Commit: 58f7f43642826c06f7aace698c6088a35186a6a0
Parents: 457528f 9d6ed41
Author: Todd Nine <tn...@apigee.com>
Authored: Fri Mar 21 10:15:31 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Fri Mar 21 10:15:31 2014 -0700

----------------------------------------------------------------------
 .gitignore                                      |   6 +
 stack/awscluster/README.md                      |  31 +-
 stack/corepersistence/perftest1/pom.xml         |  76 +++++
 .../usergrid/persistence/UsergridBootstrap.java | 303 ++++++++++++++++++
 .../src/main/resources/log4j.properties         |  44 +++
 .../src/main/resources/project.properties       |   1 +
 .../main/resources/usergrid-test-context.xml    |  39 +++
 .../persistence/Usergrid1PerformanceTest.java   | 302 ++++++++++++++++++
 .../persistence/UsergridBootstrapTest.java      |  56 ++++
 stack/corepersistence/perftest2/pom.xml         |  64 ++++
 .../main/groovy/perftest2/CreateEntity.groovy   | 100 ++++++
 .../persistence/CorePerformanceTest.java        | 318 +++++++++++++++++++
 .../index/guice/TestIndexModule.java            |  30 ++
 .../index/impl/EsEntityCollectionIndex.java     |  13 +-
 .../index/impl/CorePerformanceIT.java           | 304 ++++++++++++++++++
 stack/pom.xml                                   |   3 +
 16 files changed, 1666 insertions(+), 24 deletions(-)
----------------------------------------------------------------------



[18/27] Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
deleted file mode 100644
index 518e39f..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class FloatLiteral extends Literal<Float> implements NumericLiteral {
-
-    private float value;
-
-
-    /**
-     * @param t
-     */
-    public FloatLiteral( Token t ) {
-        super( t );
-        value = Float.valueOf( t.getText() );
-    }
-
-
-    public FloatLiteral( float f ) {
-        super( new ClassicToken( 0, String.valueOf( f ) ) );
-        value = f;
-    }
-
-
-    /** @return the value */
-    public Float getValue() {
-        return value;
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
-     */
-    @Override
-    public float getFloatValue() {
-        return value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
deleted file mode 100644
index 966fbb2..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class GreaterThan extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public GreaterThan( Token t ) {
-        super( t );
-    }
-
-
-    public GreaterThan() {
-        super( new CommonToken( 0, ">" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws NoIndexException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
deleted file mode 100644
index d561010..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class GreaterThanEqual extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public GreaterThanEqual( Token t ) {
-        super( t );
-    }
-
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public GreaterThanEqual() {
-        super( new CommonToken( 0, ">=" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws NoIndexException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
deleted file mode 100644
index 008abf5..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class LessThan extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public LessThan( Token t ) {
-        super( t );
-    }
-
-
-    public LessThan() {
-        super( new CommonToken( 0, "<" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws NoIndexException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
deleted file mode 100644
index 1ea5d81..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class LessThanEqual extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public LessThanEqual( Token t ) {
-        super( t );
-    }
-
-
-    /**
-     */
-    public LessThanEqual() {
-        super( new CommonToken( 0, "<=" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws NoIndexException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
deleted file mode 100644
index acd9ac4..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.antlr.runtime.tree.CommonTree;
-
-
-/**
- * Abstract class for literals
- *
- * @author tnine
- */
-public abstract class Literal<V> extends CommonTree {
-
-
-    protected Literal( Token t ) {
-        super( t );
-    }
-
-
-    /** Return the value of the literal the user has passed in */
-    public abstract V getValue();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
deleted file mode 100644
index 2895797..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import java.util.UUID;
-
-
-/**
- * Simple factory for generating literal instance based on the runtime value
- *
- * @author tnine
- */
-public class LiteralFactory {
-
-    /** Generate the correct literal subclass based on the runtime instance. */
-    public static final Literal<?> getLiteral( Object value ) {
-        if ( value instanceof Integer ) {
-            return new LongLiteral( ( Integer ) value );
-        }
-        if ( value instanceof Long ) {
-            return new LongLiteral( ( Long ) value );
-        }
-
-        if ( value instanceof String ) {
-            return new StringLiteral( ( String ) value );
-        }
-
-        if ( value instanceof Float ) {
-            return new FloatLiteral( ( Float ) value );
-        }
-
-        if ( value instanceof UUID ) {
-            return new UUIDLiteral( ( UUID ) value );
-        }
-
-        if ( value instanceof Boolean ) {
-            return new BooleanLiteral( ( Boolean ) value );
-        }
-
-        throw new UnsupportedOperationException(
-                String.format( "Unsupported type of %s was passed when trying to construct a literal",
-                        value.getClass() ) );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
deleted file mode 100644
index 609e11c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class LongLiteral extends Literal<Long> implements NumericLiteral {
-
-    private long value;
-
-
-    /**
-     * @param t
-     */
-    public LongLiteral( Token t ) {
-        super( t );
-        this.value = Long.valueOf( t.getText() );
-    }
-
-
-    /**
-     *
-     * @param value
-     */
-    public LongLiteral( long value ) {
-        super( new ClassicToken( 0, String.valueOf( value ) ) );
-        this.value = value;
-    }
-
-
-    /**
-     *
-     * @return
-     */
-    public Long getValue() {
-        return this.value;
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
-     */
-    @Override
-    public float getFloatValue() {
-        return value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
deleted file mode 100644
index 8388e5d..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class NotOperand extends Operand {
-
-
-    public NotOperand( Token t ) {
-        super( t );
-    }
-
-
-    /** get the only child operation */
-    public Operand getOperation() {
-        return ( Operand ) this.children.get( 0 );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence.query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws PersistenceException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
deleted file mode 100644
index 9ec5b0c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-/** @author tnine */
-public interface NumericLiteral {
-
-    /** Return the value of this numeric literal as a float */
-    public float getFloatValue();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
deleted file mode 100644
index d3f5791..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.antlr.runtime.tree.CommonTree;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/**
- * Any logical operation should subclass.  Boolean logic, equality, not, contains, within and others are examples of
- * operands
- *
- * @author tnine
- */
-public abstract class Operand extends CommonTree {
-
-
-    /** Default constructor to take a token */
-    public Operand( Token t ) {
-        super( t );
-    }
-
-
-    /** Get the pointer to the parent node */
-    public Operand getParent() {
-        return ( Operand ) super.getParent();
-    }
-
-
-    /** Visitor method */
-    public abstract void visit( QueryVisitor visitor ) throws PersistenceException;
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
deleted file mode 100644
index 279c0f1..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class OrOperand extends BooleanOperand {
-
-    /**
-     * @param left
-     * @param token
-     * @param right
-     */
-    public OrOperand( Token t ) {
-        super( t );
-    }
-
-
-    public OrOperand() {
-        super( new CommonToken( 0, "or" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws PersistenceException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
deleted file mode 100644
index dee3d91..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/**
- * A property
- *
- * @author tnine
- */
-public class Property extends Literal<String> {
-
-    private String property;
-
-
-    public Property( Token t ) {
-        super( t );
-        this.property = t.getText();
-    }
-
-
-    public Property( String property ) {
-        this( new ClassicToken( 0, property ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.usergrid.persistence.query.tree.Literal#getValue()
-     */
-    @Override
-    public String getValue() {
-        return this.property;
-    }
-
-
-    /**
-     * Subclasses an override.  Indexed value could be different when stored internally.  By default returns the same
-     * property
-     */
-    public String getIndexedValue() {
-        return this.property;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
deleted file mode 100644
index 888f1cf..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.apache.usergrid.persistence.exceptions.NoFullTextIndexException;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-
-
-/**
- * Interface for visiting nodes in our AST as we produce
- *
- * @author tnine
- */
-public interface QueryVisitor {
-
-    /**
-     *
-     * @param op
-     * @throws PersistenceException
-     */
-    public void visit( AndOperand op ) throws PersistenceException;
-
-    /**
-     * @param op
-     * @throws PersistenceException
-     */
-    public void visit( OrOperand op ) throws PersistenceException;
-
-    /**
-     * @param op
-     * @throws PersistenceException
-     */
-    public void visit( NotOperand op ) throws PersistenceException;
-
-    /**
-     * @param op
-     * @throws NoIndexException
-     */
-    public void visit( LessThan op ) throws NoIndexException;
-
-    /**
-     * @param op
-     * @throws NoFullTextIndexException
-     */
-    public void visit( ContainsOperand op ) throws NoFullTextIndexException;
-
-    /**
-     * @param op
-     */
-    public void visit( WithinOperand op );
-
-    /**
-     * @param op
-     * @throws NoIndexException
-     */
-    public void visit( LessThanEqual op ) throws NoIndexException;
-
-    /**
-     * @param op
-     * @throws NoIndexException
-     */
-    public void visit( Equal op ) throws NoIndexException;
-
-    /**
-     * @param op
-     * @throws NoIndexException
-     */
-    public void visit( GreaterThan op ) throws NoIndexException;
-
-    /**
-     * @param op
-     * @throws NoIndexException
-     */
-    public void visit( GreaterThanEqual op ) throws NoIndexException;
-
-    /** 
-     * Returns resulting query builder.
-     */
-    public QueryBuilder getQueryBuilder();
-
-	public FilterBuilder getFilterBuilder();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
deleted file mode 100644
index 982cb8a..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-import static org.apache.commons.lang.StringUtils.removeEnd;
-
-
-/** @author tnine */
-public class StringLiteral extends Literal<String> {
-
-    private String value;
-    private String finishValue;
-
-
-    /**
-     * @param t
-     */
-    public StringLiteral( Token t ) {
-        super( t );
-        String newValue = t.getText();
-        newValue = newValue.substring( 1, newValue.length() - 1 );
-
-        parseValue( newValue );
-    }
-
-
-    public StringLiteral( String value ) {
-        super( new ClassicToken( 0, value ) );
-        parseValue( value );
-    }
-
-
-    /** Parse the value and set the optional end value */
-    private void parseValue( String value ) {
-
-        this.value = value.trim().toLowerCase();
-
-        if ( "*".equals( value ) ) {
-            this.value = null;
-            this.finishValue = null;
-            return;
-        }
-
-        if ( value != null && value.endsWith( "*" ) ) {
-            this.value = removeEnd( value.toString(), "*" );
-
-            finishValue = this.value + "\uFFFF";
-        }
-        // set the end value to the same as the start value
-        else {
-            finishValue = value;
-        }
-    }
-
-
-    /** If this were a string literal */
-    public String getEndValue() {
-        return this.finishValue;
-    }
-
-
-    public String getValue() {
-        return this.value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
deleted file mode 100644
index 1b60540..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import java.util.UUID;
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class UUIDLiteral extends Literal<UUID> {
-
-    private UUID value;
-
-
-    /**
-     * @param t
-     */
-    public UUIDLiteral( Token t ) {
-        super( t );
-        value = UUID.fromString( t.getText() );
-    }
-
-
-    public UUIDLiteral( UUID value ) {
-        super( new ClassicToken( 0, String.valueOf( value ) ) );
-        this.value = value;
-    }
-
-
-    public UUID getValue() {
-        return this.value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
deleted file mode 100644
index debf07c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class WithinOperand extends Operand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public WithinOperand( Token t ) {
-        super( t );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) {
-        visitor.visit( this );
-    }
-
-
-    /**
-     * @param propName
-     */
-    public void setProperty( String propName ) {
-        setChild( 0, new WithinProperty( propName ) );
-    }
-
-
-    /**
-     * @param distance
-     */
-    public void setDistance( float distance ) {
-        setChild( 1, new FloatLiteral( distance ) );
-    }
-
-
-    /**
-     * @param Latitude
-     */
-    public void setLatitude( float Latitude ) {
-        setChild( 2, new FloatLiteral( Latitude ) );
-    }
-
-
-    /**
-     * @param longitude
-     */
-    public void setLongitude( float longitude ) {
-        setChild( 3, new FloatLiteral( longitude ) );
-    }
-
-
-    /**
-     *
-     * @return
-     */
-    public WithinProperty getProperty() {
-        return ( WithinProperty ) this.children.get( 0 );
-    }
-
-
-    /**
-     *
-     * @return
-     */
-    public NumericLiteral getDistance() {
-        return ( NumericLiteral ) this.children.get( 1 );
-    }
-
-
-    /**
-     * @return
-     */
-    public NumericLiteral getLatitude() {
-        return ( NumericLiteral ) this.children.get( 2 );
-    }
-
-
-    /**
-     * @return
-     */
-    public NumericLiteral getLongitude() {
-        return ( NumericLiteral ) this.children.get( 3 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
deleted file mode 100644
index 2707e77..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/**
- * A property
- *
- * @author tnine
- */
-public class WithinProperty extends Property {
-
-    private String indexedName = null;
-
-
-    public WithinProperty( Token t ) {
-        super( t );
-        this.indexedName = String.format( "%s.coordinates", super.getValue() );
-    }
-
-
-    public WithinProperty( String property ) {
-        this( new ClassicToken( 0, property ) );
-    }
-
-
-    /** Get the */
-    public String getIndexedName() {
-        return this.indexedName;
-    }
-
-
-    /** @return the property */
-    public WithinProperty getProperty() {
-        return ( WithinProperty ) this.children.get( 0 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java
deleted file mode 100644
index 6ce847e..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-
-public class ClassUtils extends org.apache.commons.lang.ClassUtils {
-
-    @SuppressWarnings("unchecked")
-    public static <A, B> B cast( A a ) {
-        return ( B ) a;
-    }
-
-
-    @SuppressWarnings("unchecked")
-    private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>(
-            Arrays.asList( Boolean.class, Byte.class, Character.class, Double.class, Float.class, Integer.class,
-                    Long.class, Short.class, Void.class ) );
-
-
-    public static boolean isWrapperType( Class<?> clazz ) {
-        return WRAPPER_TYPES.contains( clazz );
-    }
-
-
-    public static boolean isPrimitiveType( Class<?> clazz ) {
-        if ( clazz == null ) {
-            return false;
-        }
-        return clazz.isPrimitive() || isWrapperType( clazz );
-    }
-
-
-    public static boolean isBasicType( Class<?> clazz ) {
-        if ( clazz == null ) {
-            return false;
-        }
-        return ( String.class.isAssignableFrom( clazz ) ) || isPrimitiveType( clazz );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
deleted file mode 100644
index 567a713..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
+++ /dev/null
@@ -1,765 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang.math.NumberUtils;
-
-
-/** Convenience methods for converting to and from formats, primarily between byte arrays and UUIDs, Strings,
- * and Longs. */
-public class ConversionUtils {
-
-    private static final Logger logger = LoggerFactory.getLogger( ConversionUtils.class );
-
-    /**
-     *
-     */
-    public static final String UTF8_ENCODING = "UTF-8";
-
-    /**
-     *
-     */
-    public static final String ASCII_ENCODING = "US-ASCII";
-
-    public static final ByteBuffer HOLDER = ByteBuffer.wrap( new byte[] { 0 } );
-
-
-    /**
-     * @param uuid
-     * @return
-     */
-    public static UUID uuid( byte[] uuid ) {
-        return uuid( uuid, 0 );
-    }
-
-
-    /**
-     * @param uuid
-     * @param offset
-     * @return
-     */
-    public static UUID uuid( byte[] uuid, int offset ) {
-        ByteBuffer bb = ByteBuffer.wrap( uuid, offset, 16 );
-        return new UUID( bb.getLong(), bb.getLong() );
-    }
-
-
-    public static UUID uuid( ByteBuffer bb ) {
-        if ( bb == null ) {
-            return null;
-        }
-        if ( bb.remaining() < 16 ) {
-            return null;
-        }
-        bb = bb.slice();
-        return new UUID( bb.getLong(), bb.getLong() );
-    }
-
-
-    /**
-     * @param uuid
-     * @return
-     */
-    public static UUID uuid( String uuid ) {
-        try {
-            return UUID.fromString( uuid );
-        }
-        catch ( Exception e ) {
-            logger.error( "Bad UUID", e );
-        }
-        return UUIDUtils.ZERO_UUID;
-    }
-
-
-    /**
-     * @param obj
-     * @return
-     */
-    public static UUID uuid( Object obj ) {
-        return uuid( obj, UUIDUtils.ZERO_UUID );
-    }
-
-
-    public static UUID uuid( Object obj, UUID defaultValue ) {
-        if ( obj instanceof UUID ) {
-            return ( UUID ) obj;
-        }
-        else if ( obj instanceof byte[] ) {
-            return uuid( ( byte[] ) obj );
-        }
-        else if ( obj instanceof ByteBuffer ) {
-            return uuid( ( ByteBuffer ) obj );
-        }
-        else if ( obj instanceof String ) {
-            return uuid( ( String ) obj );
-        }
-        return defaultValue;
-    }
-
-
-    /**
-     * @param uuid
-     * @return
-     */
-    public static byte[] bytes( UUID uuid ) {
-        if ( uuid == null ) {
-            return null;
-        }
-        long msb = uuid.getMostSignificantBits();
-        long lsb = uuid.getLeastSignificantBits();
-        byte[] buffer = new byte[16];
-
-        for ( int i = 0; i < 8; i++ ) {
-            buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) );
-        }
-        for ( int i = 8; i < 16; i++ ) {
-            buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) );
-        }
-
-        return buffer;
-    }
-
-
-    public static ByteBuffer bytebuffer( UUID uuid ) {
-        if ( uuid == null ) {
-            return null;
-        }
-        return ByteBuffer.wrap( bytes( uuid ) );
-    }
-
-
-    /**
-     * @param uuid
-     * @return
-     */
-    public static byte[] uuidToBytesNullOk( UUID uuid ) {
-        if ( uuid != null ) {
-            return bytes( uuid );
-        }
-        return new byte[16];
-    }
-
-
-    /**
-     * @param s
-     * @return
-     */
-    public static byte[] bytes( String s ) {
-        return bytes( s, UTF8_ENCODING );
-    }
-
-
-    public static ByteBuffer bytebuffer( String s ) {
-        return ByteBuffer.wrap( bytes( s ) );
-    }
-
-
-    /**
-     * @param s
-     * @return
-     */
-    public static byte[] ascii( String s ) {
-        if ( s == null ) {
-            return new byte[0];
-        }
-        return bytes( s, ASCII_ENCODING );
-    }
-
-
-    public ByteBuffer asciibuffer( String s ) {
-        return ByteBuffer.wrap( ascii( s ) );
-    }
-
-
-    /**
-     * @param s
-     * @param encoding
-     * @return
-     */
-    public static byte[] bytes( String s, String encoding ) {
-        try {
-            return s.getBytes( encoding );
-        }
-        catch ( UnsupportedEncodingException e ) {
-            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
-            throw new RuntimeException( e );
-        }
-    }
-
-
-    public static byte[] bytes( ByteBuffer bb ) {
-        byte[] b = new byte[bb.remaining()];
-        bb.duplicate().get( b );
-        return b;
-    }
-
-
-    public static ByteBuffer bytebuffer( String s, String encoding ) {
-        return ByteBuffer.wrap( bytes( s, encoding ) );
-    }
-
-
-    /**
-     * @param b
-     * @return
-     */
-    public static byte[] bytes( Boolean b ) {
-        byte[] bytes = new byte[1];
-        bytes[0] = b ? ( byte ) 1 : 0;
-        return bytes;
-    }
-
-
-    public static ByteBuffer bytebuffer( Boolean b ) {
-        return ByteBuffer.wrap( bytes( b ) );
-    }
-
-
-    /**
-     * @param val
-     * @return
-     */
-    public static byte[] bytes( Long val ) {
-        ByteBuffer buf = ByteBuffer.allocate( 8 );
-        buf.order( ByteOrder.BIG_ENDIAN );
-        buf.putLong( val );
-        return buf.array();
-    }
-
-
-    public static ByteBuffer bytebuffer( Long val ) {
-        ByteBuffer buf = ByteBuffer.allocate( 8 );
-        buf.order( ByteOrder.BIG_ENDIAN );
-        buf.putLong( val );
-        return ( ByteBuffer ) buf.rewind();
-    }
-
-
-    /**
-     * @param obj
-     * @return
-     */
-    public static byte[] bytes( Object obj ) {
-        if ( obj == null ) {
-            return new byte[0];
-        }
-        else if ( obj instanceof byte[] ) {
-            return ( byte[] ) obj;
-        }
-        else if ( obj instanceof Long ) {
-            return bytes( ( Long ) obj );
-        }
-        else if ( obj instanceof String ) {
-            return bytes( ( String ) obj );
-        }
-        else if ( obj instanceof UUID ) {
-            return bytes( ( UUID ) obj );
-        }
-        else if ( obj instanceof Boolean ) {
-            return bytes( ( Boolean ) obj );
-        }
-        else if ( obj instanceof Date ) {
-            return bytes( ( ( Date ) obj ).getTime() );
-        }
-        else {
-            return bytes( obj.toString() );
-        }
-    }
-
-
-    public static ByteBuffer bytebuffer( byte[] bytes ) {
-        return ByteBuffer.wrap( bytes );
-    }
-
-
-    public static ByteBuffer bytebuffer( ByteBuffer bytes ) {
-        return bytes.duplicate();
-    }
-
-
-    public static ByteBuffer bytebuffer( Object obj ) {
-        if ( obj instanceof ByteBuffer ) {
-            return ( ( ByteBuffer ) obj ).duplicate();
-        }
-        return ByteBuffer.wrap( bytes( obj ) );
-    }
-
-
-    public static List<ByteBuffer> bytebuffers( List<?> l ) {
-        List<ByteBuffer> results = new ArrayList<ByteBuffer>( l.size() );
-        for ( Object o : l ) {
-            results.add( bytebuffer( o ) );
-        }
-        return results;
-    }
-
-
-    /**
-     * @param bytes
-     * @return
-     */
-    public static boolean getBoolean( byte[] bytes ) {
-        return bytes[0] != 0;
-    }
-
-
-    public static boolean getBoolean( ByteBuffer bytes ) {
-        return bytes.slice().get() != 0;
-    }
-
-
-    /**
-     * @param bytes
-     * @param offset
-     * @return
-     */
-    public static boolean getBoolean( byte[] bytes, int offset ) {
-        return bytes[offset] != 0;
-    }
-
-
-    public static boolean getBoolean( Object obj ) {
-        if ( obj instanceof Boolean ) {
-            return ( Boolean ) obj;
-        }
-        else if ( obj instanceof String ) {
-            return Boolean.parseBoolean( ( String ) obj );
-        }
-        else if ( obj instanceof Number ) {
-            return ( ( Number ) obj ).longValue() > 0;
-        }
-
-        return false;
-    }
-
-
-    /**
-     * @param obj
-     * @return
-     */
-    public static String string( Object obj ) {
-        if ( obj instanceof String ) {
-            return ( String ) obj;
-        }
-        else if ( obj instanceof byte[] ) {
-            return string( ( byte[] ) obj );
-        }
-        else if ( obj instanceof ByteBuffer ) {
-            return string( ( ByteBuffer ) obj );
-        }
-        else if ( obj != null ) {
-            return obj.toString();
-        }
-        return null;
-    }
-
-
-    /**
-     * @param bytes
-     * @return
-     */
-    public static String string( byte[] bytes ) {
-        if ( bytes == null ) {
-            return null;
-        }
-        return string( bytes, 0, bytes.length, UTF8_ENCODING );
-    }
-
-
-    public static String string( ByteBuffer bytes ) {
-        if ( bytes == null ) {
-            return null;
-        }
-        return string( bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF8_ENCODING );
-    }
-
-
-    /**
-     * @param bytes
-     * @param offset
-     * @param length
-     * @return
-     */
-    public static String string( byte[] bytes, int offset, int length ) {
-        return string( bytes, offset, length, UTF8_ENCODING );
-    }
-
-
-    /**
-     * @param bytes
-     * @param offset
-     * @param length
-     * @param encoding
-     * @return
-     */
-    public static String string( byte[] bytes, int offset, int length, String encoding ) {
-
-        if ( length <= 0 ) {
-            return "";
-        }
-
-        if ( bytes == null ) {
-            return "";
-        }
-
-        try {
-            return new String( bytes, offset, length, encoding );
-        }
-        catch ( UnsupportedEncodingException e ) {
-            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
-            throw new RuntimeException( e );
-        }
-    }
-
-
-    public static <T> List<String> strings( Collection<T> items ) {
-        List<String> strings = new ArrayList<String>();
-        for ( T item : items ) {
-            strings.add( string( item ) );
-        }
-        return strings;
-    }
-
-
-    /**
-     * @param bytes
-     * @param offset
-     * @return
-     */
-    public static String stringFromLong( byte[] bytes, int offset ) {
-        if ( bytes.length == 0 ) {
-            return "";
-        }
-        if ( ( bytes.length - offset ) < 8 ) {
-            throw new IllegalArgumentException( "A long is at least 8 bytes" );
-        }
-        return String.valueOf( ByteBuffer.wrap( bytes, offset, 8 ).getLong() );
-    }
-
-
-    /**
-     * @param bytes
-     * @return
-     */
-    public static long getLong( byte[] bytes ) {
-        return ByteBuffer.wrap( bytes, 0, 8 ).getLong();
-    }
-
-
-    public static long getLong( ByteBuffer bytes ) {
-        return bytes.slice().getLong();
-    }
-
-
-    public static long getLong( Object obj ) {
-        if ( obj instanceof Long ) {
-            return ( Long ) obj;
-        }
-        if ( obj instanceof Number ) {
-            return ( ( Number ) obj ).longValue();
-        }
-        if ( obj instanceof String ) {
-            return NumberUtils.toLong( ( String ) obj );
-        }
-        if ( obj instanceof Date ) {
-            return ( ( Date ) obj ).getTime();
-        }
-        if ( obj instanceof byte[] ) {
-            return getLong( ( byte[] ) obj );
-        }
-        if ( obj instanceof ByteBuffer ) {
-            return getLong( ( ByteBuffer ) obj );
-        }
-        return 0;
-    }
-
-
-    /**
-     * @param bytes
-     * @return
-     */
-    public static int getInt( byte[] bytes ) {
-        return ByteBuffer.wrap( bytes, 0, 4 ).getInt();
-    }
-
-
-    public static int getInt( ByteBuffer bytes ) {
-        return bytes.slice().getInt();
-    }
-
-
-    public static int getInt( Object obj ) {
-        if ( obj instanceof Integer ) {
-            return ( Integer ) obj;
-        }
-        if ( obj instanceof Number ) {
-            return ( ( Number ) obj ).intValue();
-        }
-        if ( obj instanceof String ) {
-            return NumberUtils.toInt( ( String ) obj );
-        }
-        if ( obj instanceof Date ) {
-            return ( int ) ( ( Date ) obj ).getTime();
-        }
-        if ( obj instanceof byte[] ) {
-            return getInt( ( byte[] ) obj );
-        }
-        if ( obj instanceof ByteBuffer ) {
-            return getInt( ( ByteBuffer ) obj );
-        }
-        return 0;
-    }
-
-
-    /**
-     * @param bytes
-     * @return
-     */
-    public static float getFloat( byte[] bytes ) {
-        return ByteBuffer.wrap( bytes, 0, 4 ).getFloat();
-    }
-
-
-    public static float getFloat( ByteBuffer bytes ) {
-        return bytes.slice().getFloat();
-    }
-
-
-    public static float getFloat( Object obj ) {
-        if ( obj instanceof Float ) {
-            return ( Float ) obj;
-        }
-        if ( obj instanceof Number ) {
-            return ( ( Number ) obj ).floatValue();
-        }
-        if ( obj instanceof String ) {
-            return NumberUtils.toFloat( ( String ) obj );
-        }
-        if ( obj instanceof Date ) {
-            return ( ( Date ) obj ).getTime();
-        }
-        if ( obj instanceof byte[] ) {
-            return getFloat( ( byte[] ) obj );
-        }
-        if ( obj instanceof ByteBuffer ) {
-            return getFloat( ( ByteBuffer ) obj );
-        }
-        return 0;
-    }
-
-
-    public static double getDouble( byte[] bytes ) {
-        return ByteBuffer.wrap( bytes, 0, 8 ).getDouble();
-    }
-
-
-    public static double getDouble( ByteBuffer bytes ) {
-        return bytes.slice().getDouble();
-    }
-
-
-    public static double getDouble( Object obj ) {
-        if ( obj instanceof Double ) {
-            return ( Double ) obj;
-        }
-        if ( obj instanceof Number ) {
-            return ( ( Number ) obj ).doubleValue();
-        }
-        if ( obj instanceof String ) {
-            return NumberUtils.toDouble( ( String ) obj );
-        }
-        if ( obj instanceof Date ) {
-            return ( ( Date ) obj ).getTime();
-        }
-        if ( obj instanceof byte[] ) {
-            return getDouble( ( byte[] ) obj );
-        }
-        if ( obj instanceof ByteBuffer ) {
-            return getDouble( ( ByteBuffer ) obj );
-        }
-        return 0;
-    }
-
-
-    /**
-     * @param type
-     * @param bytes
-     * @return
-     */
-    public static Object object( Class<?> type, byte[] bytes ) {
-
-        try {
-            if ( Long.class.isAssignableFrom( type ) ) {
-                return getLong( bytes );
-            }
-            else if ( UUID.class.isAssignableFrom( type ) ) {
-                return uuid( bytes );
-            }
-            else if ( String.class.isAssignableFrom( type ) ) {
-                return string( bytes );
-            }
-            else if ( Boolean.class.isAssignableFrom( type ) ) {
-                return getBoolean( bytes );
-            }
-            else if ( Integer.class.isAssignableFrom( type ) ) {
-                return getInt( bytes );
-            }
-            else if ( Double.class.isAssignableFrom( type ) ) {
-                return getDouble( bytes );
-            }
-            else if ( Float.class.isAssignableFrom( type ) ) {
-                return getFloat( bytes );
-            }
-            else if ( byte[].class.isAssignableFrom( type ) ) {
-                return bytes;
-            }
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
-        }
-        return null;
-    }
-
-
-    public static Object object( Class<?> type, ByteBuffer bytes ) {
-
-        try {
-            if ( Long.class.isAssignableFrom( type ) ) {
-                return bytes.slice().getLong();
-            }
-            else if ( UUID.class.isAssignableFrom( type ) ) {
-                return uuid( bytes );
-            }
-            else if ( String.class.isAssignableFrom( type ) ) {
-                return string( bytes );
-            }
-            else if ( Boolean.class.isAssignableFrom( type ) ) {
-                return bytes.slice().get() != 0;
-            }
-            else if ( Integer.class.isAssignableFrom( type ) ) {
-                return bytes.slice().getInt();
-            }
-            else if ( Double.class.isAssignableFrom( type ) ) {
-                return bytes.slice().getDouble();
-            }
-            else if ( Float.class.isAssignableFrom( type ) ) {
-                return bytes.slice().getFloat();
-            }
-            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
-                return bytes.duplicate();
-            }
-            else if ( byte[].class.isAssignableFrom( type ) ) {
-                byte[] b = new byte[bytes.remaining()];
-                bytes.slice().get( b );
-                return b;
-            }
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
-        }
-        return null;
-    }
-
-
-    /**
-     * @param bb
-     * @param bytes
-     * @param len
-     * @return
-     */
-    public static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ) {
-        if ( len > bytes.length ) {
-            int pos = bb.position();
-            bb.put( bytes );
-            bb.position( pos + len );
-        }
-        else {
-            bb.put( bytes, 0, len );
-        }
-        return bb;
-    }
-
-
-    public static Object coerce( Class<?> type, Object obj ) {
-
-        if ( obj == null ) {
-            return null;
-        }
-
-        if ( type == null ) {
-            return obj;
-        }
-
-        try {
-            if ( Long.class.isAssignableFrom( type ) ) {
-                return getLong( obj );
-            }
-            else if ( UUID.class.isAssignableFrom( type ) ) {
-                return uuid( obj );
-            }
-            else if ( String.class.isAssignableFrom( type ) ) {
-                return string( obj );
-            }
-            else if ( Boolean.class.isAssignableFrom( type ) ) {
-                return getBoolean( obj );
-            }
-            else if ( Integer.class.isAssignableFrom( type ) ) {
-                return getInt( obj );
-            }
-            else if ( Double.class.isAssignableFrom( type ) ) {
-                return getDouble( obj );
-            }
-            else if ( Float.class.isAssignableFrom( type ) ) {
-                return getFloat( obj );
-            }
-            else if ( byte[].class.isAssignableFrom( type ) ) {
-                return bytes( obj );
-            }
-            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
-                return bytebuffer( obj );
-            }
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
-        }
-        return null;
-    }
-
-
-    public static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ) {
-        for ( Map.Entry<String, Object> entry : values.entrySet() ) {
-            if ( types.containsKey( entry.getKey() ) ) {
-                values.put( entry.getKey(), coerce( types.get( entry.getKey() ), entry.getValue() ) );
-            }
-        }
-        return values;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
deleted file mode 100644
index c9e1c84..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-
-package org.apache.usergrid.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.field.BooleanField;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.FloatField;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.value.Location;
-
-
-public class EntityBuilder {
-
-    public static Entity fromMap( String scope, Map<String, Object> item ) {
-        return fromMap( scope, null, item );
-    }
-
-    public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
-
-        if ( entity == null ) {
-            entity = new Entity();
-        }
-
-        for ( String fieldName : map.keySet() ) {
-
-            Object value = map.get( fieldName );
-
-            if ( value instanceof String ) {
-                entity.setField( new StringField( fieldName, (String)value ));
-
-            } else if ( value instanceof Boolean ) {
-                entity.setField( new BooleanField( fieldName, (Boolean)value ));
-                        
-            } else if ( value instanceof Integer ) {
-                entity.setField( new IntegerField( fieldName, (Integer)value ));
-
-            } else if ( value instanceof Double ) {
-                entity.setField( new DoubleField( fieldName, (Double)value ));
-
-		    } else if ( value instanceof Float ) {
-                entity.setField( new FloatField( fieldName, (Float)value ));
-				
-            } else if ( value instanceof Long ) {
-                entity.setField( new LongField( fieldName, (Long)value ));
-
-            } else if ( value instanceof List) {
-                entity.setField( listToListField( scope, fieldName, (List)value ));
-
-            } else if ( value instanceof Map ) {
-
-				Field field = null;
-
-				// is the map really a location element?
-				Map<String, Object> m = (Map<String, Object>)value;
-				if ( m.size() == 2) {
-					Double lat = null;
-					Double lon = null;
-					try {
-						if ( m.get("latitude") != null && m.get("longitude") != null ) {
-							lat = Double.parseDouble( m.get("latitude").toString() );
-							lon = Double.parseDouble( m.get("longitude").toString() );
-
-						} else if ( m.get("lat") != null && m.get("lon") != null ) { 
-							lat = Double.parseDouble( m.get("lat").toString() );
-							lon = Double.parseDouble( m.get("lon").toString() );
-						}
-					} catch ( NumberFormatException ignored ) {}
-
-					if ( lat != null && lon != null ) {
-						field = new LocationField( fieldName, new Location( lat, lon ));
-					}
-				}
-
-				if ( field == null ) { 
-
-					// not a location element, process it as map
-					entity.setField( new EntityObjectField( fieldName, 
-						fromMap( scope, (Map<String, Object>)value ))); // recursion
-
-				} else {
-					entity.setField( field );
-				}
-	
-			} else {
-                throw new RuntimeException("Unknown type " + value.getClass().getName());
-            }
-        }
-
-        return entity;
-    }
-
-    
-    private static ListField listToListField( String scope, String fieldName, List list ) {
-
-        if (list.isEmpty()) {
-            return new ListField( fieldName );
-        }
-
-        Object sample = list.get(0);
-
-        if ( sample instanceof Map ) {
-            return new ListField<Entity>( fieldName, processListForField( scope, list ));
-
-        } else if ( sample instanceof List ) {
-            return new ListField<List>( fieldName, processListForField( scope, list ));
-            
-        } else if ( sample instanceof String ) {
-            return new ListField<String>( fieldName, (List<String>)list );
-                    
-        } else if ( sample instanceof Boolean ) {
-            return new ListField<Boolean>( fieldName, (List<Boolean>)list );
-                    
-        } else if ( sample instanceof Integer ) {
-            return new ListField<Integer>( fieldName, (List<Integer>)list );
-
-        } else if ( sample instanceof Double ) {
-            return new ListField<Double>( fieldName, (List<Double>)list );
-
-        } else if ( sample instanceof Long ) {
-            return new ListField<Long>( fieldName, (List<Long>)list );
-
-        } else {
-            throw new RuntimeException("Unknown type " + sample.getClass().getName());
-        }
-    }
-
-    
-    private static List processListForField( String scope, List list ) {
-        if ( list.isEmpty() ) {
-            return list;
-        }
-        Object sample = list.get(0);
-
-        if ( sample instanceof Map ) {
-            List<Entity> newList = new ArrayList<Entity>();
-            for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
-                newList.add( fromMap( scope, map ) );
-            }
-            return newList;
-
-        } else if ( sample instanceof List ) {
-            return processListForField( scope, list ); // recursion
-            
-        } else { 
-            return list;
-        } 
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
deleted file mode 100644
index 4b3e40d..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.io.File;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.exceptions.JsonReadException;
-import org.apache.usergrid.persistence.exceptions.JsonWriteException;
-//import org.apache.usergrid.persistence.Entity;
-
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.io.JsonStringEncoder;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig.Feature;
-import org.codehaus.jackson.smile.SmileFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.commons.lang.StringUtils.substringAfter;
-
-import static org.apache.usergrid.utils.StringUtils.stringOrSubstringBeforeFirst;
-
-
-public class JsonUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger( JsonUtils.class );
-
-    static ObjectMapper mapper = new ObjectMapper();
-
-    static SmileFactory smile = new SmileFactory();
-
-    static ObjectMapper smileMapper = new ObjectMapper( smile );
-
-    private static ObjectMapper indentObjectMapper = new ObjectMapper();
-
-
-    static {
-        indentObjectMapper.getSerializationConfig().set( Feature.INDENT_OUTPUT, true );
-    }
-
-
-    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
-    public static String mapToJsonString( Object obj ) {
-        try {
-            return mapper.writeValueAsString( obj );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error generating JSON", t );
-            throw new JsonWriteException( "Error generating JSON", t );
-        }
-    }
-
-
-    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
-    public static String mapToFormattedJsonString( Object obj ) {
-        try {
-            return indentObjectMapper.writeValueAsString( obj );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error generating JSON", t );
-            throw new JsonWriteException( "Error generating JSON", t );
-        }
-    }
-
-
-    /** Parses JSON string  and returns object, throws runtime exception JsonReadException on failure. */
-    public static Object parse( String json ) {
-        try {
-            return mapper.readValue( json, Object.class );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error parsing JSON", t );
-            throw new JsonReadException( "Error parsing JSON", t );
-        }
-    }
-
-
-    public static String quoteString( String s ) {
-        JsonStringEncoder encoder = new JsonStringEncoder();
-        return new String( encoder.quoteAsUTF8( s ) );
-    }
-
-
-    public static ByteBuffer toByteBuffer( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-
-        byte[] bytes = null;
-        try {
-            bytes = smileMapper.writeValueAsBytes( obj );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error getting SMILE bytes", e );
-        }
-        if ( bytes != null ) {
-            return ByteBuffer.wrap( bytes );
-        }
-        return null;
-    }
-
-
-    public static Object fromByteBuffer( ByteBuffer byteBuffer ) {
-        return fromByteBuffer( byteBuffer, Object.class );
-    }
-
-
-    public static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ) {
-        if ( ( byteBuffer == null ) || !byteBuffer.hasRemaining() ) {
-            return null;
-        }
-        if ( clazz == null ) {
-            clazz = Object.class;
-        }
-
-        Object obj = null;
-        try {
-            obj = smileMapper.readValue( byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
-                    byteBuffer.remaining(), clazz );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error parsing SMILE bytes", e );
-        }
-        return obj;
-    }
-
-
-    public static JsonNode toJsonNode( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-        return mapper.convertValue( obj, JsonNode.class );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static Map<String, Object> toJsonMap( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-
-        return ( Map<String, Object> ) mapper.convertValue( obj, Map.class );
-    }
-
-
-    private static UUID tryConvertToUUID( Object o ) {
-        if ( o instanceof String ) {
-            String s = ( String ) o;
-            if ( s.length() == 36 ) {
-                try {
-                    return UUID.fromString( s );
-                }
-                catch ( IllegalArgumentException e ) {
-                    LOG.warn( "Argument to UUID.fromString({}) was invalid.", s, e );
-                }
-            }
-        }
-        return null;
-    }
-
-
-    public static Object normalizeJsonTree( Object obj ) {
-        if ( obj instanceof Map ) {
-            @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj;
-            Object o;
-            UUID uuid;
-            for ( Object k : m.keySet() ) {
-                if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) {
-                    continue;
-                }
-
-                o = m.get( k );
-                uuid = tryConvertToUUID( o );
-                if ( uuid != null ) {
-                    m.put( k, uuid );
-                }
-                else if ( o instanceof Integer ) {
-                    m.put( k, ( ( Integer ) o ).longValue() );
-                }
-                else if ( o instanceof BigInteger ) {
-                    m.put( k, ( ( BigInteger ) o ).longValue() );
-                }
-            }
-        }
-        else if ( obj instanceof List ) {
-            @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj;
-            Object o;
-            UUID uuid;
-            for ( int i = 0; i < l.size(); i++ ) {
-                o = l.get( i );
-                uuid = tryConvertToUUID( o );
-                if ( uuid != null ) {
-                    l.set( i, uuid );
-                }
-                else if ( ( o instanceof Map ) || ( o instanceof List ) ) {
-                    normalizeJsonTree( o );
-                }
-                else if ( o instanceof Integer ) {
-                    l.set( i, ( ( Integer ) o ).longValue() );
-                }
-                else if ( o instanceof BigInteger ) {
-                    l.set( i, ( ( BigInteger ) o ).longValue() );
-                }
-            }
-        }
-        else if ( obj instanceof String ) {
-            UUID uuid = tryConvertToUUID( obj );
-            if ( uuid != null ) {
-                return uuid;
-            }
-        }
-        else if ( obj instanceof Integer ) {
-            return ( ( Integer ) obj ).longValue();
-        }
-        else if ( obj instanceof BigInteger ) {
-            return ( ( BigInteger ) obj ).longValue();
-        }
-        else if ( obj instanceof JsonNode ) {
-            return mapper.convertValue( obj, Object.class );
-        }
-        return obj;
-    }
-
-
-//    public static Object select( Object obj, String path ) {
-//        return select( obj, path, false );
-//    }
-//
-//
-//    public static Object select( Object obj, String path, boolean buildResultTree ) {
-//
-//        if ( obj == null ) {
-//            return null;
-//        }
-//
-//        if ( org.apache.commons.lang.StringUtils.isBlank( path ) ) {
-//            return obj;
-//        }
-//
-//        String segment = stringOrSubstringBeforeFirst( path, '.' );
-//        String remaining = substringAfter( path, "." );
-//
-//        if ( obj instanceof Map ) {
-//            Map<?, ?> map = ( Map<?, ?> ) obj;
-//            Object child = map.get( segment );
-//            Object result = select( child, remaining, buildResultTree );
-//            if ( result != null ) {
-//                if ( buildResultTree ) {
-//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-//                    results.put( segment, result );
-//                    return results;
-//                }
-//                else {
-//                    return result;
-//                }
-//            }
-//            return null;
-//        }
-//        if ( obj instanceof List ) {
-//            List<Object> results = new ArrayList<Object>();
-//            List<?> list = ( List<?> ) obj;
-//            for ( Object i : list ) {
-//                Object result = select( i, path, buildResultTree );
-//                if ( result != null ) {
-//                    results.add( result );
-//                }
-//            }
-//            if ( !results.isEmpty() ) {
-//                return results;
-//            }
-//            return null;
-//        }
-//
-//        if ( obj instanceof Entity ) {
-//            Object child = ( ( Entity ) obj ).getProperty( segment );
-//            Object result = select( child, remaining, buildResultTree );
-//            if ( result != null ) {
-//                if ( buildResultTree ) {
-//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-//                    results.put( segment, result );
-//                    return results;
-//                }
-//                else {
-//                    return result;
-//                }
-//            }
-//            else {
-//                return result;
-//            }
-//        }
-//
-//        return obj;
-//    }
-
-
-    public static Object loadFromFilesystem( String filename ) {
-        Object json = null;
-        try {
-            File file = new File( filename );
-            json = mapper.readValue( file, Object.class );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error loading JSON", e );
-        }
-        return json;
-    }
-}


[27/27] git commit: Merge branch 'two-dot-o' into entity-manager

Posted by sn...@apache.org.
Merge branch 'two-dot-o' into entity-manager

Conflicts:
	stack/corepersistence/perftest1/pom.xml


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

Branch: refs/heads/entity-manager
Commit: c662838273497cbf1e08b2c5e20c704eaee521f0
Parents: 8adbe29 9caf38b
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 27 12:30:23 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 27 12:30:23 2014 -0400

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpModule.java      |   42 +-
 stack/corepersistence/collection/pom.xml        |   13 +
 .../collection/guice/CollectionModule.java      |    8 +-
 .../impl/EntityCollectionManagerImpl.java       |   19 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |   14 +-
 .../collection/rx/CassandraThreadScheduler.java |  107 --
 .../persistence/collection/rx/RxFig.java        |   42 -
 .../stage/write/WriteUniqueVerifyStageTest.java |    3 +-
 .../mvcc/stage/write/WriteUniqueVerifyTest.java |    6 +-
 .../rx/CassandraThreadSchedulerTest.java        |  413 -----
 .../persistence/collection/rx/ParallelTest.java |    6 +-
 stack/corepersistence/graph/pom.xml             |    1 +
 .../usergrid/persistence/graph/EdgeManager.java |  163 --
 .../persistence/graph/EdgeManagerFactory.java   |   40 -
 .../usergrid/persistence/graph/GraphFig.java    |   39 +-
 .../persistence/graph/GraphManager.java         |  169 ++
 .../persistence/graph/GraphManagerFactory.java  |   40 +
 .../graph/consistency/AsyncProcessorImpl.java   |   48 +-
 .../graph/consistency/TimeoutTask.java          |    2 +-
 .../persistence/graph/guice/EdgeWrite.java      |   37 -
 .../persistence/graph/guice/GraphModule.java    |   14 +-
 .../graph/hystrix/HystrixGraphObservable.java   |   71 +
 .../graph/impl/CollectionIndexObserver.java     |   14 +-
 .../graph/impl/EdgeDeleteListener.java          |   68 +-
 .../persistence/graph/impl/EdgeManagerImpl.java |  408 -----
 .../graph/impl/EdgeWriteListener.java           |  103 --
 .../graph/impl/GraphManagerImpl.java            |  384 +++++
 .../graph/impl/NodeDeleteListener.java          |  216 ++-
 .../graph/impl/SimpleSearchByEdgeType.java      |   38 +
 .../graph/impl/stage/AbstractEdgeRepair.java    |   47 +-
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |    4 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |   33 +-
 .../graph/impl/stage/EdgeWriteRepair.java       |   44 -
 .../graph/impl/stage/EdgeWriteRepairImpl.java   |   76 -
 .../graph/serialization/EdgeSerialization.java  |   12 +-
 .../impl/EdgeMetadataSerializationImpl.java     |   19 +-
 .../impl/EdgeSerializationImpl.java             |  256 +--
 .../impl/parse/ColumnNameIterator.java          |   38 +-
 .../impl/parse/ObservableIterator.java          |   26 +-
 .../persistence/graph/EdgeManagerIT.java        | 1468 -----------------
 .../graph/EdgeManagerStressTest.java            |  313 ----
 .../persistence/graph/GraphManagerIT.java       | 1497 ++++++++++++++++++
 .../graph/GraphManagerStressTest.java           |  317 ++++
 .../graph/GraphManagerTimeoutIT.java            |  230 +++
 .../graph/consistency/AsyncProcessorTest.java   |   25 +-
 .../consistency/LocalTimeoutQueueTest.java      |    2 +-
 .../graph/guice/TestGraphModule.java            |    4 +-
 .../graph/impl/NodeDeleteListenerTest.java      |  221 ++-
 .../graph/impl/stage/EdgeDeleteRepairTest.java  |    6 +-
 .../graph/impl/stage/EdgeMetaRepairTest.java    |   83 +-
 .../graph/impl/stage/EdgeWriteRepairTest.java   |  220 ---
 .../EdgeSerializationChopTest.java              |   35 +-
 .../serialization/EdgeSerializationTest.java    |  206 ++-
 .../serialization/NodeSerializationTest.java    |   13 +-
 .../graph/serialization/TestCount.java          |  125 ++
 .../serialization/util/EdgeHasherTest.java      |   14 +-
 .../graph/test/util/EdgeTestUtils.java          |    7 +-
 .../graph/src/test/resources/log4j.properties   |   36 +
 stack/corepersistence/perftest1/pom.xml         |    2 +-
 stack/corepersistence/pom.xml                   |    3 +
 60 files changed, 3880 insertions(+), 4030 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c6628382/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
index 7388a8a,0000000..3529ace
mode 100644,000000..100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpModule.java
@@@ -1,124 -1,0 +1,122 @@@
 +/*
 + * Copyright 2014 The Apache Software Foundation.
 + *
 + * Licensed under the Apache License, Version 2.0 (the "License");
 + * you may not use this file except in compliance with the License.
 + * You may obtain a copy of the License at
 + *
 + *      http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +
 +package org.apache.usergrid.corepersistence;
 +
 +import com.google.inject.AbstractModule;
 +import com.google.inject.assistedinject.FactoryModuleBuilder;
 +import com.google.inject.multibindings.Multibinder;
 +import org.apache.usergrid.persistence.collection.guice.CollectionModule;
 +import org.apache.usergrid.persistence.collection.migration.Migration;
 +import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
- import org.apache.usergrid.persistence.graph.EdgeManager;
- import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
 +import org.apache.usergrid.persistence.graph.GraphFig;
++import org.apache.usergrid.persistence.graph.GraphManager;
++import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 +import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 +import org.apache.usergrid.persistence.graph.consistency.AsyncProcessorImpl;
 +import org.apache.usergrid.persistence.graph.consistency.LocalTimeoutQueue;
 +import org.apache.usergrid.persistence.graph.consistency.TimeService;
 +import org.apache.usergrid.persistence.graph.consistency.TimeoutQueue;
 +import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
- import org.apache.usergrid.persistence.graph.guice.EdgeWrite;
 +import org.apache.usergrid.persistence.graph.guice.NodeDelete;
 +import org.apache.usergrid.persistence.graph.impl.CollectionIndexObserver;
- import org.apache.usergrid.persistence.graph.impl.EdgeManagerImpl;
++import org.apache.usergrid.persistence.graph.impl.GraphManagerImpl;
 +import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
 +import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepairImpl;
 +import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
 +import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepairImpl;
- import org.apache.usergrid.persistence.graph.impl.stage.EdgeWriteRepair;
- import org.apache.usergrid.persistence.graph.impl.stage.EdgeWriteRepairImpl;
 +import org.apache.usergrid.persistence.graph.serialization.CassandraConfig;
 +import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 +import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
 +import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
 +import org.apache.usergrid.persistence.graph.serialization.impl.CassandraConfigImpl;
 +import org.apache.usergrid.persistence.graph.serialization.impl.EdgeMetadataSerializationImpl;
 +import org.apache.usergrid.persistence.graph.serialization.impl.EdgeSerializationImpl;
 +import org.apache.usergrid.persistence.graph.serialization.impl.NodeSerializationImpl;
 +import org.apache.usergrid.persistence.index.EntityCollectionIndex;
 +import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
 +import org.apache.usergrid.persistence.index.IndexFig;
 +import org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex;
 +import org.safehaus.guicyfig.GuicyFigModule;
 +
++
++
 +/**
 + * Guice Module that encapsulates Core Persistence.
 + */
 +public class CpModule  extends AbstractModule {
 +
 +    @Override
 +    protected void configure() {
 +
 +        //------------
 +        // COLLECTION
 +        //
 +
 +        // configure collections and our core astyanax framework
 +        install(new CollectionModule());
 +
 +        //------------
 +        // INDEX 
 +        //
 +
 +        install (new GuicyFigModule( IndexFig.class ));
 +
 +        install( new FactoryModuleBuilder()
 +            .implement( EntityCollectionIndex.class, EsEntityCollectionIndex.class )
 +            .build( EntityCollectionIndexFactory.class ) );
 +
 +        //------------
 +        // GRAPH 
 +        //
 +
++        //install our configuration
 +        install (new GuicyFigModule( GraphFig.class ));
-         
++
 +        bind( PostProcessObserver.class ).to( CollectionIndexObserver.class );
 +
 +        bind( EdgeMetadataSerialization.class).to( EdgeMetadataSerializationImpl.class);
 +        bind( EdgeSerialization.class).to( EdgeSerializationImpl.class );
 +        bind( NodeSerialization.class).to( NodeSerializationImpl.class );
 +
 +        bind( CassandraConfig.class).to( CassandraConfigImpl.class );
 +
-          // create a guice factory for getting our collection manager
-         install( new FactoryModuleBuilder()
-                 .implement( EdgeManager.class, EdgeManagerImpl.class )
-                 .build( EdgeManagerFactory.class ) );
-         
-         Multibinder<Migration> migrationBinding = 
-             Multibinder.newSetBinder( binder(), Migration.class );
++        // create a guice factory for getting our collection manager
++        install( new FactoryModuleBuilder().implement( GraphManager.class, GraphManagerImpl.class )
++                                           .build( GraphManagerFactory.class ) );
 +
++        //do multibindings for migrations
++        Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
 +        migrationBinding.addBinding().to( EdgeMetadataSerializationImpl.class );
 +        migrationBinding.addBinding().to( EdgeSerializationImpl.class );
 +        migrationBinding.addBinding().to( NodeSerializationImpl.class );
 +
-         // local queue
-         bind(TimeoutQueue.class).to( LocalTimeoutQueue.class );
++        // Graph event bus, will need to be refactored into it's own classes
++
++        // create a guice factor for getting our collection manager
 +
++        //local queue.  Need to
++        bind(TimeoutQueue.class).to( LocalTimeoutQueue.class );
 +
-         bind( AsyncProcessor.class).annotatedWith( EdgeDelete.class ).to( AsyncProcessorImpl.class );
-         bind( AsyncProcessor.class).annotatedWith( EdgeWrite.class ).to( AsyncProcessorImpl.class );
-         bind( AsyncProcessor.class).annotatedWith( NodeDelete.class ).to( AsyncProcessorImpl.class );
++        bind(AsyncProcessor.class).annotatedWith( EdgeDelete.class ).to( AsyncProcessorImpl.class );
++        bind(AsyncProcessor.class).annotatedWith( NodeDelete.class ).to( AsyncProcessorImpl.class );
 +
-         // Repair/cleanup classes
++        //Repair/cleanup classes
 +        bind( EdgeMetaRepair.class).to( EdgeMetaRepairImpl.class );
-         bind( EdgeWriteRepair.class).to( EdgeWriteRepairImpl.class );
 +        bind( EdgeDeleteRepair.class).to( EdgeDeleteRepairImpl.class );
- 
 +        bind( TimeService.class).to( TimeServiceImpl.class );
 +    }    
 +}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c6628382/stack/corepersistence/perftest1/pom.xml
----------------------------------------------------------------------
diff --cc stack/corepersistence/perftest1/pom.xml
index fd58f9a,08f5513..c9b9f2e
--- a/stack/corepersistence/perftest1/pom.xml
+++ b/stack/corepersistence/perftest1/pom.xml
@@@ -68,4 -68,4 +68,4 @@@
  
          </plugins>
      </build>
--</project>
++</project>


[08/27] Merged hystrix into asyncqueue

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationChopTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationChopTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationChopTest.java
index 7d97f0e..e7a3504 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationChopTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationChopTest.java
@@ -18,8 +18,6 @@ import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
-import org.apache.usergrid.persistence.graph.SearchByEdge;
-import org.apache.usergrid.persistence.graph.guice.GraphModule;
 import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -28,12 +26,8 @@ import com.google.inject.Inject;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -41,11 +35,10 @@ import static org.mockito.Mockito.when;
 
 /**
  * Test for use with Judo CHOP to stress test
- *
  */
-@IterationChop( iterations = 10, threads = 2 )
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
+@IterationChop(iterations = 10, threads = 2)
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
 public class EdgeSerializationChopTest {
 
     @ClassRule
@@ -63,18 +56,16 @@ public class EdgeSerializationChopTest {
     protected OrganizationScope scope;
 
 
-
     /**
      * Static UUID so ALL nodes write to this as the source
      */
-    private static final UUID ORG_ID = UUID.fromString("5697ad38-8dd8-11e3-8436-600308a690e3");
-
+    private static final UUID ORG_ID = UUID.fromString( "5697ad38-8dd8-11e3-8436-600308a690e3" );
 
 
     /**
      * Static UUID so ALL nodes write to this as the source
      */
-    private static final UUID SOURCE_NODE_ID = UUID.fromString("5697ad38-8dd8-11e3-8436-600308a690e2");
+    private static final UUID SOURCE_NODE_ID = UUID.fromString( "5697ad38-8dd8-11e3-8436-600308a690e2" );
 
 
     @Before
@@ -97,8 +88,8 @@ public class EdgeSerializationChopTest {
     public void mixedEdgeTypes() throws ConnectionException {
 
 
-        final Id sourceId = createId( SOURCE_NODE_ID, "source");
-        final Id targetId = createId("target");
+        final Id sourceId = createId( SOURCE_NODE_ID, "source" );
+        final Id targetId = createId( "target" );
 
 
         final Edge edge = createEdge( sourceId, "edge", targetId );
@@ -110,20 +101,18 @@ public class EdgeSerializationChopTest {
 
         //get our edges out by name
 
-        Iterator<MarkedEdge>
-                results = serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, "edge", now, null ) );
+        Iterator<MarkedEdge> results =
+                serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, "edge", now, null ) );
 
         boolean found = false;
 
-        while(!found && results.hasNext()){
-            if(edge.equals(results.next())){
+        while ( !found && results.hasNext() ) {
+            if ( edge.equals( results.next() ) ) {
                 found = true;
                 break;
             }
         }
 
-        assertTrue("Found entity", found);
-
+        assertTrue( "Found entity", found );
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
index 5a37cc8..776b9df 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
@@ -202,59 +202,18 @@ public class EdgeSerializationTest {
 
         SearchByEdge search = createGetByEdge( sourceId, "edge1", targetId, now, null );
 
-        Iterator<MarkedEdge> results = serialization.getEdgeFromSource( scope, search );
+        Iterator<MarkedEdge> results = serialization.getEdgeVersions( scope, search );
 
         assertEquals( edgev2, results.next() );
         assertEquals( edgev1, results.next() );
         assertFalse( "No results should be returned", results.hasNext() );
 
-
-        results = serialization.getEdgeToTarget( scope, search );
-
-        assertEquals( edgev2, results.next() );
-        assertEquals( edgev1, results.next() );
-        assertFalse( "No results should be returned", results.hasNext() );
-
-        //test paging
-        search = createGetByEdge( sourceId, "edge1", targetId, now, edgev2 );
-
-        results = serialization.getEdgeFromSource( scope, search );
-
-        assertEquals( edgev1, results.next() );
-        assertFalse( "No results should be returned", results.hasNext() );
-
-
-        results = serialization.getEdgeToTarget( scope, search );
-
-        assertEquals( edgev1, results.next() );
-        assertFalse( "No results should be returned", results.hasNext() );
-
-        //test paging
-        search = createGetByEdge( sourceId, "edge1", targetId, now, edgev1 );
-
-        results = serialization.getEdgeFromSource( scope, search );
-
-        assertFalse( "No results should be returned", results.hasNext() );
-
-
-        results = serialization.getEdgeToTarget( scope, search );
-
-        assertFalse( "No results should be returned", results.hasNext() );
-
         //max version test
 
         //test max version
         search = createGetByEdge( sourceId, "edge1", targetId, edgev1.getVersion(), null );
 
-        results = serialization.getEdgeFromSource( scope, search );
-
-        assertEquals( edgev1, results.next() );
-        assertFalse( "Max version was honored", results.hasNext() );
-
-
-        search = createGetByEdge( sourceId, "edge1", targetId, edgev1.getVersion(), null );
-
-        results = serialization.getEdgeToTarget( scope, search );
+        results = serialization.getEdgeVersions( scope, search );
 
         assertEquals( edgev1, results.next() );
         assertFalse( "Max version was honored", results.hasNext() );
@@ -339,31 +298,32 @@ public class EdgeSerializationTest {
         Iterator<MarkedEdge> results = serialization.getEdgesFromSourceByTargetType( scope,
                 createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null ) );
 
-        assertEquals( edge1, results.next() );
         assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
+
         assertFalse( results.hasNext() );
 
         //test getting the next edge
         results = serialization.getEdgesFromSourceByTargetType( scope,
-                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge1 ) );
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge2 ) );
 
-        assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
         assertFalse( results.hasNext() );
 
         results = serialization.getEdgesFromSourceByTargetType( scope,
-                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge2 ) );
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge1 ) );
 
         assertFalse( results.hasNext() );
 
         //test getting source edges from the target
 
         results = serialization.getEdgesToTargetBySourceType( scope,
-                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), edge1 ) );
+                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), edge2 ) );
         assertFalse( results.hasNext() );
 
 
         results = serialization.getEdgesToTargetBySourceType( scope,
-                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), edge2 ) );
+                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), edge1 ) );
         assertFalse( results.hasNext() );
     }
 
@@ -393,15 +353,15 @@ public class EdgeSerializationTest {
         Iterator<MarkedEdge> results = serialization.getEdgesFromSourceByTargetType( scope,
                 createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null ) );
 
-        assertEquals( edge1, results.next() );
         assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
         assertFalse( results.hasNext() );
 
         //get them out by type
         results = serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, "edge", now, null ) );
 
-        assertEquals( edge1, results.next() );
         assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
         assertFalse( results.hasNext() );
 
 
@@ -498,15 +458,15 @@ public class EdgeSerializationTest {
         Iterator<MarkedEdge> results = serialization.getEdgesFromSourceByTargetType( scope,
                 createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null ) );
 
-        assertEquals( edge1, results.next() );
         assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
         assertFalse( results.hasNext() );
 
         //get them out by type
         results = serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, "edge", now, null ) );
 
-        assertEquals( edge1, results.next() );
         assertEquals( edge2, results.next() );
+        assertEquals( edge1, results.next() );
         assertFalse( results.hasNext() );
 
 
@@ -548,13 +508,13 @@ public class EdgeSerializationTest {
 
         MarkedEdge edge = results.next();
 
-        assertEquals( edge1, edge );
+        assertEquals( edge2, edge );
         assertTrue( edge.isDeleted() );
 
 
         edge = results.next();
 
-        assertEquals( edge2, edge );
+        assertEquals( edge1, edge );
         assertTrue( edge.isDeleted() );
 
         assertFalse( results.hasNext() );
@@ -564,12 +524,12 @@ public class EdgeSerializationTest {
 
         edge = results.next();
 
-        assertEquals( edge1, edge );
+        assertEquals( edge2, edge );
         assertTrue( edge.isDeleted() );
 
         edge = results.next();
 
-        assertEquals( edge2, edge );
+        assertEquals( edge1, edge );
         assertTrue( edge.isDeleted() );
 
         assertFalse( results.hasNext() );
@@ -620,49 +580,92 @@ public class EdgeSerializationTest {
         //now we've validated everything exists
     }
 
+
     /**
-         * Test paging by resuming the search from the edge
-         */
-        @Test
-        public void pageIteration() throws ConnectionException {
+     * Test paging by resuming the search from the edge
+     */
+    @Test
+    public void pageIteration() throws ConnectionException {
 
-            int size = graphFig.getScanPageSize()*2;
+        int size = graphFig.getScanPageSize() * 2;
 
-            final Id sourceId= createId( "source" );
-            final String type = "edge";
+        final Id sourceId = createId( "source" );
+        final String type = "edge";
 
-            Set<Edge> edges = new HashSet<Edge>(size);
+        Set<Edge> edges = new HashSet<Edge>( size );
 
 
-            for(int i = 0; i < size; i ++){
-                final Edge edge = createEdge( sourceId, type, createId("target" ));
+        for ( int i = 0; i < size; i++ ) {
+            final Edge edge = createEdge( sourceId, type, createId( "target" ) );
 
-                serialization.writeEdge( scope, edge ).execute();
-                edges.add( edge );
-            }
+            serialization.writeEdge( scope, edge ).execute();
+            edges.add( edge );
+        }
 
 
+        UUID now = UUIDGenerator.newTimeUUID();
 
+        //get our edges out by name
+        Iterator<MarkedEdge> results =
+                serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, type, now, null ) );
 
+        for ( MarkedEdge edge : new IterableWrapper<MarkedEdge>( results ) ) {
+            assertTrue( "Removed edge from write set", edges.remove( edge ) );
+        }
 
+        assertEquals( "All edges were returned", 0, edges.size() );
+    }
 
-            UUID now = UUIDGenerator.newTimeUUID();
 
-            //get our edges out by name
-            Iterator<MarkedEdge> results = serialization.getEdgesFromSource( scope,
-                    createSearchByEdge( sourceId, type, now, null ) );
 
-            for(MarkedEdge edge: new IterableWrapper<MarkedEdge>(results)){
-                assertTrue("Removed edge from write set", edges.remove( edge ));
-            }
+    /**
+     * Tests mixing 2 edge types between 2 nodes.  We should get results for the same source->destination with the 2
+     * edge types
+     */
+    @Test
+    public void testIteratorPaging() throws ConnectionException {
+        final Edge edgev1 = createEdge( "source", "edge1", "target" );
 
-            assertEquals("All edges were returned", 0, edges.size());
+        final Id sourceId = edgev1.getSourceNode();
+        final Id targetId = edgev1.getTargetNode();
 
 
-        }
+        final Edge edgev2 = createEdge( sourceId, "edge1", targetId );
+
+        assertTrue( "Edge version 1 has lower time uuid",
+                UUIDComparator.staticCompare( edgev1.getVersion(), edgev2.getVersion() ) < 0 );
+
+        //create edge type 2 to ensure we don't get it in results
+        final Edge edgeType2V1 = createEdge( sourceId, "edge2", targetId );
+
+        serialization.writeEdge( scope, edgev1 ).execute();
+        serialization.writeEdge( scope, edgev2 ).execute();
+        serialization.writeEdge( scope, edgeType2V1 ).execute();
+
+        final UUID now = UUIDGenerator.newTimeUUID();
+
+
+        SearchByEdge search = createGetByEdge( sourceId, "edge1", targetId, now, null );
+
+        Iterator<MarkedEdge> results = serialization.getEdgeVersions( scope, search );
+
+        assertEquals( edgev2, results.next() );
+        assertEquals( edgev1, results.next() );
+        assertFalse( "No results should be returned", results.hasNext() );
+
+        //max version test
+
+        //test max version
+        search = createGetByEdge( sourceId, "edge1", targetId, edgev1.getVersion(), null );
+
+        results = serialization.getEdgeVersions( scope, search );
+
+        assertEquals( edgev1, results.next() );
+        assertFalse( "Max version was honored", results.hasNext() );
+    }
 
 
-    private class IterableWrapper<T> implements Iterable<T>{
+    private class IterableWrapper<T> implements Iterable<T> {
 
         private final Iterator<T> source;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/NodeSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/NodeSerializationTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/NodeSerializationTest.java
index 6e0b365..60f714e 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/NodeSerializationTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/NodeSerializationTest.java
@@ -36,8 +36,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
 public class NodeSerializationTest {
 
 
@@ -171,12 +171,13 @@ public class NodeSerializationTest {
         serialization.mark( scope, nodeId1, version ).execute();
         serialization.mark( scope, nodeId2, version ).execute();
 
-        Map<Id, UUID> marks = serialization.getMaxVersions( scope, Arrays.asList(  createEdge( nodeId1, "test", nodeId2 ), createEdge(nodeId2, "test", nodeId3) ) );
+        Map<Id, UUID> marks = serialization.getMaxVersions( scope,
+                Arrays.asList( createEdge( nodeId1, "test", nodeId2 ), createEdge( nodeId2, "test", nodeId3 ) ) );
 
 
-        assertEquals(version, marks.get( nodeId1 ));
-        assertEquals(version, marks.get( nodeId2 ));
-        assertFalse(marks.containsKey( nodeId3 ));
+        assertEquals( version, marks.get( nodeId1 ) );
+        assertEquals( version, marks.get( nodeId2 ) );
+        assertFalse( marks.containsKey( nodeId3 ) );
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasherTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasherTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasherTest.java
index c55138a..9d7511c 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasherTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasherTest.java
@@ -288,7 +288,8 @@ public class EdgeHasherTest {
         for ( Character.UnicodeBlock unicodeBlock : blocks ) {
             if ( count++ < limit ) {
                 testCollisions( unicodeBlock );
-            } else {
+            }
+            else {
                 break;
             }
         }
@@ -338,9 +339,8 @@ public class EdgeHasherTest {
                 if ( hashed.contains( edgeHash ) ) {
 
                     fail( String.format(
-                            "Expected hash of '%s' to be unique, but hash of '%s' already exists in unicode block " +
-                                    "'%s'.",
-                            sourceString, edgeHash, unicodeBlock ) );
+                            "Expected hash of '%s' to be unique, but hash of '%s' already exists in unicode block "
+                                    + "'%s'.", sourceString, edgeHash, unicodeBlock ) );
                 }
 
                 hashed.add( edgeHash );
@@ -367,9 +367,9 @@ public class EdgeHasherTest {
 
 
     /**
-     * Taken from the character source.  Note this purposefully eliminates Surrogate sets from the blocks
-     * since there are invalid, and do cause hash conflicts due to multiple characters mapping
-     * to a single byte value by the JVM in both UTF-8 and UTF-16
+     * Taken from the character source.  Note this purposefully eliminates Surrogate sets from the blocks since there
+     * are invalid, and do cause hash conflicts due to multiple characters mapping to a single byte value by the JVM in
+     * both UTF-8 and UTF-16
      */
     public static Character.UnicodeBlock[] blocks = {
             BASIC_LATIN, LATIN_1_SUPPLEMENT, LATIN_EXTENDED_A, LATIN_EXTENDED_B, IPA_EXTENSIONS,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 5ffab73..2beddd5 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -75,6 +75,7 @@
                     <systemPropertyVariables>
                         <archaius.deployment.environment>UNIT</archaius.deployment.environment>
                     </systemPropertyVariables>
+                    <argLine>-Xms2G -Xmx2G</argLine>
                 </configuration>
             </plugin>
 


[16/27] git commit: Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.


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

Branch: refs/heads/entity-manager
Commit: 8f969d8d969a141a5705c141949e4841cfed8293
Parents: 8043bf3
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 26 15:12:04 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 26 15:17:08 2014 -0400

----------------------------------------------------------------------
 stack/corepersistence/queryindex/pom.xml        |    2 +-
 .../persistence/index/query/tree/QueryFilter.g  |  311 ++++++
 .../index/EntityCollectionIndex.java            |    4 +-
 .../index/exceptions/IndexException.java        |   41 +
 .../index/exceptions/JsonReadException.java     |   29 +
 .../index/exceptions/JsonWriteException.java    |   29 +
 .../exceptions/NoFullTextIndexException.java    |   52 +
 .../index/exceptions/NoIndexException.java      |   50 +
 .../index/exceptions/PersistenceException.java  |   47 +
 .../index/exceptions/QueryException.java        |   41 +
 .../index/exceptions/QueryParseException.java   |   65 ++
 .../index/exceptions/QueryTokenException.java   |   54 +
 .../index/impl/EsEntityCollectionIndex.java     |    6 +-
 .../persistence/index/impl/EsQueryVistor.java   |   28 +-
 .../index/legacy/EntityManagerFacade.java       |    8 +-
 .../persistence/index/query/EntityRef.java      |   30 +
 .../usergrid/persistence/index/query/Query.java | 1015 ++++++++++++++++++
 .../persistence/index/query/Results.java        |  126 +++
 .../index/query/SimpleEntityRef.java            |  131 +++
 .../index/query/tree/AndOperand.java            |   50 +
 .../index/query/tree/BooleanLiteral.java        |   50 +
 .../index/query/tree/BooleanOperand.java        |   50 +
 .../index/query/tree/ContainsOperand.java       |   71 ++
 .../index/query/tree/ContainsProperty.java      |   59 +
 .../persistence/index/query/tree/Equal.java     |   54 +
 .../index/query/tree/EqualityOperand.java       |   90 ++
 .../index/query/tree/FloatLiteral.java          |   59 +
 .../index/query/tree/GreaterThan.java           |   55 +
 .../index/query/tree/GreaterThanEqual.java      |   59 +
 .../persistence/index/query/tree/LessThan.java  |   55 +
 .../index/query/tree/LessThanEqual.java         |   57 +
 .../persistence/index/query/tree/Literal.java   |   41 +
 .../index/query/tree/LiteralFactory.java        |   61 ++
 .../index/query/tree/LongLiteral.java           |   67 ++
 .../index/query/tree/NotOperand.java            |   45 +
 .../index/query/tree/NumericLiteral.java        |   27 +
 .../persistence/index/query/tree/Operand.java   |   50 +
 .../persistence/index/query/tree/OrOperand.java |   56 +
 .../persistence/index/query/tree/Property.java  |   65 ++
 .../index/query/tree/QueryVisitor.java          |  102 ++
 .../index/query/tree/StringLiteral.java         |   85 ++
 .../index/query/tree/UUIDLiteral.java           |   52 +
 .../index/query/tree/WithinOperand.java         |  111 ++
 .../index/query/tree/WithinProperty.java        |   57 +
 .../persistence/index/utils/ClassUtils.java     |   58 +
 .../index/utils/ConversionUtils.java            |  765 +++++++++++++
 .../persistence/index/utils/EntityBuilder.java  |  177 +++
 .../persistence/index/utils/JsonUtils.java      |  329 ++++++
 .../persistence/index/utils/ListUtils.java      |  232 ++++
 .../persistence/index/utils/MapUtils.java       |  377 +++++++
 .../persistence/index/utils/StringUtils.java    |  172 +++
 .../persistence/index/utils/UUIDUtils.java      |  412 +++++++
 .../persistence/index/impl/CollectionIT.java    |   10 +-
 .../index/impl/CorePerformanceIT.java           |    4 +-
 .../impl/EntityCollectionIndexStressTest.java   |    4 +-
 .../index/impl/EntityCollectionIndexTest.java   |    6 +-
 .../usergrid/persistence/index/impl/GeoIT.java  |   10 +-
 .../persistence/index/impl/IndexIT.java         |    6 +-
 .../persistence/index/legacy/Application.java   |    4 +-
 .../index/legacy/CoreApplication.java           |    4 +-
 .../index/legacy/CoreITSetupImpl.java           |    2 +-
 .../query/AbstractIteratingQueryIT.java         |    2 +
 .../query/AllInConnectionNoTypeIT.java          |    2 +
 .../query/IntersectionUnionPagingIT.java        |    2 +
 .../usergrid/persistence/query/QueryTest.java   |   31 +-
 .../persistence/query/tree/GrammarTreeTest.java |   20 +-
 .../persistence/query/tree/LongLiteralTest.java |    1 +
 .../query/tree/StringLiteralTest.java           |    2 +-
 68 files changed, 6162 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/pom.xml b/stack/corepersistence/queryindex/pom.xml
index 9b9e67a..a6f8d43 100644
--- a/stack/corepersistence/queryindex/pom.xml
+++ b/stack/corepersistence/queryindex/pom.xml
@@ -12,7 +12,7 @@
     <parent>
         <artifactId>persistence</artifactId>
         <groupId>org.apache.usergrid</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>2.0.0-SNAPSHOT</version>
     </parent>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/index/query/tree/QueryFilter.g
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/index/query/tree/QueryFilter.g b/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/index/query/tree/QueryFilter.g
new file mode 100644
index 0000000..d8a5f8b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/index/query/tree/QueryFilter.g
@@ -0,0 +1,311 @@
+grammar QueryFilter;
+//NOTES:  '^' denotes operator, all others in the string become operands
+
+options {
+    output=AST;
+//    ASTLabelType=CommonTree;
+}
+
+@rulecatch { }
+
+
+@header {
+package org.apache.usergrid.persistence.index.query.tree;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Query.SortPredicate;
+
+}
+
+
+@members {
+	Query query = new Query();
+
+  private static final Logger logger = LoggerFactory
+      .getLogger(QueryFilterLexer.class);
+
+	@Override
+	public void emitErrorMessage(String msg) {
+		logger.info(msg);
+	}
+}
+
+
+@lexer::header {
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.persistence.index.exceptions.QueryTokenException;
+
+}
+
+@lexer::members {
+
+
+
+  private static final Logger logger = LoggerFactory
+      .getLogger(QueryFilterLexer.class);
+
+
+
+
+	@Override
+	public void emitErrorMessage(String msg) {
+		logger.info(msg);
+	}
+
+	@Override
+    public void recover(RecognitionException e) {
+         //We don't want to recover, we want to re-throw to the user since they passed us invalid input
+         throw new QueryTokenException(e);
+    }
+
+
+}
+
+//these must come before ID. Otherwise lt, lte, eq, etc will be returned as id tokens
+LT  : '<' | 'lt';
+
+LTE : '<=' |  'lte';
+
+EQ  : '=' | 'eq';
+
+GT  : '>' | 'gt';
+
+GTE : '>=' |  'gte';  
+
+
+//keywords before var ids
+BOOLEAN : (TRUE|FALSE);
+
+AND : ('A'|'a')('N'|'n')('D'|'d') | '&&';
+
+OR  : ('O'|'o')('R'|'r') | '||' ;
+
+NOT : ('N'|'n')('O'|'o')('T'|'t');
+
+ASC : ('A'|'a')('S'|'s')('C'|'c');
+
+DESC : ('D'|'d')('E'|'e')('S'|'s')('C'|'c');
+
+CONTAINS : ('C'|'c')('O'|'o')('N'|'n')('T'|'t')('A'|'a')('I'|'i')('N'|'n')('S'|'s');
+
+WITHIN : ('W'|'w')('I'|'i')('T'|'t')('H'|'h')('I'|'i')('N'|'n');
+
+OF : ('O'|'o')('F'|'f');
+
+UUID :  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+  ;
+
+//ids and values
+ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|'-')*
+    ;
+
+LONG :	('-')? '0'..'9'+
+    ;
+
+FLOAT
+    :  ('-')? ( ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
+    |   '.' ('0'..'9')+ EXPONENT?
+    |   ('0'..'9')+ EXPONENT)
+    ;
+    
+STRING
+    :  '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
+    ;
+
+
+    
+WS : (' ' | '\t' | '\n' | '\r' | '\f')+  {$channel=HIDDEN;};
+
+
+
+    
+
+
+
+fragment TRUE : ('T'|'t')('R'|'r')('U'|'u')('E'|'e');
+
+fragment FALSE : ('F'|'f')('A'|'a')('L'|'l')('S'|'s')('E'|'e');
+
+
+fragment
+EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
+
+fragment
+HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
+
+fragment
+ESC_SEQ
+    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+    |   UNICODE_ESC
+    |   OCTAL_ESC
+    ;
+
+fragment
+OCTAL_ESC
+    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7')
+    ;
+
+fragment
+UNICODE_ESC
+    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+    ;
+
+
+
+
+//NE : '!=';
+
+
+
+property :	ID<Property>;
+
+containsproperty : ID<ContainsProperty>;
+
+withinproperty : ID<WithinProperty>;
+	
+booleanliteral: BOOLEAN<BooleanLiteral>;
+
+
+longliteral :
+  LONG<LongLiteral> ;
+
+uuidliteral :
+  UUID<UUIDLiteral>;
+
+stringliteral :
+  STRING<StringLiteral>;
+  
+floatliteral :
+  FLOAT<FloatLiteral> ;
+
+//We delegate to each sub class literal so we can get each type	
+value : 
+  booleanliteral
+  | longliteral
+  | uuidliteral
+  | stringliteral
+  | floatliteral
+  ;
+  
+
+
+//Every operand returns with the name of 'op'.  This is used because all subtrees require operands,
+//this allows us to link the java code easily by using the same name as a converntion
+
+//begin search expressions
+  
+//mathmatical equality operations
+equalityop :
+  property LT<LessThan>^ value
+  |property LTE<LessThanEqual>^ value
+  |property EQ<Equal>^ value
+  |property GT<GreaterThan>^ value
+  |property GTE<GreaterThanEqual>^ value
+  ; 
+
+//geo location search
+locationop :
+  withinproperty WITHIN<WithinOperand>^ (floatliteral|longliteral) OF! (floatliteral|longliteral) ','! (floatliteral|longliteral);
+  
+//string search
+containsop :
+  containsproperty CONTAINS<ContainsOperand>^ stringliteral;
+
+//
+operation :
+ '('! expression ')'!
+   | equalityop 
+   | locationop 
+   | containsop 
+   ;
+
+//negations of expressions
+notexp :
+//only link if we have the not
+ NOT<NotOperand>^ operation  
+ |operation 
+ ;
+
+//and expressions contain operands.  These should always be closer to the leaves of a tree, it allows
+//for faster result intersection sooner in the query execution
+andexp :
+ notexp (AND<AndOperand>^ notexp )*;
+ 
+ 
+//or expression should always be after AND expressions.  This will give us a smaller result set to union when evaluating trees
+//also a root level expression
+expression :
+ andexp (OR<OrOperand>^ andexp )*;
+
+
+
+//end expressions
+
+//begin order clauses
+
+//direction for ordering
+direction  : (ASC | DESC);
+
+//order clause
+order
+  : (property direction?){
+		String property = $property.text; 
+		String direction = $direction.text;
+		query.addSort(new SortPredicate(property, direction));
+    
+  };
+
+//end order clauses
+  
+//Begin select clauses
+
+select_subject
+  : ID {
+
+  query.addSelect($ID.text);
+
+};
+
+ 
+
+select_assign
+  : target=ID ':' source=ID {
+
+  query.addSelect($target.text, $source.text);
+
+};
+
+select_expr 
+  : ('*' | select_subject (',' select_subject) * | '{' select_assign (',' select_assign) * '}');  
+   
+//end select clauses
+
+ql returns [Query query]
+  : ('select'! select_expr!)? ('where'!? expression)? ('order by'! order! (','! order!)*)? {
+
+  if($expression.tree instanceof Operand){
+    query.setRootOperand((Operand)$expression.tree);
+  }
+  
+  retval.query = query;
+
+
+};
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
index 7cf318b..f4c04e6 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
@@ -22,8 +22,8 @@ package org.apache.usergrid.persistence.index;
 import java.util.UUID;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/IndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/IndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/IndexException.java
new file mode 100644
index 0000000..e492759
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/IndexException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+public class IndexException extends RuntimeException {
+
+    public IndexException() {
+        super();
+    }
+
+
+    public IndexException( String message, Throwable cause ) {
+        super( message, cause );
+    }
+
+
+    public IndexException( String message ) {
+        super( message );
+    }
+
+
+    public IndexException( Throwable cause ) {
+        super( cause );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonReadException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonReadException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonReadException.java
new file mode 100644
index 0000000..100d7e1
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonReadException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+public class JsonReadException extends RuntimeException {
+    private static final long serialVersionUID = 1L;
+
+
+    public JsonReadException( String msg, Throwable t ) {
+        super( msg, t );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonWriteException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonWriteException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonWriteException.java
new file mode 100644
index 0000000..a222f92
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/JsonWriteException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+public class JsonWriteException extends RuntimeException {
+    private static final long serialVersionUID = 1L;
+
+
+    public JsonWriteException( String msg, Throwable t ) {
+        super( msg, t );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoFullTextIndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoFullTextIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoFullTextIndexException.java
new file mode 100644
index 0000000..ef36095
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoFullTextIndexException.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+/**
+ * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed
+ *
+ * @author tnine
+ */
+public class NoFullTextIndexException extends PersistenceException {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+    final String entityType;
+    final String propertyName;
+
+
+    public NoFullTextIndexException( String entityType, String propertyName ) {
+        super( "Entity '" + entityType + "' with property named '" + propertyName
+                + "' is not full text indexed.  You cannot use the 'contains' operand on this field" );
+        this.entityType = entityType;
+        this.propertyName = propertyName;
+    }
+
+
+    public String getEntityType() {
+        return entityType;
+    }
+
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
new file mode 100644
index 0000000..ca9f9cb
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+/**
+ * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed
+ *
+ * @author tnine
+ */
+public class NoIndexException extends PersistenceException {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+    final String entityType;
+    final String propertyName;
+
+
+    public NoIndexException( String entityType, String propertyName ) {
+        super( "Entity '" + entityType + "' with property named '" + propertyName
+                + "' is not indexed.  You cannot use the this field in queries." );
+        this.entityType = entityType;
+        this.propertyName = propertyName;
+    }
+
+
+    public String getEntityType() {
+        return entityType;
+    }
+
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/PersistenceException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/PersistenceException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/PersistenceException.java
new file mode 100644
index 0000000..2f983b4
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/PersistenceException.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+public class PersistenceException extends Exception {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+
+    public PersistenceException() {
+        super();
+    }
+
+
+    public PersistenceException( String message, Throwable cause ) {
+        super( message, cause );
+    }
+
+
+    public PersistenceException( String message ) {
+        super( message );
+    }
+
+
+    public PersistenceException( Throwable cause ) {
+        super( cause );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryException.java
new file mode 100644
index 0000000..a9928ec
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+public class QueryException extends RuntimeException {
+
+    public QueryException() {
+        super();
+    }
+
+
+    public QueryException( String message, Throwable cause ) {
+        super( message, cause );
+    }
+
+
+    public QueryException( String message ) {
+        super( message );
+    }
+
+
+    public QueryException( Throwable cause ) {
+        super( cause );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryParseException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryParseException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryParseException.java
new file mode 100644
index 0000000..4e46bc5
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryParseException.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+/**
+ * An exception thrown when a query cannot be parsed
+ *
+ * @author tnine
+ */
+public class QueryParseException extends RuntimeException {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     *
+     */
+    public QueryParseException() {
+        super();
+    }
+
+
+    /**
+     * @param arg0
+     * @param arg1
+     */
+    public QueryParseException( String arg0, Throwable arg1 ) {
+        super( arg0, arg1 );
+    }
+
+
+    /**
+     * @param arg0
+     */
+    public QueryParseException( String arg0 ) {
+        super( arg0 );
+    }
+
+
+    /**
+     * @param arg0
+     */
+    public QueryParseException( Throwable arg0 ) {
+        super( arg0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryTokenException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryTokenException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryTokenException.java
new file mode 100644
index 0000000..5bf45d7
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryTokenException.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+/**
+ * An exception thrown when a query encounters a token it doesn't recognize
+ * @author tnine
+ */
+public class QueryTokenException extends RuntimeException {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+
+
+
+    /**
+     * @param arg0
+     */
+    public QueryTokenException( Throwable arg0 ) {
+        super( arg0 );
+    }
+
+
+    @Override
+    public String getMessage() {
+        //antlr errors or strange.  We have to do this, there's no message
+        return getCause().toString();
+    }
+
+
+    @Override
+    public String getLocalizedMessage() {
+        return getMessage();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
index 8e16d88..3c0239c 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
@@ -34,7 +34,7 @@ import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
-import org.apache.usergrid.persistence.exceptions.IndexException;
+import org.apache.usergrid.persistence.index.exceptions.IndexException;
 import org.apache.usergrid.persistence.index.EntityCollectionIndex;
 import org.apache.usergrid.persistence.index.IndexFig;
 import org.apache.usergrid.persistence.model.entity.Entity;
@@ -47,8 +47,8 @@ import org.apache.usergrid.persistence.model.field.ListField;
 import org.apache.usergrid.persistence.model.field.LocationField;
 import org.apache.usergrid.persistence.model.field.SetField;
 import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest;
 import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
index 5998bf2..332c47b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
@@ -21,22 +21,22 @@ package org.apache.usergrid.persistence.index.impl;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
-import org.apache.usergrid.persistence.exceptions.NoFullTextIndexException;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
+import org.apache.usergrid.persistence.index.exceptions.NoFullTextIndexException;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
 import static org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex.ANALYZED_SUFFIX;
 import static org.apache.usergrid.persistence.index.impl.EsEntityCollectionIndex.GEO_SUFFIX;
-import org.apache.usergrid.persistence.query.tree.AndOperand;
-import org.apache.usergrid.persistence.query.tree.ContainsOperand;
-import org.apache.usergrid.persistence.query.tree.Equal;
-import org.apache.usergrid.persistence.query.tree.GreaterThan;
-import org.apache.usergrid.persistence.query.tree.GreaterThanEqual;
-import org.apache.usergrid.persistence.query.tree.LessThan;
-import org.apache.usergrid.persistence.query.tree.LessThanEqual;
-import org.apache.usergrid.persistence.query.tree.NotOperand;
-import org.apache.usergrid.persistence.query.tree.OrOperand;
-import org.apache.usergrid.persistence.query.tree.QueryVisitor;
-import org.apache.usergrid.persistence.query.tree.WithinOperand;
+import org.apache.usergrid.persistence.index.query.tree.AndOperand;
+import org.apache.usergrid.persistence.index.query.tree.ContainsOperand;
+import org.apache.usergrid.persistence.index.query.tree.Equal;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThan;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.LessThan;
+import org.apache.usergrid.persistence.index.query.tree.LessThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.NotOperand;
+import org.apache.usergrid.persistence.index.query.tree.OrOperand;
+import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
+import org.apache.usergrid.persistence.index.query.tree.WithinOperand;
 import org.elasticsearch.common.unit.DistanceUnit;
 import org.elasticsearch.index.query.FilterBuilder;
 import org.elasticsearch.index.query.FilterBuilders;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
index 5e57ace..912978f 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
@@ -17,7 +17,7 @@
  */
 package org.apache.usergrid.persistence.index.legacy;
 
-import org.apache.usergrid.utils.EntityBuilder;
+import org.apache.usergrid.persistence.index.utils.EntityBuilder;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.usergrid.persistence.collection.CollectionScope;
@@ -33,9 +33,9 @@ import org.apache.usergrid.persistence.model.field.LocationField;
 import org.apache.usergrid.persistence.model.field.LongField;
 import org.apache.usergrid.persistence.model.field.value.Location;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.query.EntityRef;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.index.query.EntityRef;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.query.Results;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityRef.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityRef.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityRef.java
new file mode 100644
index 0000000..2abbbe5
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityRef.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query;
+
+
+import java.util.UUID;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+public interface EntityRef {
+
+    public Id getId();
+
+    public UUID getVersion();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
new file mode 100644
index 0000000..23aad8b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -0,0 +1,1015 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.UUID;
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenRewriteStream;
+import static org.apache.commons.codec.binary.Base64.decodeBase64;
+import org.apache.commons.lang.StringUtils;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.commons.lang.StringUtils.split;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
+import org.apache.usergrid.persistence.index.impl.EsQueryVistor;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.index.query.tree.AndOperand;
+import org.apache.usergrid.persistence.index.query.tree.ContainsOperand;
+import org.apache.usergrid.persistence.index.query.tree.Equal;
+import org.apache.usergrid.persistence.index.query.tree.EqualityOperand;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThan;
+import org.apache.usergrid.persistence.index.query.tree.GreaterThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.LessThan;
+import org.apache.usergrid.persistence.index.query.tree.LessThanEqual;
+import org.apache.usergrid.persistence.index.query.tree.Operand;
+import org.apache.usergrid.persistence.index.query.tree.QueryFilterLexer;
+import org.apache.usergrid.persistence.index.query.tree.QueryFilterParser;
+import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
+import static org.apache.usergrid.persistence.index.utils.ClassUtils.cast;
+import org.apache.usergrid.persistence.index.utils.JsonUtils;
+import org.apache.usergrid.persistence.index.utils.ListUtils;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.first;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.firstBoolean;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.firstInteger;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.firstLong;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.firstUuid;
+import static org.apache.usergrid.persistence.index.utils.ListUtils.isEmpty;
+import static org.apache.usergrid.persistence.index.utils.MapUtils.toMapList;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class Query {
+    private static final Logger logger = LoggerFactory.getLogger( Query.class );
+
+    public static final int PAGE_SIZE = 1000;
+
+    public static final int DEFAULT_LIMIT = 10;
+    public static final int MAX_LIMIT = 1000;
+    public static final String PROPERTY_ID = "id";
+
+    private String type;
+    private List<SortPredicate> sortPredicates = new ArrayList<SortPredicate>();
+    private Operand rootOperand;
+    private UUID startResult;
+    private String cursor;
+    private int limit = 0;
+
+    private Map<String, String> selectAssignments = new LinkedHashMap<String, String>();
+    private boolean mergeSelectResults = false;
+    private String connection;
+    private List<String> permissions;
+    private boolean reversed;
+    private boolean reversedSet = false;
+    private Long startTime;
+    private Long finishTime;
+    private boolean pad;
+    private List<Id> identifiers;
+    private String collection;
+    private String ql;
+
+
+    public Query() {
+    }
+
+
+    public Query( Query q ) {
+        if ( q != null ) {
+            type = q.type;
+            sortPredicates = q.sortPredicates != null 
+                    ? new ArrayList<SortPredicate>( q.sortPredicates ) : null;
+            startResult = q.startResult;
+            cursor = q.cursor;
+            limit = q.limit;
+            selectAssignments = q.selectAssignments != null 
+                    ? new LinkedHashMap<String, String>( q.selectAssignments ) : null;
+            mergeSelectResults = q.mergeSelectResults;
+            connection = q.connection;
+            permissions = q.permissions != null ? new ArrayList<String>( q.permissions ) : null;
+            reversed = q.reversed;
+            reversedSet = q.reversedSet;
+            startTime = q.startTime;
+            finishTime = q.finishTime;
+            pad = q.pad;
+            rootOperand = q.rootOperand;
+            identifiers = q.identifiers != null ? new ArrayList<Id>( q.identifiers ) : null;
+            collection = q.collection;
+        }
+    }
+
+
+    public QueryBuilder createQueryBuilder() {
+
+        QueryBuilder queryBuilder = null;
+
+        if ( getRootOperand() != null ) {
+            QueryVisitor v = new EsQueryVistor();
+            try {
+                getRootOperand().visit( v );
+
+            } catch ( PersistenceException ex ) {
+                throw new RuntimeException( "Error building ElasticSearch query", ex );
+            }
+            queryBuilder = v.getQueryBuilder();
+        } 
+
+		if ( queryBuilder == null ) {
+            queryBuilder = QueryBuilders.matchAllQuery();
+		}
+
+        return queryBuilder;
+    }
+
+
+	public FilterBuilder createFilterBuilder() {
+	    FilterBuilder filterBuilder = null;
+
+        if ( getRootOperand() != null ) {
+            QueryVisitor v = new EsQueryVistor();
+            try {
+                getRootOperand().visit( v );
+
+            } catch ( PersistenceException ex ) {
+                throw new RuntimeException( "Error building ElasticSearch query", ex );
+            }
+            filterBuilder = v.getFilterBuilder();
+        } 
+
+        return filterBuilder;	
+	}
+
+
+    public static Query fromQL( String ql ) throws QueryParseException {
+        if ( ql == null ) {
+            return null;
+        }
+        String originalQl = ql;
+        ql = ql.trim();
+
+        String qlt = ql.toLowerCase();
+        if ( !qlt.startsWith( "select" ) 
+                && !qlt.startsWith( "insert" ) 
+                && !qlt.startsWith( "update" ) 
+                && !qlt.startsWith( "delete" ) ) {
+            if ( qlt.startsWith( "order by" ) ) {
+                ql = "select * " + ql;
+            }
+            else {
+                ql = "select * where " + ql;
+            }
+        }
+
+        ANTLRStringStream in = new ANTLRStringStream( ql.trim() );
+        QueryFilterLexer lexer = new QueryFilterLexer( in );
+        CommonTokenStream tokens = new CommonTokenStream( lexer );
+        QueryFilterParser parser = new QueryFilterParser( tokens );
+
+        try {
+            Query q = parser.ql().query;
+            q.setQl( originalQl );
+            return q;
+
+        } catch ( RecognitionException e ) {
+            logger.error( "Unable to parse \"{}\"", ql, e );
+            int index = e.index;
+            int lineNumber = e.line;
+            Token token = e.token;
+            String message = String.format("The query cannot be parsed. "
+                    + "The token '%s' at column %d on line %d cannot be parsed", 
+                    token.getText(), index, lineNumber );
+            throw new QueryParseException( message, e );
+        }
+    }
+
+
+    private static Query newQueryIfNull( Query query ) {
+        if ( query == null ) {
+            query = new Query();
+        }
+        return query;
+    }
+
+
+    public static Query fromJsonString( String json ) throws QueryParseException {
+        Object o = JsonUtils.parse( json );
+        if ( o instanceof Map ) {
+            @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, List<String>> params =
+                    cast( toMapList( ( Map ) o ) );
+            return fromQueryParams( params );
+        }
+        return null;
+    }
+
+
+    public static Query fromQueryParams( 
+            Map<String, List<String>> params ) throws QueryParseException {
+
+        Query q = null;
+        List<Id> identifiers = null;
+
+        String ql = Query.queryStrFrom( params );
+        String type = first( params.get( "type" ) );
+        Boolean reversed = firstBoolean( params.get( "reversed" ) );
+        String connection = first( params.get( "connection" ) );
+        UUID start = firstUuid( params.get( "start" ) );
+        String cursor = first( params.get( "cursor" ) );
+        Integer limit = firstInteger( params.get( "limit" ) );
+        List<String> permissions = params.get( "permission" );
+        Long startTime = firstLong( params.get( "start_time" ) );
+        Long finishTime = firstLong( params.get( "end_time" ) );
+
+        Boolean pad = firstBoolean( params.get( "pad" ) );
+
+        for ( Entry<String, List<String>> param : params.entrySet() ) {
+            Id identifier = null;
+            if ( ( param.getValue() == null ) || ( param.getValue().size() == 0 ) ) {
+                if ( identifier != null ) {
+                    if ( identifiers == null ) {
+                        identifiers = new ArrayList<Id>();
+                    }
+                    identifiers.add( identifier );
+                }
+            }
+        }
+
+        if ( ql != null ) {
+            q = Query.fromQL( decode( ql ) );
+        }
+
+        List<String> l = params.get( "filter" );
+
+        if ( !isEmpty( l ) ) {
+            q = newQueryIfNull( q );
+            for ( String s : l ) {
+                q.addFilter( decode( s ) );
+            }
+        }
+
+        l = params.get( "sort" );
+        if ( !isEmpty( l ) ) {
+            q = newQueryIfNull( q );
+            for ( String s : l ) {
+                q.addSort( decode( s ) );
+            }
+        }
+
+        if ( type != null ) {
+            q = newQueryIfNull( q );
+            q.setEntityType( type );
+        }
+
+        if ( connection != null ) {
+            q = newQueryIfNull( q );
+            q.setConnectionType( connection );
+        }
+
+        if ( permissions != null ) {
+            q = newQueryIfNull( q );
+            q.setPermissions( permissions );
+        }
+
+        if ( start != null ) {
+            q = newQueryIfNull( q );
+            q.setStartResult( start );
+        }
+
+        if ( cursor != null ) {
+            q = newQueryIfNull( q );
+            q.setCursor( cursor );
+        }
+
+        if ( limit != null ) {
+            q = newQueryIfNull( q );
+            q.setLimit( limit );
+        }
+
+        if ( startTime != null ) {
+            q = newQueryIfNull( q );
+            q.setStartTime( startTime );
+        }
+
+        if ( finishTime != null ) {
+            q = newQueryIfNull( q );
+            q.setFinishTime( finishTime );
+        }
+
+        if ( pad != null ) {
+            q = newQueryIfNull( q );
+            q.setPad( pad );
+        }
+
+        if ( identifiers != null ) {
+            q = newQueryIfNull( q );
+            q.setIdentifiers( identifiers );
+        }
+
+        if ( reversed != null ) {
+            q = newQueryIfNull( q );
+            q.setReversed( reversed );
+        }
+
+        return q;
+    }
+
+
+    public static Query searchForProperty( String propertyName, Object propertyValue ) {
+        Query q = new Query();
+        q.addEqualityFilter( propertyName, propertyValue );
+        return q;
+    }
+
+
+    public static Query findForProperty( String propertyName, Object propertyValue ) {
+        Query q = new Query();
+        q.addEqualityFilter( propertyName, propertyValue );
+        q.setLimit( 1 );
+        return q;
+    }
+
+
+    public static Query fromId( Id id ) {
+        Query q = new Query();
+        q.addIdentifier( id );
+        return q;
+    }
+
+    public boolean hasQueryPredicates() {
+        return rootOperand != null;
+    }
+
+    public Query addSort( SortPredicate sort ) {
+        if ( sort == null ) {
+            return this;
+        }
+
+        for ( SortPredicate s : sortPredicates ) {
+            if ( s.getPropertyName().equals( sort.getPropertyName() ) ) {
+                throw new QueryParseException(
+                    String.format( 
+                        "Attempted to set sort order for %s more than once", s.getPropertyName()));
+            }
+        }
+        sortPredicates.add( sort );
+        return this;
+    }
+
+
+    public Query withReversed( boolean reversed ) {
+        setReversed( reversed );
+        return this;
+    }
+
+
+    public String getEntityType() {
+        return type;
+    }
+
+
+    public void setEntityType( String type ) {
+        this.type = type;
+    }
+
+
+    public String getConnectionType() {
+        return connection;
+    }
+
+
+    public void setConnectionType( String connection ) {
+        this.connection = connection;
+    }
+
+
+    public List<String> getPermissions() {
+        return permissions;
+    }
+
+
+    public void setPermissions( List<String> permissions ) {
+        this.permissions = permissions;
+    }
+
+
+    public Query addSelect( String select ) {
+
+        return addSelect( select, null );
+    }
+
+
+    public Query addSelect( String select, String output ) {
+        // be paranoid with the null checks because
+        // the query parser sometimes flakes out
+        if ( select == null ) {
+            return this;
+        }
+        select = select.trim();
+
+        if ( select.equals( "*" ) ) {
+            return this;
+        }
+
+        mergeSelectResults = StringUtils.isNotEmpty( output );
+
+        if ( output == null ) {
+            output = "";
+        }
+
+        selectAssignments.put( select, output );
+
+        return this;
+    }
+
+
+    public boolean hasSelectSubjects() {
+        return !selectAssignments.isEmpty();
+    }
+
+
+    @JsonIgnore
+    public Set<String> getSelectSubjects() {
+        return selectAssignments.keySet();
+    }
+
+
+    public Map<String, String> getSelectAssignments() {
+        return selectAssignments;
+    }
+
+
+    boolean isMergeSelectResults() {
+        return mergeSelectResults;
+    }
+
+
+    public Query addSort( String propertyName ) {
+        if ( isBlank( propertyName ) ) {
+            return this;
+        }
+        propertyName = propertyName.trim();
+        if ( propertyName.indexOf( ',' ) >= 0 ) {
+            String[] propertyNames = split( propertyName, ',' );
+            for ( String s : propertyNames ) {
+                addSort( s );
+            }
+            return this;
+        }
+
+        SortDirection direction = SortDirection.ASCENDING;
+        if ( propertyName.indexOf( ' ' ) >= 0 ) {
+            String[] parts = split( propertyName, ' ' );
+            if ( parts.length > 1 ) {
+                propertyName = parts[0];
+                direction = SortDirection.find( parts[1] );
+            }
+        }
+        else if ( propertyName.startsWith( "-" ) ) {
+            propertyName = propertyName.substring( 1 );
+            direction = SortDirection.DESCENDING;
+        }
+        else if ( propertyName.startsWith( "+" ) ) {
+            propertyName = propertyName.substring( 1 );
+            direction = SortDirection.ASCENDING;
+        }
+
+        return addSort( propertyName, direction );
+    }
+
+
+    public Query addSort( String propertyName, SortDirection direction ) {
+        if ( isBlank( propertyName ) ) {
+            return this;
+        }
+        propertyName = propertyName.trim();
+        for ( SortPredicate s : sortPredicates ) {
+            if ( s.getPropertyName().equals( propertyName ) ) {
+                logger.error(
+                        "Attempted to set sort order for " + s.getPropertyName() + " more than once, discarding..." );
+                return this;
+            }
+        }
+        sortPredicates.add( new SortPredicate( propertyName, direction ) );
+        return this;
+    }
+
+
+    @JsonIgnore
+    public boolean isSortSet() {
+        return !sortPredicates.isEmpty();
+    }
+
+
+    public List<SortPredicate> getSortPredicates() {
+        return sortPredicates;
+    }
+
+
+    public Query addFilter( String filter ) {
+
+        ANTLRStringStream in = new ANTLRStringStream( filter );
+        QueryFilterLexer lexer = new QueryFilterLexer( in );
+        TokenRewriteStream tokens = new TokenRewriteStream( lexer );
+        QueryFilterParser parser = new QueryFilterParser( tokens );
+        Operand root = null;
+
+        try {
+            root = parser.ql().query.getRootOperand();
+        }
+        catch ( RecognitionException e ) {
+            // TODO: should we create a specific Exception for this? checked?
+            throw new RuntimeException( "Unknown operation: " + filter, e );
+        }
+
+        if ( root != null ) {
+            addClause( root );
+        }
+
+        return this;
+    }
+
+
+    /** Add a less than filter to this query. && with existing clauses */
+    public Query addLessThanFilter( String propName, Object value ) {
+        LessThan equality = new LessThan( null );
+
+        addClause( equality, propName, value );
+
+        return this;
+    }
+
+
+    /** Add a less than equal filter to this query. && with existing clauses */
+    public Query addLessThanEqualFilter( String propName, Object value ) {
+        LessThanEqual equality = new LessThanEqual( null );
+
+        addClause( equality, propName, value );
+
+        return this;
+    }
+
+
+    /** Add a equal filter to this query. && with existing clauses */
+    public Query addEqualityFilter( String propName, Object value ) {
+        Equal equality = new Equal( new ClassicToken( 0, "=" ) );
+
+        addClause( equality, propName, value );
+
+        return this;
+    }
+
+
+    /** Add a greater than equal filter to this query. && with existing clauses */
+    public Query addGreaterThanEqualFilter( String propName, Object value ) {
+        GreaterThanEqual equality = new GreaterThanEqual( null );
+
+        addClause( equality, propName, value );
+
+        return this;
+    }
+
+
+    /** Add a less than filter to this query. && with existing clauses */
+    public Query addGreaterThanFilter( String propName, Object value ) {
+        GreaterThan equality = new GreaterThan( null );
+
+        addClause( equality, propName, value );
+
+        return this;
+    }
+
+
+    public Query addContainsFilter( String propName, String keyword ) {
+        ContainsOperand equality = new ContainsOperand( new ClassicToken( 0, "contains" ) );
+
+        equality.setProperty( propName );
+        equality.setLiteral( keyword );
+
+        addClause( equality );
+
+        return this;
+    }
+
+
+    private void addClause( EqualityOperand equals, String propertyName, Object value ) {
+        equals.setProperty( propertyName );
+        equals.setLiteral( value );
+        addClause( equals );
+    }
+
+
+    private void addClause( Operand equals ) {
+
+        if ( rootOperand == null ) {
+            rootOperand = equals;
+            return;
+        }
+
+        AndOperand and = new AndOperand();
+        and.addChild( rootOperand );
+        and.addChild( equals );
+
+        // redirect the root to new && clause
+        rootOperand = and;
+    }
+
+
+    @JsonIgnore
+    public Operand getRootOperand() {
+        if ( rootOperand == null ) { // attempt deserialization
+            if ( ql != null ) {
+                try {
+                    Query q = Query.fromQL( ql );
+                    rootOperand = q.rootOperand;
+                }
+                catch ( QueryParseException e ) {
+                    logger.error( "error parsing sql for rootOperand", e ); // shouldn't happen
+                }
+            }
+        }
+        return rootOperand;
+    }
+
+
+    public void setRootOperand( Operand root ) {
+        this.rootOperand = root;
+    }
+
+
+    void setStartResult( UUID startResult ) {
+        this.startResult = startResult;
+    }
+
+
+    public Query withStartResult( UUID startResult ) {
+        this.startResult = startResult;
+        return this;
+    }
+
+
+    public UUID getStartResult() {
+        if ( ( startResult == null ) && ( cursor != null ) ) {
+            byte[] cursorBytes = decodeBase64( cursor );
+            if ( ( cursorBytes != null ) && ( cursorBytes.length == 16 ) ) {
+                startResult = null; 
+            }
+        }
+        return startResult;
+    }
+
+
+    public String getCursor() {
+        return cursor;
+    }
+
+
+    public void setCursor( String cursor ) {
+        this.cursor = cursor;
+    }
+
+
+    public Query withCursor( String cursor ) {
+        setCursor( cursor );
+        return this;
+    }
+
+
+    public int getLimit() {
+        return getLimit( DEFAULT_LIMIT );
+    }
+
+
+    public int getLimit( int defaultLimit ) {
+        if ( limit <= 0 ) {
+            if ( defaultLimit > 0 ) {
+                return defaultLimit;
+            }
+            else {
+                return DEFAULT_LIMIT;
+            }
+        }
+        return limit;
+    }
+
+
+    public void setLimit( int limit ) {
+
+        //      tnine.  After users have had time to change their query limits,
+        // this needs to be uncommented and enforced.
+        //        if(limit > MAX_LIMIT){
+        //          throw new IllegalArgumentException(String.format("Query limit must be <= to %d", MAX_LIMIT));
+        //        }
+
+        if ( limit > MAX_LIMIT ) {
+            limit = MAX_LIMIT;
+        }
+
+        this.limit = limit;
+    }
+
+
+    public Query withLimit( int limit ) {
+        setLimit( limit );
+        return this;
+    }
+
+
+    public boolean isReversed() {
+        return reversed;
+    }
+
+
+    public void setReversed( boolean reversed ) {
+        reversedSet = true;
+        this.reversed = reversed;
+    }
+
+
+    public boolean isReversedSet() {
+        return reversedSet;
+    }
+
+
+    public Long getStartTime() {
+        return startTime;
+    }
+
+
+    public void setStartTime( Long startTime ) {
+        this.startTime = startTime;
+    }
+
+
+    public Long getFinishTime() {
+        return finishTime;
+    }
+
+
+    public void setFinishTime( Long finishTime ) {
+        this.finishTime = finishTime;
+    }
+
+
+    public boolean isPad() {
+        return pad;
+    }
+
+
+    public void setPad( boolean pad ) {
+        this.pad = pad;
+    }
+
+
+    public void addIdentifier( Id id ) {
+        if ( identifiers == null ) {
+            identifiers = new ArrayList<Id>();
+        }
+        identifiers.add( id );
+    }
+
+
+    void setIdentifiers( List<Id> identifiers ) {
+        this.identifiers = identifiers;
+    }
+
+
+    @Override
+    public String toString() {
+        if ( ql != null ) {
+            return ql;
+        }
+        StringBuilder s = new StringBuilder( "select " );
+        if ( selectAssignments.isEmpty() ) {
+            s.append( "*" );
+        }
+        else {
+            if ( mergeSelectResults ) {
+                s.append( "{ " );
+                boolean first = true;
+                for ( Map.Entry<String, String> select : selectAssignments.entrySet() ) {
+                    if ( !first ) {
+                        s.append( ", " );
+                    }
+                    s.append( select.getValue() ).append( " : " ).append( select.getKey() );
+                    first = false;
+                }
+                s.append( " }" );
+            }
+            else {
+                boolean first = true;
+                for ( String select : selectAssignments.keySet() ) {
+                    if ( !first ) {
+                        s.append( ", " );
+                    }
+                    s.append( select );
+                    first = false;
+                }
+            }
+        }
+        s.append( " from " );
+        s.append( type );
+        if ( !sortPredicates.isEmpty() ) {
+            boolean first = true;
+            s.append( " order by " );
+            for ( SortPredicate sp : sortPredicates ) {
+                if ( !first ) {
+                    s.append( ", " );
+                }
+                s.append( sp );
+                first = false;
+            }
+        }
+        return s.toString();
+    }
+
+
+    public static enum SortDirection {
+        ASCENDING, DESCENDING;
+
+
+        public static SortDirection find( String s ) {
+            if ( s == null ) {
+                return ASCENDING;
+            }
+            s = s.toLowerCase();
+            if ( s.startsWith( "asc" ) ) {
+                return ASCENDING;
+            }
+            if ( s.startsWith( "des" ) ) {
+                return DESCENDING;
+            }
+            if ( s.equals( "+" ) ) {
+                return ASCENDING;
+            }
+            if ( s.equals( "-" ) ) {
+                return DESCENDING;
+            }
+            return ASCENDING;
+        }
+    }
+
+
+    public static final class SortPredicate implements Serializable {
+        private static final long serialVersionUID = 1L;
+        private final String propertyName;
+        private final Query.SortDirection direction;
+
+
+        public SortPredicate( String propertyName, Query.SortDirection direction ) {
+            if ( propertyName == null ) {
+                throw new NullPointerException( "Property name was null" );
+            }
+
+            if ( direction == null ) {
+                direction = SortDirection.ASCENDING;
+            }
+
+            this.propertyName = propertyName.trim();
+            this.direction = direction;
+        }
+
+
+        public SortPredicate( String propertyName, String direction ) {
+            this( propertyName, SortDirection.find( direction ) );
+        }
+
+
+        public String getPropertyName() {
+            return propertyName;
+        }
+
+
+        public Query.SortDirection getDirection() {
+            return direction;
+        }
+
+
+        @Override
+        public boolean equals( Object o ) {
+            if ( this == o ) {
+                return true;
+            }
+            if ( ( o == null ) || ( super.getClass() != o.getClass() ) ) {
+                return false;
+            }
+
+            SortPredicate that = ( SortPredicate ) o;
+
+            if ( direction != that.direction ) {
+                return false;
+            }
+
+            return ( propertyName.equals( that.propertyName ) );
+        }
+
+
+        @Override
+        public int hashCode() {
+            int result = propertyName.hashCode();
+            result = ( 31 * result ) + direction.hashCode();
+            return result;
+        }
+
+
+        @Override
+        public String toString() {
+            return propertyName + ( ( direction == Query.SortDirection.DESCENDING ) ? " DESC" : "" );
+        }
+    }
+
+
+    private static String decode( String input ) {
+        try {
+            return URLDecoder.decode( input, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException e ) {
+            // shouldn't happen, but just in case
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    // note: very likely to be null
+    public String getCollection() {
+        return collection;
+    }
+
+
+    public void setCollection( String collection ) {
+        this.collection = collection;
+    }
+
+
+    // may be null
+    public String getQl() {
+        return ql;
+    }
+
+
+    public void setQl( String ql ) {
+        this.ql = ql;
+    }
+
+
+    public List<Id> getIdentifiers() {
+        return identifiers;
+    }
+
+
+    public String getConnection() {
+        return connection;
+    }
+
+
+    public String getType() {
+        return type;
+    }
+
+    
+    public static final String PARAM_QL = "ql";
+    public static final String PARAM_Q = "q";
+    public static final String PARAM_QUERY = "query";
+
+    public static String queryStrFrom( Map<String, List<String>> params ) {
+        if ( params.containsKey( PARAM_QL ) ) {
+            return ListUtils.first( params.get( PARAM_QL ) );
+        }
+        else if ( params.containsKey( PARAM_Q ) ) {
+            return ListUtils.first( params.get( PARAM_Q ) );
+        }
+        else if ( params.containsKey( PARAM_QUERY ) ) {
+            return ListUtils.first( params.get( PARAM_QUERY ) );
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Results.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Results.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Results.java
new file mode 100644
index 0000000..7be9f28
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Results.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.index.exceptions.IndexException;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+@XmlRootElement
+public class Results implements Iterable<Entity> {
+
+    final List<Id> ids;
+    final Query query;
+    final EntityCollectionManager ecm;
+
+    String cursor = null;
+    List<Entity> entities = null;
+    List<EntityRef> refs = null;
+
+    public Results( EntityCollectionManager ecm, Query query, List<Id> ids ) {
+        this.ecm = ecm;
+        this.query = query;
+        this.ids = ids;
+    }
+
+
+    public boolean hasCursor() {
+        return cursor != null;
+    }
+
+
+    public String getCursor() {
+        return cursor;
+    }
+
+
+    public void setCursor(String cursor) {
+        this.cursor = cursor;
+    }
+
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Query getQuery() {
+        return query;
+    }
+
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public List<Id> getIds() {
+        return Collections.unmodifiableList( ids );
+    }
+
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    @SuppressWarnings("unchecked")
+    public List<EntityRef> getRefs() {
+        if ( entities == null ) {
+            getEntities();
+        }
+        return Collections.unmodifiableList( refs );
+    }
+
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public List<Entity> getEntities() {
+        if ( entities == null ) {
+            entities = new ArrayList<Entity>();
+            refs = new ArrayList<EntityRef>();
+            for ( Id id : ids ) {
+                Entity entity = ecm.load( id ).toBlockingObservable().last();
+                if (entity == null) {
+                    throw new IndexException("Entity id [" + id + "] not found");
+                }
+                entities.add( entity );
+                refs.add( new SimpleEntityRef( entity.getId(), entity.getVersion() ));
+            }
+        }
+        return Collections.unmodifiableList( entities );
+    }
+
+
+    public int size() {
+        return ids.size();
+    }
+
+
+    public boolean isEmpty() {
+        return ids.isEmpty();
+    }
+
+
+    @Override
+    public Iterator<Entity> iterator() {
+        return getEntities().iterator();
+    }
+
+    public void setIds(List<Id> ids) {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SimpleEntityRef.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SimpleEntityRef.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SimpleEntityRef.java
new file mode 100644
index 0000000..34cca44
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SimpleEntityRef.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query;
+
+
+import java.util.UUID;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+public class SimpleEntityRef implements EntityRef {
+
+    private final Id id;
+
+    private final UUID version;
+
+
+    public SimpleEntityRef( Id id, UUID version ) {
+        this.id = id;
+        this.version = version;
+    }
+
+
+    public SimpleEntityRef( EntityRef entityRef ) {
+        this.id = entityRef.getId();
+        this.version = entityRef.getVersion(); 
+    }
+
+
+    public static EntityRef ref() {
+        return new SimpleEntityRef( null, null );
+    }
+
+    public static EntityRef ref( Id id ) {
+        return new SimpleEntityRef( id, null );
+    }
+
+    public static EntityRef ref( Id id, UUID version ) {
+        return new SimpleEntityRef(  id, version );
+    }
+
+
+    public static EntityRef ref( EntityRef ref ) {
+        return new SimpleEntityRef( ref );
+    }
+
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
+        result = prime * result + ( ( version == null ) ? 0 : version.hashCode() );
+        return result;
+    }
+
+
+    @Override
+    public boolean equals( Object obj ) {
+        if ( this == obj ) {
+            return true;
+        }
+        if ( obj == null ) {
+            return false;
+        }
+        if ( getClass() != obj.getClass() ) {
+            return false;
+        }
+        SimpleEntityRef other = ( SimpleEntityRef ) obj;
+        if ( id == null ) {
+            if ( other.id != null ) {
+                return false;
+            }
+        }
+        else if ( !id.equals( other.id ) ) {
+            return false;
+        }
+        if ( version == null ) {
+            if ( other.version != null ) {
+                return false;
+            }
+        }
+        else if ( !version.equals( other.version ) ) {
+            return false;
+        }
+        return true;
+    }
+
+
+    @Override
+    public String toString() {
+        return id.toString() + "|" + version.toString();
+    }
+
+    public static Id getId( EntityRef ref ) {
+        if ( ref == null ) {
+            return null;
+        }
+        return ref.getId();
+    }
+
+
+    public static String getType( EntityRef ref ) {
+        if ( ref == null ) {
+            return null;
+        }
+        return ref.getId().getType();
+    }
+
+    public Id getId() {
+        return id;
+    }
+
+    public UUID getVersion() {
+        return version;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/AndOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/AndOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/AndOperand.java
new file mode 100644
index 0000000..88e1d38
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/AndOperand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class AndOperand extends BooleanOperand {
+
+    public AndOperand() {
+        super( new CommonToken( 0, "and" ) );
+    }
+
+
+    public AndOperand( Token t ) {
+        super( t );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanLiteral.java
new file mode 100644
index 0000000..87adeaf
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanLiteral.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class BooleanLiteral extends Literal<Boolean> {
+
+    private boolean value;
+
+
+    /**
+     * @param t
+     */
+    protected BooleanLiteral( Token t ) {
+        super( t );
+        value = Boolean.valueOf( t.getText() );
+    }
+
+
+    /** The boolean literal */
+    public BooleanLiteral( boolean value ) {
+        super( new ClassicToken( 0, String.valueOf( value ) ) );
+        this.value = value;
+    }
+
+
+    public Boolean getValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanOperand.java
new file mode 100644
index 0000000..9c5324c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/BooleanOperand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+
+
+/**
+ * A base class for any equality expression.  Expressions must have a property and a value. Examples are >=, >, =, <,
+ * <=,
+ *
+ * @author tnine
+ */
+public abstract class BooleanOperand extends Operand {
+
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public BooleanOperand( Token t ) {
+        super( t );
+    }
+
+
+    public Operand getLeft() {
+        return ( Operand ) this.children.get( 0 );
+    }
+
+
+    public Operand getRight() {
+        return ( Operand ) this.children.get( 1 );
+    }
+}


[25/27] git commit: Use 2.0.0-SNAPSHOT version in Core Persistence too.

Posted by sn...@apache.org.
Use 2.0.0-SNAPSHOT version in Core Persistence too.


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

Branch: refs/heads/entity-manager
Commit: 9caf38bdeee5363afa11f8dab7a49c843358c29a
Parents: 17c2ac4
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 27 12:24:55 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 27 12:24:55 2014 -0400

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml | 2 +-
 stack/corepersistence/graph/pom.xml      | 3 ++-
 stack/corepersistence/model/pom.xml      | 2 +-
 stack/corepersistence/perftest1/pom.xml  | 2 +-
 stack/corepersistence/perftest2/pom.xml  | 4 ++--
 stack/corepersistence/pom.xml            | 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/collection/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml
index 038fb67..d442c6d 100644
--- a/stack/corepersistence/collection/pom.xml
+++ b/stack/corepersistence/collection/pom.xml
@@ -6,7 +6,7 @@
     <parent>
         <artifactId>persistence</artifactId>
         <groupId>org.apache.usergrid</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>2.0.0-SNAPSHOT</version>
     </parent>
 
     <modelVersion>4.0.0</modelVersion>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/graph/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/pom.xml b/stack/corepersistence/graph/pom.xml
index 069962d..1abec48 100644
--- a/stack/corepersistence/graph/pom.xml
+++ b/stack/corepersistence/graph/pom.xml
@@ -24,8 +24,9 @@
   <parent>
     <artifactId>persistence</artifactId>
     <groupId>org.apache.usergrid</groupId>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
   </parent>
+  
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>graph</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/model/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/pom.xml b/stack/corepersistence/model/pom.xml
index 8a7af5b..42d64ec 100644
--- a/stack/corepersistence/model/pom.xml
+++ b/stack/corepersistence/model/pom.xml
@@ -5,7 +5,7 @@
     <parent>
         <artifactId>persistence</artifactId>
         <groupId>org.apache.usergrid</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>2.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/perftest1/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/perftest1/pom.xml b/stack/corepersistence/perftest1/pom.xml
index 64e76f7..08f5513 100644
--- a/stack/corepersistence/perftest1/pom.xml
+++ b/stack/corepersistence/perftest1/pom.xml
@@ -6,7 +6,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.usergrid</groupId>
     <artifactId>perftest1</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <properties>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/perftest2/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/perftest2/pom.xml b/stack/corepersistence/perftest2/pom.xml
index 34ef45f..979f427 100644
--- a/stack/corepersistence/perftest2/pom.xml
+++ b/stack/corepersistence/perftest2/pom.xml
@@ -6,7 +6,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.usergrid</groupId>
     <artifactId>perftest2</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <properties>
@@ -20,7 +20,7 @@
         <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>queryindex</artifactId>
-            <version>1.0-SNAPSHOT</version>
+            <version>2.0.0-SNAPSHOT</version>
             <type>jar</type>
         </dependency>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 9a9b7d3..0d4f13f 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -10,7 +10,7 @@
     <groupId>org.apache.usergrid</groupId>
     <artifactId>persistence</artifactId>
     <packaging>pom</packaging>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
 
     <properties>
 


[22/27] Updated tests. Need to figure a work around for Mockito

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
new file mode 100644
index 0000000..3105c7f
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
@@ -0,0 +1,1497 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.usergrid.persistence.graph;
+
+
+import java.util.Iterator;
+import java.util.UUID;
+
+import org.jukito.All;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Inject;
+
+import rx.Observable;
+
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
+public class GraphManagerIT {
+
+
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
+
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+
+    @Inject
+    protected GraphManagerFactory emf;
+
+    protected OrganizationScope scope;
+
+
+    @Before
+    public void setup() {
+        scope = mock( OrganizationScope.class );
+
+        Id orgId = mock( Id.class );
+
+        when( orgId.getType() ).thenReturn( "organization" );
+        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
+
+        when( scope.getOrganization() ).thenReturn( orgId );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeSource() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().last();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getSourceNode(), edge.getType() + "invalid", edge.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTarget() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionSource() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTarget() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    /**
+     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
+     */
+    @Test
+    public void testWriteReadEdgeTypeVersionSourceDistinct() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTargetDistinct() {
+
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingSource() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+        final Id sourceId = createId( "source" );
+
+
+        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //still edge 3 is our max version, but we start with edge 2 as our last read
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge1, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingTarget() {
+
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        final Id targetId = createId( "target" );
+
+        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge1, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeSource() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeTarget() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteSource() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        final SearchByEdge searchByEdge = createGetByEdge(edge.getSourceNode(), edge.getType(), edge.getTargetNode(), edge.getVersion(), null);
+
+        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().single();
+
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        returned = em.deleteEdge( edge ).toBlockingObservable().last();
+
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().singleOrDefault(null);
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteTarget() {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        em.deleteEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypes() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        Observable<String> edges =
+                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+
+        //now get types for test2
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypes() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId1 = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get types for test2
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypesPaging() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
+
+        edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get the next page
+
+        edges = em.getIdTypesFromSource(
+                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypesPaging() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
+
+        edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now get the next page
+
+        edges = em.getIdTypesToTarget(
+                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testMarkSourceEdges() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdges() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges =
+                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkSourceEdgesType() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdgesType() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
+                        null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void markSourceNode() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( sourceId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test
+    public void markTargetNode() {
+
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( targetId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test(expected = NullPointerException.class)
+    public void invalidEdgeTypesWrite( @All Edge edge ) {
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        em.writeEdge( edge );
+    }
+
+
+    @Test(expected = NullPointerException.class)
+    public void invalidEdgeTypesDelete( @All Edge edge ) {
+        final GraphManager em = emf.createEdgeManager( scope );
+
+        em.deleteEdge( edge );
+    }
+
+    //
+    //    public static class InvalidInput extends JukitoModule {
+    //
+    //        @Override
+    //        protected void configureTest() {
+    //create all edge types of junk input
+    //
+    //            final UUID version = UUIDGenerator.newTimeUUID();
+    //
+    //            Id nullUuid = mock( Id.class );
+    //            when( nullUuid.getUuid() ).thenReturn( null );
+    //
+    //
+    //            Id nullType = mock( Id.class );
+    //            when( nullType.getType() ).thenReturn( "type" );
+    //
+    //            Edge[] edges = new Edge[] {
+    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( nullType, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullType, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
+    //            };
+    //
+    //
+    //            bindManyInstances( Edge.class, edges );
+    //
+    //        }
+    //
+    //
+    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
+    //            Edge edge = mock( Edge.class );
+    //
+    //            when( edge.getSourceNode() ).thenReturn( sourceId );
+    //            when( edge.getType() ).thenReturn( type );
+    //            when( edge.getTargetNode() ).thenReturn( targetId );
+    //            when( edge.getVersion() ).thenReturn( version );
+    //
+    //            return edge;
+    //        }
+    //    }
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerStressTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerStressTest.java
new file mode 100644
index 0000000..a493029
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerStressTest.java
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.usergrid.persistence.graph;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang3.time.StopWatch;
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Inject;
+
+import rx.Observable;
+import rx.Subscriber;
+
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestGraphModule.class)
+public class GraphManagerStressTest {
+    private static final Logger log = LoggerFactory.getLogger( GraphManagerStressTest.class );
+
+    @Inject
+    private GraphManagerFactory factory;
+
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+
+    protected OrganizationScope scope;
+
+
+    @Before
+    public void setup() {
+        scope = mock( OrganizationScope.class );
+
+        Id orgId = mock( Id.class );
+
+        when( orgId.getType() ).thenReturn( "organization" );
+        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
+
+        when( scope.getOrganization() ).thenReturn( orgId );
+    }
+
+
+    @Test
+    @Ignore
+    public void writeThousands() throws InterruptedException {
+        EdgeGenerator generator = new EdgeGenerator() {
+
+            private Set<Id> sourceIds = new HashSet<Id>();
+
+
+            @Override
+            public Edge newEdge() {
+                Edge edge = createEdge( "source", "test", "target" );
+
+                sourceIds.add( edge.getSourceNode() );
+
+                return edge;
+            }
+
+
+            @Override
+            public Observable<Edge> doSearch( final GraphManager manager ) {
+
+
+                final UUID uuid = UUIDGenerator.newTimeUUID();
+
+
+                return Observable.create( new Observable.OnSubscribe<Edge>() {
+
+                    @Override
+                    public void call( final Subscriber<? super Edge> subscriber ) {
+                        try {
+                            for ( Id sourceId : sourceIds ) {
+
+                                final Iterable<Edge> edges = manager.loadEdgesFromSource(
+                                        new SimpleSearchByEdgeType( sourceId, "test", uuid, null ) )
+                                                                    .toBlockingObservable().toIterable();
+
+                                for ( Edge edge : edges ) {
+                                    log.debug( "Firing on next for edge {}", edge );
+
+                                    subscriber.onNext( edge );
+                                }
+                            }
+                        }
+                        catch ( Throwable throwable ) {
+                            subscriber.onError( throwable );
+                        }
+                    }
+                } );
+
+
+                //TODO T.N keep this code it's exhibiting a failure /exception swallowing with RX when our scheduler
+                // is full
+                //
+                //              return  Observable.create( new Observable.OnSubscribe<Edge>() {
+                //
+                //                    @Override
+                //                    public void call( final Subscriber<? super Edge> subscriber ) {
+                //                        for ( Id sourceId : sourceIds ) {
+                //
+                //                                            final Observable<Edge> edges =
+                //                                                    manager.loadEdgesFromSource( new
+                // SimpleSearchByEdgeType( sourceId, "test", uuid, null ) );
+                //
+                //                            edges.subscribe( new Action1<Edge>() {
+                //                                @Override
+                //                                public void call( final Edge edge ) {
+                //                                    subscriber.onNext( edge );
+                //                                }
+                //                            },
+                //
+                //                            new Action1<Throwable>() {
+                //                                @Override
+                //                                public void call( final Throwable throwable ) {
+                //                                    subscriber.onError( throwable );
+                //                                }
+                //                            });
+                //                         }
+                //                    }
+                //                } ) ;
+
+
+            }
+        };
+
+        doTest( generator );
+    }
+
+
+    @Ignore
+    @Test
+    public void writeThousandsSingleSource() throws InterruptedException {
+        EdgeGenerator generator = new EdgeGenerator() {
+
+            private Id sourceId = createId( "source" );
+
+
+            @Override
+            public Edge newEdge() {
+                Edge edge = createEdge( sourceId, "test", createId( "target" ) );
+
+
+                return edge;
+            }
+
+
+            @Override
+            public Observable<Edge> doSearch( final GraphManager manager ) {
+                UUID uuid = UUIDGenerator.newTimeUUID();
+
+                return manager.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceId, "test", uuid, null ) );
+            }
+        };
+
+        doTest( generator );
+    }
+
+
+    @Test
+    @Ignore
+    public void writeThousandsSingleTarget() throws InterruptedException {
+        EdgeGenerator generator = new EdgeGenerator() {
+
+            private Id targetId = createId( "target" );
+
+
+            @Override
+            public Edge newEdge() {
+                Edge edge = createEdge( createId( "source" ), "test", targetId );
+
+
+                return edge;
+            }
+
+
+            @Override
+            public Observable<Edge> doSearch( final GraphManager manager ) {
+                UUID uuid = UUIDGenerator.newTimeUUID();
+
+                return manager.loadEdgesToTarget( new SimpleSearchByEdgeType( targetId, "test", uuid, null ) );
+            }
+        };
+
+        doTest( generator );
+    }
+
+
+    /**
+     * Execute the test with the generator
+     */
+    private void doTest( EdgeGenerator generator ) throws InterruptedException {
+        GraphManager manager = factory.createEdgeManager( scope );
+
+        int limit = 10000;
+
+        final StopWatch timer = new StopWatch();
+        timer.start();
+        final Set<Edge> ids = new HashSet<Edge>( limit );
+
+        for ( int i = 0; i < limit; i++ ) {
+
+            Edge edge = generator.newEdge();
+
+            Edge returned = manager.writeEdge( edge ).toBlockingObservable().last();
+
+
+            assertNotNull( "Returned has a version", returned.getVersion() );
+
+            ids.add( returned );
+
+            if ( i % 1000 == 0 ) {
+                log.info( "   Wrote: " + i );
+            }
+        }
+
+        timer.stop();
+        log.info( "Total time to write {} entries {}ms", limit, timer.getTime() );
+        timer.reset();
+
+        timer.start();
+
+        final CountDownLatch latch = new CountDownLatch( 1 );
+
+
+        generator.doSearch( manager ).subscribe( new Subscriber<Edge>() {
+            @Override
+            public void onCompleted() {
+                timer.stop();
+                latch.countDown();
+            }
+
+
+            @Override
+            public void onError( final Throwable throwable ) {
+                fail( "Exception occurced " + throwable );
+            }
+
+
+            @Override
+            public void onNext( final Edge edge ) {
+                ids.remove( edge );
+            }
+        } );
+
+
+        latch.await();
+
+
+        assertEquals( 0, ids.size() );
+
+
+        log.info( "Total time to read {} entries {}ms", limit, timer.getTime() );
+    }
+
+
+    private interface EdgeGenerator {
+
+        /**
+         * Create a new edge to persiste
+         */
+        public Edge newEdge();
+
+        public Observable<Edge> doSearch( final GraphManager manager );
+    }
+}


[15/27] Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
new file mode 100644
index 0000000..b952d13
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class ContainsOperand extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public ContainsOperand( Token t ) {
+        super( t );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+
+
+    public StringLiteral getString() {
+        return ( StringLiteral ) getLiteral();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#newProperty(java.lang.String)
+     */
+    @Override
+    protected Property newProperty( String name ) {
+        return new ContainsProperty( name );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#getProperty()
+     */
+    @Override
+    public ContainsProperty getProperty() {
+        return ( ContainsProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
new file mode 100644
index 0000000..0c282ac
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property for full text searching that requires special renaming
+ *
+ * @author tnine
+ */
+public class ContainsProperty extends Property {
+
+    private String indexedName = null;
+
+
+    public ContainsProperty( Token t ) {
+        super( t );
+        this.indexedName = String.format( "%s.keywords", super.getValue() );
+    }
+
+
+    public ContainsProperty( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.Property#getIndexedValue()
+     */
+    @Override
+    public String getIndexedValue() {
+        return this.indexedName;
+    }
+
+
+    /** @return the property */
+    public ContainsProperty getProperty() {
+        return ( ContainsProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
new file mode 100644
index 0000000..0769f39
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class Equal extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public Equal( Token t ) {
+        super( t );
+    }
+
+
+    public Equal() {
+        super( new ClassicToken( 0, "=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
new file mode 100644
index 0000000..3ae654d
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+
+
+/**
+ * A base class for any equality expression. Expressions must have a property and a value. Examples are >=, >, =, <,
+ * <=,
+ *
+ * @author tnine
+ */
+public abstract class EqualityOperand extends Operand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public EqualityOperand( Token t ) {
+        super( t );
+    }
+
+
+    public EqualityOperand( String propName, Literal<?> value ) {
+        super( null );
+    }
+
+
+    /** Set the property on this operand */
+    public void setProperty( String name ) {
+        setAtIndex( 0, newProperty( name ) );
+    }
+
+
+    /** Get the property to set into the equality. Allows subclasses to override the type */
+    protected Property newProperty( String name ) {
+        return new Property( name );
+    }
+
+
+    /** Set the literal on this operand from the given value */
+    public void setLiteral( Object value ) {
+        setAtIndex( 1, LiteralFactory.getLiteral( value ) );
+    }
+
+
+    /** Set the child at the specified index. If it doesn't exist, it's added until it does */
+    @SuppressWarnings("unchecked")
+    private void setAtIndex( int index, Literal<?> value ) {
+
+        if ( children == null ) {
+            children = createChildrenList();
+        }
+
+        while ( children.size() - 1 < index ) {
+            children.add( null );
+        }
+
+        setChild( index, value );
+    }
+
+
+    /** @return the property */
+    public Property getProperty() {
+        return ( Property ) this.children.get( 0 );
+    }
+
+
+    /** @return the literal */
+    public Literal<?> getLiteral() {
+        return ( Literal<?> ) this.children.get( 1 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
new file mode 100644
index 0000000..eaec4d4
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class FloatLiteral extends Literal<Float> implements NumericLiteral {
+
+    private float value;
+
+
+    /**
+     * @param t
+     */
+    public FloatLiteral( Token t ) {
+        super( t );
+        value = Float.valueOf( t.getText() );
+    }
+
+
+    public FloatLiteral( float f ) {
+        super( new ClassicToken( 0, String.valueOf( f ) ) );
+        value = f;
+    }
+
+
+    /** @return the value */
+    public Float getValue() {
+        return value;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
+     */
+    @Override
+    public float getFloatValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
new file mode 100644
index 0000000..fd8e628
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class GreaterThan extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThan( Token t ) {
+        super( t );
+    }
+
+
+    public GreaterThan() {
+        super( new CommonToken( 0, ">" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
new file mode 100644
index 0000000..075c3a8
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class GreaterThanEqual extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThanEqual( Token t ) {
+        super( t );
+    }
+
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThanEqual() {
+        super( new CommonToken( 0, ">=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
new file mode 100644
index 0000000..9113f20
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class LessThan extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public LessThan( Token t ) {
+        super( t );
+    }
+
+
+    public LessThan() {
+        super( new CommonToken( 0, "<" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
new file mode 100644
index 0000000..bc75c78
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class LessThanEqual extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public LessThanEqual( Token t ) {
+        super( t );
+    }
+
+
+    /**
+     */
+    public LessThanEqual() {
+        super( new CommonToken( 0, "<=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
new file mode 100644
index 0000000..cca51f8
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+
+
+/**
+ * Abstract class for literals
+ *
+ * @author tnine
+ */
+public abstract class Literal<V> extends CommonTree {
+
+
+    protected Literal( Token t ) {
+        super( t );
+    }
+
+
+    /** Return the value of the literal the user has passed in */
+    public abstract V getValue();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
new file mode 100644
index 0000000..672a6df
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import java.util.UUID;
+
+
+/**
+ * Simple factory for generating literal instance based on the runtime value
+ *
+ * @author tnine
+ */
+public class LiteralFactory {
+
+    /** Generate the correct literal subclass based on the runtime instance. */
+    public static final Literal<?> getLiteral( Object value ) {
+        if ( value instanceof Integer ) {
+            return new LongLiteral( ( Integer ) value );
+        }
+        if ( value instanceof Long ) {
+            return new LongLiteral( ( Long ) value );
+        }
+
+        if ( value instanceof String ) {
+            return new StringLiteral( ( String ) value );
+        }
+
+        if ( value instanceof Float ) {
+            return new FloatLiteral( ( Float ) value );
+        }
+
+        if ( value instanceof UUID ) {
+            return new UUIDLiteral( ( UUID ) value );
+        }
+
+        if ( value instanceof Boolean ) {
+            return new BooleanLiteral( ( Boolean ) value );
+        }
+
+        throw new UnsupportedOperationException(
+                String.format( "Unsupported type of %s was passed when trying to construct a literal",
+                        value.getClass() ) );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
new file mode 100644
index 0000000..690fb51
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class LongLiteral extends Literal<Long> implements NumericLiteral {
+
+    private long value;
+
+
+    /**
+     * @param t
+     */
+    public LongLiteral( Token t ) {
+        super( t );
+        this.value = Long.valueOf( t.getText() );
+    }
+
+
+    /**
+     *
+     * @param value
+     */
+    public LongLiteral( long value ) {
+        super( new ClassicToken( 0, String.valueOf( value ) ) );
+        this.value = value;
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public Long getValue() {
+        return this.value;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
+     */
+    @Override
+    public float getFloatValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
new file mode 100644
index 0000000..e41e94b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class NotOperand extends Operand {
+
+
+    public NotOperand( Token t ) {
+        super( t );
+    }
+
+
+    /** get the only child operation */
+    public Operand getOperation() {
+        return ( Operand ) this.children.get( 0 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence.query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
new file mode 100644
index 0000000..493a211
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+/** @author tnine */
+public interface NumericLiteral {
+
+    /** Return the value of this numeric literal as a float */
+    public float getFloatValue();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
new file mode 100644
index 0000000..1363941
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/**
+ * Any logical operation should subclass.  Boolean logic, equality, not, contains, within and others are examples of
+ * operands
+ *
+ * @author tnine
+ */
+public abstract class Operand extends CommonTree {
+
+
+    /** Default constructor to take a token */
+    public Operand( Token t ) {
+        super( t );
+    }
+
+
+    /** Get the pointer to the parent node */
+    public Operand getParent() {
+        return ( Operand ) super.getParent();
+    }
+
+
+    /** Visitor method */
+    public abstract void visit( QueryVisitor visitor ) throws PersistenceException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
new file mode 100644
index 0000000..97678bc
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class OrOperand extends BooleanOperand {
+
+    /**
+     * @param left
+     * @param token
+     * @param right
+     */
+    public OrOperand( Token t ) {
+        super( t );
+    }
+
+
+    public OrOperand() {
+        super( new CommonToken( 0, "or" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
new file mode 100644
index 0000000..f9bf67c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property
+ *
+ * @author tnine
+ */
+public class Property extends Literal<String> {
+
+    private String property;
+
+
+    public Property( Token t ) {
+        super( t );
+        this.property = t.getText();
+    }
+
+
+    public Property( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.usergrid.persistence.query.tree.Literal#getValue()
+     */
+    @Override
+    public String getValue() {
+        return this.property;
+    }
+
+
+    /**
+     * Subclasses an override.  Indexed value could be different when stored internally.  By default returns the same
+     * property
+     */
+    public String getIndexedValue() {
+        return this.property;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
new file mode 100644
index 0000000..e12c134
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.apache.usergrid.persistence.index.exceptions.NoFullTextIndexException;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.QueryBuilder;
+
+
+/**
+ * Interface for visiting nodes in our AST as we produce
+ *
+ * @author tnine
+ */
+public interface QueryVisitor {
+
+    /**
+     *
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( AndOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( OrOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( NotOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( LessThan op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoFullTextIndexException
+     */
+    public void visit( ContainsOperand op ) throws NoFullTextIndexException;
+
+    /**
+     * @param op
+     */
+    public void visit( WithinOperand op );
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( LessThanEqual op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( Equal op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( GreaterThan op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( GreaterThanEqual op ) throws NoIndexException;
+
+    /** 
+     * Returns resulting query builder.
+     */
+    public QueryBuilder getQueryBuilder();
+
+	public FilterBuilder getFilterBuilder();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
new file mode 100644
index 0000000..196fcfa
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+import static org.apache.commons.lang.StringUtils.removeEnd;
+
+
+/** @author tnine */
+public class StringLiteral extends Literal<String> {
+
+    private String value;
+    private String finishValue;
+
+
+    /**
+     * @param t
+     */
+    public StringLiteral( Token t ) {
+        super( t );
+        String newValue = t.getText();
+        newValue = newValue.substring( 1, newValue.length() - 1 );
+
+        parseValue( newValue );
+    }
+
+
+    public StringLiteral( String value ) {
+        super( new ClassicToken( 0, value ) );
+        parseValue( value );
+    }
+
+
+    /** Parse the value and set the optional end value */
+    private void parseValue( String value ) {
+
+        this.value = value.trim().toLowerCase();
+
+        if ( "*".equals( value ) ) {
+            this.value = null;
+            this.finishValue = null;
+            return;
+        }
+
+        if ( value != null && value.endsWith( "*" ) ) {
+            this.value = removeEnd( value.toString(), "*" );
+
+            finishValue = this.value + "\uFFFF";
+        }
+        // set the end value to the same as the start value
+        else {
+            finishValue = value;
+        }
+    }
+
+
+    /** If this were a string literal */
+    public String getEndValue() {
+        return this.finishValue;
+    }
+
+
+    public String getValue() {
+        return this.value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
new file mode 100644
index 0000000..0cf91a3
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import java.util.UUID;
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class UUIDLiteral extends Literal<UUID> {
+
+    private UUID value;
+
+
+    /**
+     * @param t
+     */
+    public UUIDLiteral( Token t ) {
+        super( t );
+        value = UUID.fromString( t.getText() );
+    }
+
+
+    public UUIDLiteral( UUID value ) {
+        super( new ClassicToken( 0, String.valueOf( value ) ) );
+        this.value = value;
+    }
+
+
+    public UUID getValue() {
+        return this.value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
new file mode 100644
index 0000000..602fc34
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class WithinOperand extends Operand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public WithinOperand( Token t ) {
+        super( t );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) {
+        visitor.visit( this );
+    }
+
+
+    /**
+     * @param propName
+     */
+    public void setProperty( String propName ) {
+        setChild( 0, new WithinProperty( propName ) );
+    }
+
+
+    /**
+     * @param distance
+     */
+    public void setDistance( float distance ) {
+        setChild( 1, new FloatLiteral( distance ) );
+    }
+
+
+    /**
+     * @param Latitude
+     */
+    public void setLatitude( float Latitude ) {
+        setChild( 2, new FloatLiteral( Latitude ) );
+    }
+
+
+    /**
+     * @param longitude
+     */
+    public void setLongitude( float longitude ) {
+        setChild( 3, new FloatLiteral( longitude ) );
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public WithinProperty getProperty() {
+        return ( WithinProperty ) this.children.get( 0 );
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public NumericLiteral getDistance() {
+        return ( NumericLiteral ) this.children.get( 1 );
+    }
+
+
+    /**
+     * @return
+     */
+    public NumericLiteral getLatitude() {
+        return ( NumericLiteral ) this.children.get( 2 );
+    }
+
+
+    /**
+     * @return
+     */
+    public NumericLiteral getLongitude() {
+        return ( NumericLiteral ) this.children.get( 3 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
new file mode 100644
index 0000000..a9b5899
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property
+ *
+ * @author tnine
+ */
+public class WithinProperty extends Property {
+
+    private String indexedName = null;
+
+
+    public WithinProperty( Token t ) {
+        super( t );
+        this.indexedName = String.format( "%s.coordinates", super.getValue() );
+    }
+
+
+    public WithinProperty( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /** Get the */
+    public String getIndexedName() {
+        return this.indexedName;
+    }
+
+
+    /** @return the property */
+    public WithinProperty getProperty() {
+        return ( WithinProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
new file mode 100644
index 0000000..ab51d55
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class ClassUtils extends org.apache.commons.lang.ClassUtils {
+
+    @SuppressWarnings("unchecked")
+    public static <A, B> B cast( A a ) {
+        return ( B ) a;
+    }
+
+
+    @SuppressWarnings("unchecked")
+    private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>(
+            Arrays.asList( Boolean.class, Byte.class, Character.class, Double.class, Float.class, Integer.class,
+                    Long.class, Short.class, Void.class ) );
+
+
+    public static boolean isWrapperType( Class<?> clazz ) {
+        return WRAPPER_TYPES.contains( clazz );
+    }
+
+
+    public static boolean isPrimitiveType( Class<?> clazz ) {
+        if ( clazz == null ) {
+            return false;
+        }
+        return clazz.isPrimitive() || isWrapperType( clazz );
+    }
+
+
+    public static boolean isBasicType( Class<?> clazz ) {
+        if ( clazz == null ) {
+            return false;
+        }
+        return ( String.class.isAssignableFrom( clazz ) ) || isPrimitiveType( clazz );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
new file mode 100644
index 0000000..503d597
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
@@ -0,0 +1,765 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence.index.utils;
+
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang.math.NumberUtils;
+
+
+/** Convenience methods for converting to and from formats, primarily between byte arrays and UUIDs, Strings,
+ * and Longs. */
+public class ConversionUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger( ConversionUtils.class );
+
+    /**
+     *
+     */
+    public static final String UTF8_ENCODING = "UTF-8";
+
+    /**
+     *
+     */
+    public static final String ASCII_ENCODING = "US-ASCII";
+
+    public static final ByteBuffer HOLDER = ByteBuffer.wrap( new byte[] { 0 } );
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static UUID uuid( byte[] uuid ) {
+        return uuid( uuid, 0 );
+    }
+
+
+    /**
+     * @param uuid
+     * @param offset
+     * @return
+     */
+    public static UUID uuid( byte[] uuid, int offset ) {
+        ByteBuffer bb = ByteBuffer.wrap( uuid, offset, 16 );
+        return new UUID( bb.getLong(), bb.getLong() );
+    }
+
+
+    public static UUID uuid( ByteBuffer bb ) {
+        if ( bb == null ) {
+            return null;
+        }
+        if ( bb.remaining() < 16 ) {
+            return null;
+        }
+        bb = bb.slice();
+        return new UUID( bb.getLong(), bb.getLong() );
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static UUID uuid( String uuid ) {
+        try {
+            return UUID.fromString( uuid );
+        }
+        catch ( Exception e ) {
+            logger.error( "Bad UUID", e );
+        }
+        return UUIDUtils.ZERO_UUID;
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static UUID uuid( Object obj ) {
+        return uuid( obj, UUIDUtils.ZERO_UUID );
+    }
+
+
+    public static UUID uuid( Object obj, UUID defaultValue ) {
+        if ( obj instanceof UUID ) {
+            return ( UUID ) obj;
+        }
+        else if ( obj instanceof byte[] ) {
+            return uuid( ( byte[] ) obj );
+        }
+        else if ( obj instanceof ByteBuffer ) {
+            return uuid( ( ByteBuffer ) obj );
+        }
+        else if ( obj instanceof String ) {
+            return uuid( ( String ) obj );
+        }
+        return defaultValue;
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static byte[] bytes( UUID uuid ) {
+        if ( uuid == null ) {
+            return null;
+        }
+        long msb = uuid.getMostSignificantBits();
+        long lsb = uuid.getLeastSignificantBits();
+        byte[] buffer = new byte[16];
+
+        for ( int i = 0; i < 8; i++ ) {
+            buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) );
+        }
+        for ( int i = 8; i < 16; i++ ) {
+            buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) );
+        }
+
+        return buffer;
+    }
+
+
+    public static ByteBuffer bytebuffer( UUID uuid ) {
+        if ( uuid == null ) {
+            return null;
+        }
+        return ByteBuffer.wrap( bytes( uuid ) );
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static byte[] uuidToBytesNullOk( UUID uuid ) {
+        if ( uuid != null ) {
+            return bytes( uuid );
+        }
+        return new byte[16];
+    }
+
+
+    /**
+     * @param s
+     * @return
+     */
+    public static byte[] bytes( String s ) {
+        return bytes( s, UTF8_ENCODING );
+    }
+
+
+    public static ByteBuffer bytebuffer( String s ) {
+        return ByteBuffer.wrap( bytes( s ) );
+    }
+
+
+    /**
+     * @param s
+     * @return
+     */
+    public static byte[] ascii( String s ) {
+        if ( s == null ) {
+            return new byte[0];
+        }
+        return bytes( s, ASCII_ENCODING );
+    }
+
+
+    public ByteBuffer asciibuffer( String s ) {
+        return ByteBuffer.wrap( ascii( s ) );
+    }
+
+
+    /**
+     * @param s
+     * @param encoding
+     * @return
+     */
+    public static byte[] bytes( String s, String encoding ) {
+        try {
+            return s.getBytes( encoding );
+        }
+        catch ( UnsupportedEncodingException e ) {
+            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    public static byte[] bytes( ByteBuffer bb ) {
+        byte[] b = new byte[bb.remaining()];
+        bb.duplicate().get( b );
+        return b;
+    }
+
+
+    public static ByteBuffer bytebuffer( String s, String encoding ) {
+        return ByteBuffer.wrap( bytes( s, encoding ) );
+    }
+
+
+    /**
+     * @param b
+     * @return
+     */
+    public static byte[] bytes( Boolean b ) {
+        byte[] bytes = new byte[1];
+        bytes[0] = b ? ( byte ) 1 : 0;
+        return bytes;
+    }
+
+
+    public static ByteBuffer bytebuffer( Boolean b ) {
+        return ByteBuffer.wrap( bytes( b ) );
+    }
+
+
+    /**
+     * @param val
+     * @return
+     */
+    public static byte[] bytes( Long val ) {
+        ByteBuffer buf = ByteBuffer.allocate( 8 );
+        buf.order( ByteOrder.BIG_ENDIAN );
+        buf.putLong( val );
+        return buf.array();
+    }
+
+
+    public static ByteBuffer bytebuffer( Long val ) {
+        ByteBuffer buf = ByteBuffer.allocate( 8 );
+        buf.order( ByteOrder.BIG_ENDIAN );
+        buf.putLong( val );
+        return ( ByteBuffer ) buf.rewind();
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static byte[] bytes( Object obj ) {
+        if ( obj == null ) {
+            return new byte[0];
+        }
+        else if ( obj instanceof byte[] ) {
+            return ( byte[] ) obj;
+        }
+        else if ( obj instanceof Long ) {
+            return bytes( ( Long ) obj );
+        }
+        else if ( obj instanceof String ) {
+            return bytes( ( String ) obj );
+        }
+        else if ( obj instanceof UUID ) {
+            return bytes( ( UUID ) obj );
+        }
+        else if ( obj instanceof Boolean ) {
+            return bytes( ( Boolean ) obj );
+        }
+        else if ( obj instanceof Date ) {
+            return bytes( ( ( Date ) obj ).getTime() );
+        }
+        else {
+            return bytes( obj.toString() );
+        }
+    }
+
+
+    public static ByteBuffer bytebuffer( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes );
+    }
+
+
+    public static ByteBuffer bytebuffer( ByteBuffer bytes ) {
+        return bytes.duplicate();
+    }
+
+
+    public static ByteBuffer bytebuffer( Object obj ) {
+        if ( obj instanceof ByteBuffer ) {
+            return ( ( ByteBuffer ) obj ).duplicate();
+        }
+        return ByteBuffer.wrap( bytes( obj ) );
+    }
+
+
+    public static List<ByteBuffer> bytebuffers( List<?> l ) {
+        List<ByteBuffer> results = new ArrayList<ByteBuffer>( l.size() );
+        for ( Object o : l ) {
+            results.add( bytebuffer( o ) );
+        }
+        return results;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static boolean getBoolean( byte[] bytes ) {
+        return bytes[0] != 0;
+    }
+
+
+    public static boolean getBoolean( ByteBuffer bytes ) {
+        return bytes.slice().get() != 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @return
+     */
+    public static boolean getBoolean( byte[] bytes, int offset ) {
+        return bytes[offset] != 0;
+    }
+
+
+    public static boolean getBoolean( Object obj ) {
+        if ( obj instanceof Boolean ) {
+            return ( Boolean ) obj;
+        }
+        else if ( obj instanceof String ) {
+            return Boolean.parseBoolean( ( String ) obj );
+        }
+        else if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).longValue() > 0;
+        }
+
+        return false;
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static String string( Object obj ) {
+        if ( obj instanceof String ) {
+            return ( String ) obj;
+        }
+        else if ( obj instanceof byte[] ) {
+            return string( ( byte[] ) obj );
+        }
+        else if ( obj instanceof ByteBuffer ) {
+            return string( ( ByteBuffer ) obj );
+        }
+        else if ( obj != null ) {
+            return obj.toString();
+        }
+        return null;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static String string( byte[] bytes ) {
+        if ( bytes == null ) {
+            return null;
+        }
+        return string( bytes, 0, bytes.length, UTF8_ENCODING );
+    }
+
+
+    public static String string( ByteBuffer bytes ) {
+        if ( bytes == null ) {
+            return null;
+        }
+        return string( bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF8_ENCODING );
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @param length
+     * @return
+     */
+    public static String string( byte[] bytes, int offset, int length ) {
+        return string( bytes, offset, length, UTF8_ENCODING );
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @param length
+     * @param encoding
+     * @return
+     */
+    public static String string( byte[] bytes, int offset, int length, String encoding ) {
+
+        if ( length <= 0 ) {
+            return "";
+        }
+
+        if ( bytes == null ) {
+            return "";
+        }
+
+        try {
+            return new String( bytes, offset, length, encoding );
+        }
+        catch ( UnsupportedEncodingException e ) {
+            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    public static <T> List<String> strings( Collection<T> items ) {
+        List<String> strings = new ArrayList<String>();
+        for ( T item : items ) {
+            strings.add( string( item ) );
+        }
+        return strings;
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @return
+     */
+    public static String stringFromLong( byte[] bytes, int offset ) {
+        if ( bytes.length == 0 ) {
+            return "";
+        }
+        if ( ( bytes.length - offset ) < 8 ) {
+            throw new IllegalArgumentException( "A long is at least 8 bytes" );
+        }
+        return String.valueOf( ByteBuffer.wrap( bytes, offset, 8 ).getLong() );
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static long getLong( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 8 ).getLong();
+    }
+
+
+    public static long getLong( ByteBuffer bytes ) {
+        return bytes.slice().getLong();
+    }
+
+
+    public static long getLong( Object obj ) {
+        if ( obj instanceof Long ) {
+            return ( Long ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).longValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toLong( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getLong( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getLong( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static int getInt( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 4 ).getInt();
+    }
+
+
+    public static int getInt( ByteBuffer bytes ) {
+        return bytes.slice().getInt();
+    }
+
+
+    public static int getInt( Object obj ) {
+        if ( obj instanceof Integer ) {
+            return ( Integer ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).intValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toInt( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( int ) ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getInt( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getInt( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static float getFloat( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 4 ).getFloat();
+    }
+
+
+    public static float getFloat( ByteBuffer bytes ) {
+        return bytes.slice().getFloat();
+    }
+
+
+    public static float getFloat( Object obj ) {
+        if ( obj instanceof Float ) {
+            return ( Float ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).floatValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toFloat( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getFloat( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getFloat( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    public static double getDouble( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 8 ).getDouble();
+    }
+
+
+    public static double getDouble( ByteBuffer bytes ) {
+        return bytes.slice().getDouble();
+    }
+
+
+    public static double getDouble( Object obj ) {
+        if ( obj instanceof Double ) {
+            return ( Double ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).doubleValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toDouble( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getDouble( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getDouble( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param type
+     * @param bytes
+     * @return
+     */
+    public static Object object( Class<?> type, byte[] bytes ) {
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return getLong( bytes );
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( bytes );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( bytes );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return getBoolean( bytes );
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return getInt( bytes );
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return getDouble( bytes );
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return getFloat( bytes );
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                return bytes;
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    public static Object object( Class<?> type, ByteBuffer bytes ) {
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getLong();
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( bytes );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( bytes );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return bytes.slice().get() != 0;
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getInt();
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getDouble();
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getFloat();
+            }
+            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
+                return bytes.duplicate();
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                byte[] b = new byte[bytes.remaining()];
+                bytes.slice().get( b );
+                return b;
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    /**
+     * @param bb
+     * @param bytes
+     * @param len
+     * @return
+     */
+    public static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ) {
+        if ( len > bytes.length ) {
+            int pos = bb.position();
+            bb.put( bytes );
+            bb.position( pos + len );
+        }
+        else {
+            bb.put( bytes, 0, len );
+        }
+        return bb;
+    }
+
+
+    public static Object coerce( Class<?> type, Object obj ) {
+
+        if ( obj == null ) {
+            return null;
+        }
+
+        if ( type == null ) {
+            return obj;
+        }
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return getLong( obj );
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( obj );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( obj );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return getBoolean( obj );
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return getInt( obj );
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return getDouble( obj );
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return getFloat( obj );
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                return bytes( obj );
+            }
+            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
+                return bytebuffer( obj );
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    public static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ) {
+        for ( Map.Entry<String, Object> entry : values.entrySet() ) {
+            if ( types.containsKey( entry.getKey() ) ) {
+                values.put( entry.getKey(), coerce( types.get( entry.getKey() ), entry.getValue() ) );
+            }
+        }
+        return values;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
new file mode 100644
index 0000000..6de9d39
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+
+package org.apache.usergrid.persistence.index.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.field.BooleanField;
+import org.apache.usergrid.persistence.model.field.DoubleField;
+import org.apache.usergrid.persistence.model.field.EntityObjectField;
+import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.FloatField;
+import org.apache.usergrid.persistence.model.field.IntegerField;
+import org.apache.usergrid.persistence.model.field.ListField;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+
+
+public class EntityBuilder {
+
+    public static Entity fromMap( String scope, Map<String, Object> item ) {
+        return fromMap( scope, null, item );
+    }
+
+    public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
+
+        if ( entity == null ) {
+            entity = new Entity();
+        }
+
+        for ( String fieldName : map.keySet() ) {
+
+            Object value = map.get( fieldName );
+
+            if ( value instanceof String ) {
+                entity.setField( new StringField( fieldName, (String)value ));
+
+            } else if ( value instanceof Boolean ) {
+                entity.setField( new BooleanField( fieldName, (Boolean)value ));
+                        
+            } else if ( value instanceof Integer ) {
+                entity.setField( new IntegerField( fieldName, (Integer)value ));
+
+            } else if ( value instanceof Double ) {
+                entity.setField( new DoubleField( fieldName, (Double)value ));
+
+		    } else if ( value instanceof Float ) {
+                entity.setField( new FloatField( fieldName, (Float)value ));
+				
+            } else if ( value instanceof Long ) {
+                entity.setField( new LongField( fieldName, (Long)value ));
+
+            } else if ( value instanceof List) {
+                entity.setField( listToListField( scope, fieldName, (List)value ));
+
+            } else if ( value instanceof Map ) {
+
+				Field field = null;
+
+				// is the map really a location element?
+				Map<String, Object> m = (Map<String, Object>)value;
+				if ( m.size() == 2) {
+					Double lat = null;
+					Double lon = null;
+					try {
+						if ( m.get("latitude") != null && m.get("longitude") != null ) {
+							lat = Double.parseDouble( m.get("latitude").toString() );
+							lon = Double.parseDouble( m.get("longitude").toString() );
+
+						} else if ( m.get("lat") != null && m.get("lon") != null ) { 
+							lat = Double.parseDouble( m.get("lat").toString() );
+							lon = Double.parseDouble( m.get("lon").toString() );
+						}
+					} catch ( NumberFormatException ignored ) {}
+
+					if ( lat != null && lon != null ) {
+						field = new LocationField( fieldName, new Location( lat, lon ));
+					}
+				}
+
+				if ( field == null ) { 
+
+					// not a location element, process it as map
+					entity.setField( new EntityObjectField( fieldName, 
+						fromMap( scope, (Map<String, Object>)value ))); // recursion
+
+				} else {
+					entity.setField( field );
+				}
+	
+			} else {
+                throw new RuntimeException("Unknown type " + value.getClass().getName());
+            }
+        }
+
+        return entity;
+    }
+
+    
+    private static ListField listToListField( String scope, String fieldName, List list ) {
+
+        if (list.isEmpty()) {
+            return new ListField( fieldName );
+        }
+
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            return new ListField<Entity>( fieldName, processListForField( scope, list ));
+
+        } else if ( sample instanceof List ) {
+            return new ListField<List>( fieldName, processListForField( scope, list ));
+            
+        } else if ( sample instanceof String ) {
+            return new ListField<String>( fieldName, (List<String>)list );
+                    
+        } else if ( sample instanceof Boolean ) {
+            return new ListField<Boolean>( fieldName, (List<Boolean>)list );
+                    
+        } else if ( sample instanceof Integer ) {
+            return new ListField<Integer>( fieldName, (List<Integer>)list );
+
+        } else if ( sample instanceof Double ) {
+            return new ListField<Double>( fieldName, (List<Double>)list );
+
+        } else if ( sample instanceof Long ) {
+            return new ListField<Long>( fieldName, (List<Long>)list );
+
+        } else {
+            throw new RuntimeException("Unknown type " + sample.getClass().getName());
+        }
+    }
+
+    
+    private static List processListForField( String scope, List list ) {
+        if ( list.isEmpty() ) {
+            return list;
+        }
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            List<Entity> newList = new ArrayList<Entity>();
+            for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
+                newList.add( fromMap( scope, map ) );
+            }
+            return newList;
+
+        } else if ( sample instanceof List ) {
+            return processListForField( scope, list ); // recursion
+            
+        } else { 
+            return list;
+        } 
+    }
+
+
+}


[02/27] git commit: Pushed Hystrix down to actual read execution of RowQuery. Still not desired behavior

Posted by sn...@apache.org.
Pushed Hystrix down to actual read execution of RowQuery.  Still not desired behavior


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

Branch: refs/heads/entity-manager
Commit: c1e7a33eba78d3308e67cd8b9a6fe1ea40b5721c
Parents: 5cadb9f
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Mar 19 16:16:46 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Mar 19 16:16:46 2014 -0700

----------------------------------------------------------------------
 .../graph/impl/EdgeDeleteListener.java          |  2 +-
 .../persistence/graph/impl/EdgeManagerImpl.java | 16 +++---
 .../graph/impl/EdgeWriteListener.java           |  2 +-
 .../graph/impl/NodeDeleteListener.java          |  8 +--
 .../graph/impl/stage/AbstractEdgeRepair.java    |  4 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |  8 +--
 .../impl/EdgeMetadataSerializationImpl.java     | 17 +++---
 .../impl/EdgeSerializationImpl.java             | 21 ++++----
 .../impl/parse/ColumnNameIterator.java          | 55 ++++++++++++--------
 .../impl/parse/ObservableIterator.java          | 48 +++++------------
 10 files changed, 88 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
index d377882..a5715c9 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
@@ -76,7 +76,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
 
 
                 //go through every version of this edge <= the current version and remove it
-                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>( ) {
                     @Override
                     protected Iterator<MarkedEdge> getIterator() {
                         return edgeSerialization.getEdgeToTarget( scope,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
index 9e529c5..f825767 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
@@ -201,7 +201,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
@@ -220,7 +220,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
@@ -240,7 +240,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
@@ -258,7 +258,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
@@ -276,7 +276,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>( ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -287,7 +287,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>( ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
@@ -299,7 +299,7 @@ public class EdgeManagerImpl implements EdgeManager {
     @Override
     public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>( ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -310,7 +310,7 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>( ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesToTarget( scope, search );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
index ed8e861..e146ba9 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
@@ -52,7 +52,7 @@ public class EdgeWriteListener implements MessageListener<EdgeEvent<Edge>, EdgeE
         final OrganizationScope scope = write.getOrganizationScope();
         final UUID maxVersion = edge.getVersion();
 
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index 631ac50..0927ba8 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -210,7 +210,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesToTarget( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>(  ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -224,7 +224,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesFromSource( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<String>(  ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -238,7 +238,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesToTarget( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
@@ -252,7 +252,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesFromSource( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index e09d884..fb31a33 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -125,7 +125,7 @@ public abstract class AbstractEdgeRepair  {
      */
     private Observable<MarkedEdge> getEdgeVersionsFromSource( final OrganizationScope scope, final Edge edge ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 
@@ -142,7 +142,7 @@ public abstract class AbstractEdgeRepair  {
      */
     private Observable<MarkedEdge> getEdgeVersionsToTarget( final OrganizationScope scope, final Edge edge ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
index c54f485..0bbc91a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
@@ -251,7 +251,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+            return Observable.create( new ObservableIterator<String>( ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
@@ -264,7 +264,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+            return Observable.create( new ObservableIterator<MarkedEdge>( ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesToTargetBySourceType( scope,
@@ -296,7 +296,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>( graphFig.getReadTimeout() ) {
+            return Observable.create( new ObservableIterator<String>( ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
@@ -309,7 +309,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>( graphFig.getReadTimeout() ) {
+            return Observable.create( new ObservableIterator<MarkedEdge>( ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesFromSourceByTargetType( scope,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
index 713c7fe..b230399 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
@@ -37,6 +37,7 @@ import org.apache.usergrid.persistence.collection.astyanax.ScopedRowKey;
 import org.apache.usergrid.persistence.collection.migration.Migration;
 import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.SearchEdgeType;
 import org.apache.usergrid.persistence.graph.SearchIdType;
 import org.apache.usergrid.persistence.graph.serialization.CassandraConfig;
@@ -50,7 +51,6 @@ import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.netflix.astyanax.Keyspace;
 import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.ByteBufferRange;
 import com.netflix.astyanax.model.CompositeBuilder;
 import com.netflix.astyanax.model.CompositeParser;
@@ -111,13 +111,16 @@ public class EdgeMetadataSerializationImpl implements EdgeMetadataSerialization,
 
 
     protected final Keyspace keyspace;
-    private final CassandraConfig graphFig;
+    private final CassandraConfig cassandraConfig;
+    private final GraphFig graphFig;
 
 
 
     @Inject
-    public EdgeMetadataSerializationImpl( final Keyspace keyspace, final CassandraConfig graphFig) {
+    public EdgeMetadataSerializationImpl( final Keyspace keyspace, final CassandraConfig cassandraConfig,
+                                          final GraphFig graphFig ) {
         this.keyspace = keyspace;
+        this.cassandraConfig = cassandraConfig;
         this.graphFig = graphFig;
     }
 
@@ -329,14 +332,14 @@ public class EdgeMetadataSerializationImpl implements EdgeMetadataSerialization,
 
 
         final RangeBuilder rangeBuilder =
-                new RangeBuilder().setLimit( graphFig.getScanPageSize() ).setStart( search.getLast().or( "" ) );
+                new RangeBuilder().setLimit( cassandraConfig.getScanPageSize() ).setStart( search.getLast().or( "" ) );
 
         RowQuery<ScopedRowKey<OrganizationScope, Id>, String> query =
                 keyspace.prepareQuery( cf ).getKey( sourceKey ).autoPaginate( true )
                         .withColumnRange( rangeBuilder.build() );
 
         return new ColumnNameIterator<String, String>( query, PARSER,
-                    search.getLast().isPresent() );
+                    search.getLast().isPresent(), graphFig.getReadTimeout() );
 
     }
 
@@ -367,14 +370,14 @@ public class EdgeMetadataSerializationImpl implements EdgeMetadataSerialization,
 
         //resume from the last if specified.  Also set the range
         final ByteBufferRange searchRange =
-                new RangeBuilder().setLimit( graphFig.getScanPageSize() ).setStart( search.getLast().or( "" ) ).build();
+                new RangeBuilder().setLimit( cassandraConfig.getScanPageSize() ).setStart( search.getLast().or( "" ) ).build();
 
         RowQuery<ScopedRowKey<OrganizationScope, EdgeIdTypeKey>, String> query =
                 keyspace.prepareQuery( cf ).getKey( sourceTypeKey ).autoPaginate( true ).withColumnRange( searchRange );
 
 
        return new ColumnNameIterator<String, String>( query, PARSER,
-                    search.getLast().isPresent() );
+                    search.getLast().isPresent(), graphFig.getReadTimeout() );
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
index 4dc3c8a..7e11206 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
@@ -41,6 +41,7 @@ import org.apache.usergrid.persistence.collection.cassandra.ColumnTypes;
 import org.apache.usergrid.persistence.collection.migration.Migration;
 import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
@@ -59,7 +60,6 @@ import com.google.common.base.Preconditions;
 import com.google.inject.Singleton;
 import com.netflix.astyanax.Keyspace;
 import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.AbstractComposite;
 import com.netflix.astyanax.model.Column;
 import com.netflix.astyanax.model.CompositeBuilder;
@@ -125,19 +125,22 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
     protected final Keyspace keyspace;
-    protected final CassandraConfig graphFig;
+    protected final CassandraConfig cassandraConfig;
+    protected final GraphFig graphFig;
 
 
     @Inject
-    public EdgeSerializationImpl( final Keyspace keyspace, final CassandraConfig graphFig ) {
+    public EdgeSerializationImpl( final Keyspace keyspace, final CassandraConfig cassandraConfig,
+                                  final GraphFig graphFig ) {
         this.keyspace = keyspace;
+        this.cassandraConfig = cassandraConfig;
         this.graphFig = graphFig;
     }
 
 
     @Override
     public MutationBatch writeEdge( final OrganizationScope scope, final Edge edge ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( graphFig.getWriteCL() );;
+        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );;
 
 
         doWrite( scope, edge, new RowOp() {
@@ -156,7 +159,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     @Override
     public MutationBatch markEdge( final OrganizationScope scope, final Edge edge ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( graphFig.getWriteCL() );;
+        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );;
 
 
         doWrite( scope, edge, new RowOp() {
@@ -175,7 +178,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     @Override
     public MutationBatch deleteEdge( final OrganizationScope scope, final Edge edge ) {
-        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( graphFig.getWriteCL());
+        final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );
 
 
         doWrite( scope, edge, new RowOp() {
@@ -477,7 +480,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
          * If the edge is present, we need to being seeking from this
          */
 
-        final RangeBuilder rangeBuilder = new RangeBuilder().setLimit( graphFig.getScanPageSize() );
+        final RangeBuilder rangeBuilder = new RangeBuilder().setLimit( cassandraConfig.getScanPageSize() );
 
 
         //set the range into the search
@@ -487,12 +490,12 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
         RowQuery<ScopedRowKey<OrganizationScope, R>, DirectedEdge> query =
-                keyspace.prepareQuery( cf ).setConsistencyLevel( graphFig.getReadCL() ).getKey( rowKey ).autoPaginate( true )
+                keyspace.prepareQuery( cf ).setConsistencyLevel( cassandraConfig.getReadCL() ).getKey( rowKey ).autoPaginate( true )
                         .withColumnRange( rangeBuilder.build() );
 
 
         return new ColumnNameIterator<DirectedEdge, MarkedEdge>( query, searcher,
-                    searcher.hasPage() );
+                    searcher.hasPage(), graphFig.getReadTimeout() );
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
index 907586c..b6d17c6 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
@@ -4,21 +4,24 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.Column;
 import com.netflix.astyanax.query.RowQuery;
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommandProperties;
 
 
 /**
- *
- * Simple iterator that wraps a Row query and will keep executing it's paging until there are no more
- * results to read from cassandra
- *
- *
+ * Simple iterator that wraps a Row query and will keep executing it's paging until there are no more results to read
+ * from cassandra
  */
 public class ColumnNameIterator<C, T> implements Iterable<T>, Iterator<T> {
 
 
+    private static final HystrixCommandGroupKey GROUP_KEY = HystrixCommandGroupKey.Factory.asKey( "CassRead" );
+
+    private final int executionTimeout;
+
 
     private final RowQuery<?, C> rowQuery;
     private final ColumnParser<C, T> parser;
@@ -26,21 +29,21 @@ public class ColumnNameIterator<C, T> implements Iterable<T>, Iterator<T> {
     private Iterator<Column<C>> sourceIterator;
 
 
-
-    public ColumnNameIterator( RowQuery<?, C> rowQuery, final ColumnParser<C, T> parser, final boolean skipFirst ) {
+    public ColumnNameIterator( RowQuery<?, C> rowQuery, final ColumnParser<C, T> parser, final boolean skipFirst,
+                               final int executionTimeout ) {
         this.rowQuery = rowQuery.autoPaginate( true );
         this.parser = parser;
+        this.executionTimeout = executionTimeout;
 
         advanceIterator();
 
         //if we are to skip the first element, we need to advance the iterator
-        if(skipFirst && sourceIterator.hasNext()){
+        if ( skipFirst && sourceIterator.hasNext() ) {
             sourceIterator.next();
         }
     }
 
 
-
     @Override
     public Iterator<T> iterator() {
         return this;
@@ -50,8 +53,8 @@ public class ColumnNameIterator<C, T> implements Iterable<T>, Iterator<T> {
     @Override
     public boolean hasNext() {
         //if we've exhausted this iterator, try to advance to the next set
-        if(sourceIterator.hasNext()){
-           return true;
+        if ( sourceIterator.hasNext() ) {
+            return true;
         }
 
         //advance the iterator, to the next page, there could be more
@@ -64,29 +67,37 @@ public class ColumnNameIterator<C, T> implements Iterable<T>, Iterator<T> {
     @Override
     public T next() {
 
-        if(!hasNext()){
+        if ( !hasNext() ) {
             throw new NoSuchElementException();
         }
 
-        return parser.parseColumn(sourceIterator.next());
+        return parser.parseColumn( sourceIterator.next() );
     }
 
 
     @Override
     public void remove() {
-       sourceIterator.remove();
+        sourceIterator.remove();
     }
 
 
     /**
      * Execute the query again and set the reuslts
      */
-    private void advanceIterator(){
-        try {
-            sourceIterator = rowQuery.execute().getResult().iterator();
-        }
-        catch ( ConnectionException e ) {
-            throw new RuntimeException("Unable to execute query", e);
-        }
+    private void advanceIterator() {
+
+        //run producing the values within a hystrix command.  This way we'll time out if the read takes too long
+        sourceIterator = new HystrixCommand<Iterator<Column<C>>>( HystrixCommand.Setter.withGroupKey( GROUP_KEY )
+                                                                                .andCommandPropertiesDefaults(
+                                                                                        HystrixCommandProperties
+                                                                                                .Setter()
+                                                                                                .withExecutionIsolationThreadTimeoutInMilliseconds(
+                                                                                                        executionTimeout ) ) ) {
+
+            @Override
+            protected Iterator<Column<C>> run() throws Exception {
+                return rowQuery.execute().getResult().iterator();
+            }
+        }.execute();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c1e7a33e/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
index c70dc4c..2274868 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
@@ -3,65 +3,43 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 
 import java.util.Iterator;
 
-import com.netflix.hystrix.HystrixCommand;
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import com.netflix.hystrix.HystrixCommandProperties;
-
 import rx.Observable;
+import rx.Observer;
 import rx.Subscriber;
+import rx.Subscription;
+import rx.subscriptions.Subscriptions;
 
 
 /**
  * Converts an iterator to an observable.  Subclasses need to only implement getting the iterator from the data source.
- * This is used in favor of "Observable.just" when the initial fetch of the iterator will require I/O.  This allows us
- * to wrap the iterator in a deferred invocation to avoid the blocking on construction.
+ * This is used in favor of "Observable.just" when the initial fetch of the iterator will require I/O.  This allows
+ * us to wrap the iterator in a deferred invocation to avoid the blocking on construction.
  */
 public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T> {
 
-    private static final HystrixCommandGroupKey GROUP_KEY = HystrixCommandGroupKey.Factory.asKey( "CassRead" );
-
-    private final int executionTimeout;
-
-
-    protected ObservableIterator( final int executionTimeout ) {
-        this.executionTimeout = executionTimeout;
-    }
-
 
     @Override
     public void call( final Subscriber<? super T> subscriber ) {
 
 
         try {
-            //run producing the values within a hystrix command.  This way we'll time out if the read takes too long
-            new HystrixCommand<Void>( HystrixCommand.Setter.withGroupKey( GROUP_KEY ).andCommandPropertiesDefaults(
-                    HystrixCommandProperties.Setter()
-                                            .withExecutionIsolationThreadTimeoutInMilliseconds( executionTimeout ) ) ) {
+            //get our iterator and push data to the observer
+            Iterator<T> itr = getIterator();
 
 
-                @Override
-                protected Void run() throws Exception {
-                    //get our iterator and push data to the observer
-                    final Iterator<T> itr = getIterator();
+            //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
+            while ( itr.hasNext() && !subscriber.isUnsubscribed()) {
+                subscriber.onNext( itr.next() );
+            }
 
-
-                    //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
-                    while ( itr.hasNext() && !subscriber.isUnsubscribed() ) {
-                        subscriber.onNext( itr.next() );
-                    }
-
-
-                    subscriber.onCompleted();
-
-                    return null;
-                }
-            }.execute();
+            subscriber.onCompleted();
         }
 
         //if any error occurs, we need to notify the observer so it can perform it's own error handling
         catch ( Throwable t ) {
             subscriber.onError( t );
         }
+
     }
 
 


[26/27] git commit: Use 2.0.0-SNAPSHOT version in Core Persistence too.

Posted by sn...@apache.org.
Use 2.0.0-SNAPSHOT version in Core Persistence too.


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

Branch: refs/heads/two-dot-o
Commit: 9caf38bdeee5363afa11f8dab7a49c843358c29a
Parents: 17c2ac4
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 27 12:24:55 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 27 12:24:55 2014 -0400

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml | 2 +-
 stack/corepersistence/graph/pom.xml      | 3 ++-
 stack/corepersistence/model/pom.xml      | 2 +-
 stack/corepersistence/perftest1/pom.xml  | 2 +-
 stack/corepersistence/perftest2/pom.xml  | 4 ++--
 stack/corepersistence/pom.xml            | 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/collection/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml
index 038fb67..d442c6d 100644
--- a/stack/corepersistence/collection/pom.xml
+++ b/stack/corepersistence/collection/pom.xml
@@ -6,7 +6,7 @@
     <parent>
         <artifactId>persistence</artifactId>
         <groupId>org.apache.usergrid</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>2.0.0-SNAPSHOT</version>
     </parent>
 
     <modelVersion>4.0.0</modelVersion>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/graph/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/pom.xml b/stack/corepersistence/graph/pom.xml
index 069962d..1abec48 100644
--- a/stack/corepersistence/graph/pom.xml
+++ b/stack/corepersistence/graph/pom.xml
@@ -24,8 +24,9 @@
   <parent>
     <artifactId>persistence</artifactId>
     <groupId>org.apache.usergrid</groupId>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
   </parent>
+  
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>graph</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/model/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/pom.xml b/stack/corepersistence/model/pom.xml
index 8a7af5b..42d64ec 100644
--- a/stack/corepersistence/model/pom.xml
+++ b/stack/corepersistence/model/pom.xml
@@ -5,7 +5,7 @@
     <parent>
         <artifactId>persistence</artifactId>
         <groupId>org.apache.usergrid</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>2.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/perftest1/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/perftest1/pom.xml b/stack/corepersistence/perftest1/pom.xml
index 64e76f7..08f5513 100644
--- a/stack/corepersistence/perftest1/pom.xml
+++ b/stack/corepersistence/perftest1/pom.xml
@@ -6,7 +6,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.usergrid</groupId>
     <artifactId>perftest1</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <properties>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/perftest2/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/perftest2/pom.xml b/stack/corepersistence/perftest2/pom.xml
index 34ef45f..979f427 100644
--- a/stack/corepersistence/perftest2/pom.xml
+++ b/stack/corepersistence/perftest2/pom.xml
@@ -6,7 +6,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.usergrid</groupId>
     <artifactId>perftest2</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <properties>
@@ -20,7 +20,7 @@
         <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>queryindex</artifactId>
-            <version>1.0-SNAPSHOT</version>
+            <version>2.0.0-SNAPSHOT</version>
             <type>jar</type>
         </dependency>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9caf38bd/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 9a9b7d3..0d4f13f 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -10,7 +10,7 @@
     <groupId>org.apache.usergrid</groupId>
     <artifactId>persistence</artifactId>
     <packaging>pom</packaging>
-    <version>1.0-SNAPSHOT</version>
+    <version>2.0.0-SNAPSHOT</version>
 
     <properties>
 


[09/27] Merged hystrix into asyncqueue

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
new file mode 100644
index 0000000..509fe6a
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
@@ -0,0 +1,1562 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph;
+
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jukito.All;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
+import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Inject;
+import com.netflix.hystrix.exception.HystrixRuntimeException;
+
+import rx.Observable;
+import rx.Subscriber;
+
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith( JukitoRunner.class )
+@UseModules( { TestGraphModule.class } )
+//@UseModules( { TestGraphModule.class, GraphManagerIT.InvalidInput.class } )
+public class GraphManagerTimeoutIT {
+
+    /**
+     * Test timeout in millis
+     */
+    private static final long TIMEOUT = 30000;
+
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
+
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+
+    @Inject
+    protected GraphManagerFactory emf;
+
+    @Inject
+    protected GraphFig graphFig;
+
+    protected OrganizationScope scope;
+
+
+    @Before
+    public void setup() {
+        scope = mock( OrganizationScope.class );
+
+        Id orgId = mock( Id.class );
+
+        when( orgId.getType() ).thenReturn( "organization" );
+        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
+
+        when( scope.getOrganization() ).thenReturn( orgId );
+
+        if ( graphFig.getReadTimeout() > TIMEOUT ) {
+            fail( "Graph read timeout must be <= " + TIMEOUT + ".  Otherwise tests are invalid" );
+        }
+    }
+
+
+    //    @Test(timeout = TIMEOUT, expected = TimeoutException.class)
+    @Test
+    public void testWriteReadEdgeTypeSource( EdgeSerialization serialization ) throws InterruptedException {
+
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+
+        final MarkedEdge edge = createEdge( "source", "edge", "target" );
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+
+        final MockingIterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
+
+
+        when( serialization.getEdgesFromSource( scope, search ) ).thenReturn( itr );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //retrieve the edge, ensure that if we block indefinitely, it times out
+
+        final AtomicInteger onNextCounter = new AtomicInteger();
+        final CountDownLatch errorLatch = new CountDownLatch( 1 );
+
+        final Throwable[] thrown = new Throwable[1];
+
+
+
+        edges.subscribe( new Subscriber<Edge>() {
+            @Override
+            public void onCompleted() {
+
+            }
+
+
+            @Override
+            public void onError( final Throwable e ) {
+                thrown[0] = e;
+                errorLatch.countDown();
+            }
+
+
+            @Override
+            public void onNext( final Edge edge ) {
+                {
+                    onNextCounter.incrementAndGet();
+                }
+            }
+        } );
+
+
+        errorLatch.await();
+
+
+        assertEquals( "One lement was produced", 1,onNextCounter.intValue() );
+        assertTrue(thrown[0] instanceof HystrixRuntimeException);
+
+    }
+
+
+    private class MockingIterator<T> implements Iterator<T> {
+
+        private final Iterator<T> items;
+
+        private final Semaphore semaphore = new Semaphore( 0 );
+
+
+        private MockingIterator( final Collection<T> items ) {
+            this.items = items.iterator();
+        }
+
+
+        @Override
+        public boolean hasNext() {
+            return true;
+        }
+
+
+        @Override
+        public T next() {
+            if ( items.hasNext() ) {
+                return items.next();
+            }
+
+            //block indefinitely
+            try {
+                semaphore.acquire();
+            }
+            catch ( InterruptedException e ) {
+                throw new RuntimeException( e );
+            }
+
+            return null;
+        }
+
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException( "Cannot remove" );
+        }
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTarget() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionSource() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTarget() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Earlier version should not be returned", returned );
+    }
+
+
+    /**
+     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
+     */
+    @Test
+    public void testWriteReadEdgeTypeVersionSourceDistinct() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesFromSource( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeVersionTargetDistinct() {
+
+
+        GraphManager em = emf.createGraphManager( scope );
+
+        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
+
+
+        Edge edge1 = createEdge( "source", "test", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId = edge1.getTargetNode();
+
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it, we should only get edge3, since it's the latest
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge3, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        //now test with an earlier version, we shouldn't get the edge back
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge2, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+        assertFalse( "No more edges", returned.hasNext() );
+
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
+
+        edges = em.loadEdgesToTarget( search );
+
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingSource() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+        final Id sourceId = createId( "source" );
+
+
+        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge3, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypePagingTarget() {
+
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        final Id targetId = createId( "target" );
+
+        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
+
+        em.writeEdge( edge3 ).toBlockingObservable().last();
+
+
+        //now test retrieving it
+
+        SearchByEdgeType search =
+                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
+
+
+        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
+        assertEquals( "Correct edge returned", edge1, returned.next() );
+
+
+        assertFalse( "No more edges", returned.hasNext() );
+
+        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
+
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Paged correctly", edge3, returned.next() );
+
+        assertFalse( "End of stream", returned.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeSource() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesFromSourceByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypeTargetTypeTarget() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //change edge type to be invalid, shouldn't get a result
+        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType() + "invalid", null );
+
+        edges = em.loadEdgesToTargetByType( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "Invalid type should not be returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteSource() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
+                edge.getTargetNode().getType(), null );
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        em.deleteEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesFromSource( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesFromSourceByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeDeleteTarget() {
+
+        GraphManager em = emf.createGraphManager( scope );
+
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        em.writeEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieving it
+
+
+        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
+
+        Observable<Edge> edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        Edge returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
+                edge.getSourceNode().getType(), null );
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().single();
+
+        assertEquals( "Correct edge returned", edge, returned );
+
+
+        //now delete it
+        em.deleteEdge( edge ).toBlockingObservable().last();
+
+        //now test retrieval, should be null
+        edges = em.loadEdgesToTarget( search );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+
+
+        //no search by type, should be null as well
+
+        edges = em.loadEdgesToTargetByType( searchById );
+
+        //implicitly blows up if more than 1 is returned from "single"
+        returned = edges.toBlockingObservable().singleOrDefault( null );
+
+        assertNull( "No edge returned", returned );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypes() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        Observable<String> edges =
+                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+
+        //now get types for test2
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+
+        assertFalse( "No results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypes() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId1 = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get types for test2
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesSourceTypesPaging() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
+
+        edges = em.getEdgeTypesFromSource( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now test sub edges
+
+        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId1.getType(), results.next() );
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now get the next page
+
+        edges = em.getIdTypesFromSource(
+                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", targetId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testWriteReadEdgeTypesTargetTypesPaging() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+
+        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
+
+
+        //get our 2 edge types
+        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
+
+        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        Iterator<String> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test", results.next() );
+        assertEquals( "Edges correct", "test2", results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now load the next page
+
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
+
+        edges = em.getEdgeTypesToTarget( edgeTypes );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", "test2", results.next() );
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now test sub edges
+
+        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId1.getType(), results.next() );
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now get the next page
+
+        edges = em.getIdTypesToTarget(
+                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Types correct", sourceId2.getType(), results.next() );
+
+        assertFalse( "No more results", results.hasNext() );
+    }
+
+
+    @Test
+    public void testMarkSourceEdges() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesFromSource(
+                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdges() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges =
+                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkSourceEdgesType() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void testMarkTargetEdgesType() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().last();
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().last();
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        //get our 2 edges
+        Observable<Edge> edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
+
+
+        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge1 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
+                        null ) );
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+
+        em.deleteEdge( edge2 ).toBlockingObservable().last();
+
+
+        edges = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
+
+
+        results = edges.toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //now delete one of the edges
+
+    }
+
+
+    @Test
+    public void markSourceNode() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId = new SimpleId( "source" );
+        Id targetId1 = new SimpleId( "target" );
+        Id targetId2 = new SimpleId( "target2" );
+
+        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( sourceId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesFromSourceByType(
+                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test
+    public void markTargetNode() {
+
+        final GraphManager em = emf.createGraphManager( scope );
+
+        Id sourceId1 = new SimpleId( "source" );
+        Id sourceId2 = new SimpleId( "source2" );
+        Id targetId = new SimpleId( "target" );
+
+        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
+
+        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
+
+        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
+
+
+        final UUID maxVersion = UUIDGenerator.newTimeUUID();
+
+        Iterator<Edge> results =
+                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                  .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edge found", edge1, results.next() );
+
+        assertEquals( "Edge found", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge1, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertEquals( "Edges correct", edge2, results.next() );
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //mark the source node
+        em.deleteNode( targetId ).toBlockingObservable().last();
+
+
+        //now re-read, nothing should be there since they're marked
+
+        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
+                    .toBlockingObservable().getIterator();
+
+        assertFalse( "No more edges", results.hasNext() );
+
+
+        //get our 2 edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+
+        //now delete one of the edges
+        results = em.loadEdgesToTargetByType(
+                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
+                    .toBlockingObservable().getIterator();
+
+
+        assertFalse( "No more edges", results.hasNext() );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void invalidEdgeTypesWrite( @All Edge edge ) {
+        final GraphManager em = emf.createGraphManager( scope );
+
+        em.writeEdge( edge );
+    }
+
+
+    @Test( expected = NullPointerException.class )
+    public void invalidEdgeTypesDelete( @All Edge edge ) {
+        final GraphManager em = emf.createGraphManager( scope );
+
+        em.deleteEdge( edge );
+    }
+
+    //
+    //    public static class InvalidInput extends JukitoModule {
+    //
+    //        @Override
+    //        protected void configureTest() {
+    //create all edge types of junk input
+    //
+    //            final UUID version = UUIDGenerator.newTimeUUID();
+    //
+    //            Id nullUuid = mock( Id.class );
+    //            when( nullUuid.getUuid() ).thenReturn( null );
+    //
+    //
+    //            Id nullType = mock( Id.class );
+    //            when( nullType.getType() ).thenReturn( "type" );
+    //
+    //            Edge[] edges = new Edge[] {
+    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( nullType, "test", createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", nullType, version ),
+    //
+    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
+    //            };
+    //
+    //
+    //            bindManyInstances( Edge.class, edges );
+    //
+    //        }
+    //
+    //
+    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
+    //            Edge edge = mock( Edge.class );
+    //
+    //            when( edge.getSourceNode() ).thenReturn( sourceId );
+    //            when( edge.getType() ).thenReturn( type );
+    //            when( edge.getTargetNode() ).thenReturn( targetId );
+    //            when( edge.getVersion() ).thenReturn( version );
+    //
+    //            return edge;
+    //        }
+    //    }
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
index eaade41..747e679 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorTest.java
@@ -88,13 +88,12 @@ public class AsyncProcessorTest {
     }
 
 
-    @Test( timeout = 5000 )
+    @Test(timeout = 5000)
     public void verifyAsyncExecution() throws InterruptedException {
 
         final TestListener listener = new TestListener();
 
 
-
         final TestEvent event = new TestEvent();
 
 
@@ -121,7 +120,7 @@ public class AsyncProcessorTest {
 
         final CountDownLatch latch = new CountDownLatch( 2 );
 
-        final TestCompleteListener completeListener = new TestCompleteListener(latch);
+        final TestCompleteListener completeListener = new TestCompleteListener( latch );
 
         asyncProcessor.addCompleteListener( completeListener );
 
@@ -149,7 +148,7 @@ public class AsyncProcessorTest {
 
         final TestEvent completeEvent = completeListener.events.peek();
 
-        assertSame(event, completeEvent);
+        assertSame( event, completeEvent );
     }
 
 
@@ -252,33 +251,29 @@ public class AsyncProcessorTest {
         final TimeoutQueue queue = mock( TimeoutQueue.class );
 
 
-        when(queue.take( 1, 10000l )).thenReturn( Collections.singletonList(asynchronousMessage ));
+        when( queue.take( 1, 10000l ) ).thenReturn( Collections.singletonList( asynchronousMessage ) );
 
         AsyncProcessor<TestEvent> processor = constructProcessor( queue );
 
 
-        Collection<AsynchronousMessage<TestEvent>> timeouts =  processor.getTimeouts( 1, 10000l );
+        Collection<AsynchronousMessage<TestEvent>> timeouts = processor.getTimeouts( 1, 10000l );
 
-        assertEquals(1, timeouts.size());
+        assertEquals( 1, timeouts.size() );
 
         AsynchronousMessage<TestEvent> returned = timeouts.iterator().next();
 
-        assertSame(asynchronousMessage, returned);
-
-
-
+        assertSame( asynchronousMessage, returned );
     }
 
 
-
     /**
      * Construct the async processor
      */
     public <T> AsyncProcessorImpl<T> constructProcessor( TimeoutQueue<T> queue ) {
 
-        GraphFig fig = mock(GraphFig.class);
+        GraphFig fig = mock( GraphFig.class );
 
-        when(fig.getScanPageSize()).thenReturn( 0 );
+        when( fig.getScanPageSize() ).thenReturn( 0 );
 
         AsyncProcessorImpl<T> processor = new AsyncProcessorImpl( queue,  fig );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/LocalTimeoutQueueTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/LocalTimeoutQueueTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/LocalTimeoutQueueTest.java
index 49ae789..45d13f1 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/LocalTimeoutQueueTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/consistency/LocalTimeoutQueueTest.java
@@ -135,7 +135,7 @@ public class LocalTimeoutQueueTest {
             //validate we get a new timeout event since the old one was re-scheduled
             Iterator<AsynchronousMessage<TestEvent>> eventIterator = results.iterator();
 
-            while(eventIterator.hasNext()){
+            while ( eventIterator.hasNext() ) {
 
                 AsynchronousMessage<TestEvent> message = eventIterator.next();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/guice/TestGraphModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/guice/TestGraphModule.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/guice/TestGraphModule.java
index aab90f5..9e63269 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/guice/TestGraphModule.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/guice/TestGraphModule.java
@@ -18,8 +18,10 @@
  */
 package org.apache.usergrid.persistence.graph.guice;
 
+
 import org.apache.usergrid.persistence.collection.guice.TestModule;
 
+
 /**
  * Wrapper for configuring our guice test env
  */
@@ -27,6 +29,6 @@ public class TestGraphModule extends TestModule {
 
     @Override
     protected void configure() {
-        install(new GraphModule());
+        install( new GraphModule() );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
index dcddb27..e735aea 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
@@ -16,8 +16,9 @@ import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.EdgeManager;
-import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
+import org.apache.usergrid.persistence.graph.GraphFig;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
@@ -30,12 +31,13 @@ import com.google.inject.Inject;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchIdType;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -70,7 +72,10 @@ public class NodeDeleteListenerTest {
     protected NodeSerialization nodeSerialization;
 
     @Inject
-    protected EdgeManagerFactory emf;
+    protected GraphManagerFactory emf;
+
+    @Inject
+    protected GraphFig graphFig;
 
 
     protected OrganizationScope scope;
@@ -96,7 +101,7 @@ public class NodeDeleteListenerTest {
     @Test
     public void testNoDeletionMarked() {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         Edge edge = createEdge( "source", "test", "target" );
 
@@ -134,7 +139,7 @@ public class NodeDeleteListenerTest {
     @Test
     public void testRemoveSourceNode() throws ConnectionException {
 
-        EdgeManager em = emf.createEdgeManager( scope );
+        GraphManager em = emf.createEdgeManager( scope );
 
         Edge edge = createEdge( "source", "test", "target" );
 
@@ -159,7 +164,7 @@ public class NodeDeleteListenerTest {
 
         int count = deleteListener.receive( deleteEvent ).toBlockingObservable().last();
 
-        assertEquals( 1, count);
+        assertEquals( 1, count );
 
         //now verify we can't get any of the info back
 
@@ -179,6 +184,12 @@ public class NodeDeleteListenerTest {
 
         assertFalse( "No target should be returned", returned.hasNext() );
 
+
+        returned = edgeSerialization
+                .getEdgeVersions( scope, createGetByEdge( sourceNode, edge.getType(), targetNode, now, null ) );
+
+        assertFalse( "No version should be returned", returned.hasNext() );
+
         //no types from source
 
         Iterator<String> types =
@@ -214,7 +225,190 @@ public class NodeDeleteListenerTest {
      * since it has no other targets
      */
     @Test
-    public void testRemoveTargetNode() {
+    public void testRemoveTargetNode() throws ConnectionException {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+        Edge edge = createEdge( "source", "test", "target" );
+
+        //write the edge
+        Edge last = em.writeEdge( edge ).toBlockingObservable().last();
+
+
+        assertEquals( edge, last );
+
+        Id sourceNode = edge.getSourceNode();
+
+        Id targetNode = edge.getTargetNode();
+
+
+        //mark the node so
+        UUID deleteVersion = UUIDGenerator.newTimeUUID();
+
+        nodeSerialization.mark( scope, targetNode, deleteVersion ).execute();
+
+        EdgeEvent<Id> deleteEvent = new EdgeEvent<Id>( scope, deleteVersion, targetNode );
+
+
+        int count = deleteListener.receive( deleteEvent ).toBlockingObservable().last();
+
+        assertEquals( 1, count );
+
+        //now verify we can't get any of the info back
+
+        UUID now = UUIDGenerator.newTimeUUID();
+
+
+        Iterator<MarkedEdge> returned = edgeSerialization
+                .getEdgesFromSource( scope, createSearchByEdge( sourceNode, edge.getType(), now, null ) );
+
+        //no edge from source node should be returned
+        assertFalse( "No source should be returned", returned.hasNext() );
+
+        //validate it's not returned by the
+
+        returned = edgeSerialization
+                .getEdgesToTarget( scope, createSearchByEdge( targetNode, edge.getType(), now, null ) );
+
+        assertFalse( "No target should be returned", returned.hasNext() );
+
+
+        returned = edgeSerialization
+                .getEdgeVersions( scope, createGetByEdge( sourceNode, edge.getType(), targetNode, now, null ) );
+
+        assertFalse( "No version should be returned", returned.hasNext() );
+
+        //no types from source
+
+        Iterator<String> types =
+                edgeMetadataSerialization.getEdgeTypesFromSource( scope, createSearchEdge( sourceNode, null ) );
+
+        assertFalse( types.hasNext() );
+
+
+        //no types to target
+
+        types = edgeMetadataSerialization.getEdgeTypesToTarget( scope, createSearchEdge( targetNode, null ) );
+
+        assertFalse( types.hasNext() );
+
+
+        //no target types from source
+
+        Iterator<String> idTypes = edgeMetadataSerialization
+                .getIdTypesFromSource( scope, createSearchIdType( sourceNode, edge.getType(), null ) );
+
+        assertFalse( idTypes.hasNext() );
+
+        //no source types to target
+        idTypes = edgeMetadataSerialization
+                .getIdTypesToTarget( scope, createSearchIdType( targetNode, edge.getType(), null ) );
+
+        assertFalse( idTypes.hasNext() );
+    }
+
+
+    /**
+     * Simple test case that tests a single edge and removing the node.  The other target node should be removed as
+     * well since it has no other targets
+     */
+    @Test
+    public void testMultiDelete() throws ConnectionException {
+
+        GraphManager em = emf.createEdgeManager( scope );
+
+
+        //create loads of edges to easily delete.  We'll keep all the types of "test"
+        final int edgeCount = graphFig.getScanPageSize() * 4;
+        Id toDelete = createId( "toDelete" );
+        final String edgeType = "test";
+
+        int countSaved = 0;
+
+
+        for ( int i = 0; i < edgeCount; i++ ) {
+            Edge edge ;
+
+            //mix up source vs target, good for testing as well as create a lot of sub types to ensure they're removed
+            if ( i % 2 == 0 ) {
+                edge = createEdge( toDelete, edgeType, createId( "target"+Math.random() ) );
+            }
+            else {
+                edge = createEdge( createId( "source"+Math.random() ), edgeType, toDelete );
+            }
+
+            //write the edge
+            Edge last = em.writeEdge( edge ).toBlockingObservable().last();
+
+
+            assertEquals( edge, last );
+
+            countSaved++;
+        }
+
+        assertEquals(edgeCount, countSaved);
+
+
+        //mark the node so
+//        UUID deleteVersion = UUIDGenerator.newTimeUUID();
+
+        UUID deleteVersion = UUID.fromString( "ffffffff-ffff-1fff-bfff-ffffffffffff" );
+
+        nodeSerialization.mark( scope, toDelete, deleteVersion ).execute();
+
+        EdgeEvent<Id> deleteEvent = new EdgeEvent<Id>( scope, deleteVersion, toDelete );
+
+
+        int count = deleteListener.receive( deleteEvent ).toBlockingObservable().last();
+
+        assertEquals( edgeCount, count );
+
+        //now verify we can't get any of the info back
+
+        UUID now = UUIDGenerator.newTimeUUID();
 
+
+        Iterator<MarkedEdge> returned = edgeSerialization
+                .getEdgesFromSource( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
+
+        //no edge from source node should be returned
+        assertFalse( "No source should be returned", returned.hasNext() );
+
+        //validate it's not returned by the
+
+        returned = edgeSerialization
+                .getEdgesToTarget( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
+
+        assertFalse( "No target should be returned", returned.hasNext() );
+
+
+
+        //no types from source
+
+        Iterator<String> types =
+                edgeMetadataSerialization.getEdgeTypesFromSource( scope, createSearchEdge( toDelete, null ) );
+
+        assertFalse( types.hasNext() );
+
+
+        //no types to target
+
+        types = edgeMetadataSerialization.getEdgeTypesToTarget( scope, createSearchEdge( toDelete, null ) );
+
+        assertFalse( types.hasNext() );
+
+
+        //no target types from source
+
+        Iterator<String> idTypes = edgeMetadataSerialization
+                .getIdTypesFromSource( scope, createSearchIdType( toDelete, edgeType, null ) );
+
+        assertFalse( idTypes.hasNext() );
+
+        //no source types to target
+        idTypes = edgeMetadataSerialization
+                .getIdTypesToTarget( scope, createSearchIdType( toDelete, edgeType, null ) );
+
+        assertFalse( idTypes.hasNext() );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairTest.java
index dc8a3ac..7dce7da 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeDeleteRepairTest.java
@@ -65,8 +65,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
 public class EdgeDeleteRepairTest {
 
     private static final Logger LOG = LoggerFactory.getLogger( EdgeDeleteRepairTest.class );
@@ -174,7 +174,7 @@ public class EdgeDeleteRepairTest {
 
 
         //now verify we get all the versions we expect back
-        Iterator<MarkedEdge> iterator = edgeSerialization.getEdgeFromSource( scope,
+        Iterator<MarkedEdge> iterator = edgeSerialization.getEdgeVersions( scope,
                 new SimpleSearchByEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID(), null ) );
 
         int count = 0;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairTest.java
index e8835c3..cb8ea67 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairTest.java
@@ -43,7 +43,6 @@ import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
@@ -62,8 +61,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
 public class EdgeMetaRepairTest {
 
 
@@ -127,7 +126,7 @@ public class EdgeMetaRepairTest {
         edgeMetadataSerialization.writeEdge( scope, edge ).execute();
 
         int value = edgeMetaRepair.repairTargets( scope, edge.getTargetNode(), edge.getType(), edge.getVersion() )
-                             .toBlockingObservable().single();
+                                  .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edge exists", 1, value );
 
@@ -136,7 +135,7 @@ public class EdgeMetaRepairTest {
         edgeSerialization.deleteEdge( scope, edge ).execute();
 
         value = edgeMetaRepair.repairTargets( scope, edge.getTargetNode(), edge.getType(), edge.getVersion() )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "Single subtype should be removed", 0, value );
 
@@ -160,21 +159,20 @@ public class EdgeMetaRepairTest {
 
         Id targetId = createId( "target" );
 
-        Edge edge1 = createEdge( createId("source1"), "test", targetId);
-
+        Edge edge1 = createEdge( createId( "source1" ), "test", targetId );
 
 
         edgeSerialization.writeEdge( scope, edge1 ).execute();
 
         edgeMetadataSerialization.writeEdge( scope, edge1 ).execute();
 
-        Edge edge2 = createEdge( createId("source2"), "test", targetId );
+        Edge edge2 = createEdge( createId( "source2" ), "test", targetId );
 
         edgeSerialization.writeEdge( scope, edge2 ).execute();
 
         edgeMetadataSerialization.writeEdge( scope, edge2 ).execute();
 
-        Edge edge3 = createEdge( createId("source3"), "test", targetId );
+        Edge edge3 = createEdge( createId( "source3" ), "test", targetId );
 
         edgeSerialization.writeEdge( scope, edge3 ).execute();
 
@@ -184,7 +182,7 @@ public class EdgeMetaRepairTest {
         UUID cleanupVersion = UUIDGenerator.newTimeUUID();
 
         int value = edgeMetaRepair.repairTargets( scope, edge1.getTargetNode(), edge1.getType(), cleanupVersion )
-                             .toBlockingObservable().single();
+                                  .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 3, value );
 
@@ -193,21 +191,21 @@ public class EdgeMetaRepairTest {
         edgeSerialization.deleteEdge( scope, edge1 ).execute();
 
         value = edgeMetaRepair.repairTargets( scope, edge1.getTargetNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 2, value );
 
         edgeSerialization.deleteEdge( scope, edge2 ).execute();
 
         value = edgeMetaRepair.repairTargets( scope, edge1.getTargetNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 1, value );
 
         edgeSerialization.deleteEdge( scope, edge3 ).execute();
 
         value = edgeMetaRepair.repairTargets( scope, edge1.getTargetNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
 
         assertEquals( "Single subtype should be removed", 0, value );
@@ -233,13 +231,13 @@ public class EdgeMetaRepairTest {
         final Id targetId = createId( "target" );
         final String edgeType = "test";
 
-        final int size =  graphFig.getRepairConcurrentSize()*2;
+        final int size = graphFig.getRepairConcurrentSize() * 2;
 
         Set<Edge> writtenEdges = new HashSet<Edge>();
 
 
-        for(int i = 0; i < size; i ++){
-            Edge edge = createEdge( createId("source"+i), edgeType, targetId);
+        for ( int i = 0; i < size; i++ ) {
+            Edge edge = createEdge( createId( "source" + i ), edgeType, targetId );
 
             edgeSerialization.writeEdge( scope, edge ).execute();
 
@@ -251,27 +249,26 @@ public class EdgeMetaRepairTest {
 
         UUID cleanupVersion = UUIDGenerator.newTimeUUID();
 
-        int value = edgeMetaRepair.repairTargets( scope, targetId, edgeType, cleanupVersion )
-                             .toBlockingObservable().single();
+        int value = edgeMetaRepair.repairTargets( scope, targetId, edgeType, cleanupVersion ).toBlockingObservable()
+                                  .single();
 
         assertEquals( "No subtypes removed, edges exist", size, value );
 
         //now delete the edge
 
-        for(Edge created: writtenEdges){
+        for ( Edge created : writtenEdges ) {
             edgeSerialization.deleteEdge( scope, created ).execute();
         }
 
 
-        value = edgeMetaRepair.repairTargets( scope, targetId, edgeType, cleanupVersion )
-                                     .toBlockingObservable().last();
+        value = edgeMetaRepair.repairTargets( scope, targetId, edgeType, cleanupVersion ).toBlockingObservable().last();
 
         assertEquals( "Subtypes removed", 0, value );
 
         //now verify they're gone
 
-        Iterator<String> edgeTypes = edgeMetadataSerialization
-                .getEdgeTypesToTarget( scope, new SimpleSearchEdgeType( targetId, null ) );
+        Iterator<String> edgeTypes =
+                edgeMetadataSerialization.getEdgeTypesToTarget( scope, new SimpleSearchEdgeType( targetId, null ) );
 
         assertFalse( "No edge types exist", edgeTypes.hasNext() );
 
@@ -283,7 +280,6 @@ public class EdgeMetaRepairTest {
     }
 
 
-
     @Test
     public void cleanSourceSingleEdge() throws ConnectionException {
         Edge edge = createEdge( "source", "test", "target" );
@@ -293,7 +289,7 @@ public class EdgeMetaRepairTest {
         edgeMetadataSerialization.writeEdge( scope, edge ).execute();
 
         int value = edgeMetaRepair.repairSources( scope, edge.getSourceNode(), edge.getType(), edge.getVersion() )
-                             .toBlockingObservable().single();
+                                  .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edge exists", 1, value );
 
@@ -302,7 +298,7 @@ public class EdgeMetaRepairTest {
         edgeSerialization.deleteEdge( scope, edge ).execute();
 
         value = edgeMetaRepair.repairSources( scope, edge.getSourceNode(), edge.getType(), edge.getVersion() )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "Single subtype should be removed", 0, value );
 
@@ -326,21 +322,20 @@ public class EdgeMetaRepairTest {
 
         Id sourceId = createId( "source" );
 
-        Edge edge1 = createEdge( sourceId, "test", createId("target1"));
-
+        Edge edge1 = createEdge( sourceId, "test", createId( "target1" ) );
 
 
         edgeSerialization.writeEdge( scope, edge1 ).execute();
 
         edgeMetadataSerialization.writeEdge( scope, edge1 ).execute();
 
-        Edge edge2 = createEdge( sourceId, "test", createId("target2") );
+        Edge edge2 = createEdge( sourceId, "test", createId( "target2" ) );
 
         edgeSerialization.writeEdge( scope, edge2 ).execute();
 
         edgeMetadataSerialization.writeEdge( scope, edge2 ).execute();
 
-        Edge edge3 = createEdge( sourceId, "test", createId("target3") );
+        Edge edge3 = createEdge( sourceId, "test", createId( "target3" ) );
 
         edgeSerialization.writeEdge( scope, edge3 ).execute();
 
@@ -350,7 +345,7 @@ public class EdgeMetaRepairTest {
         UUID cleanupVersion = UUIDGenerator.newTimeUUID();
 
         int value = edgeMetaRepair.repairSources( scope, edge1.getSourceNode(), edge1.getType(), cleanupVersion )
-                             .toBlockingObservable().single();
+                                  .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 3, value );
 
@@ -359,21 +354,21 @@ public class EdgeMetaRepairTest {
         edgeSerialization.deleteEdge( scope, edge1 ).execute();
 
         value = edgeMetaRepair.repairSources( scope, edge1.getSourceNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 2, value );
 
         edgeSerialization.deleteEdge( scope, edge2 ).execute();
 
         value = edgeMetaRepair.repairSources( scope, edge1.getSourceNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
         assertEquals( "No subtypes removed, edges exist", 1, value );
 
         edgeSerialization.deleteEdge( scope, edge3 ).execute();
 
         value = edgeMetaRepair.repairSources( scope, edge1.getSourceNode(), edge1.getType(), cleanupVersion )
-                         .toBlockingObservable().single();
+                              .toBlockingObservable().single();
 
 
         assertEquals( "Single subtype should be removed", 0, value );
@@ -400,13 +395,13 @@ public class EdgeMetaRepairTest {
 
         final String edgeType = "test";
 
-        final int size =  graphFig.getRepairConcurrentSize()*2;
+        final int size = graphFig.getRepairConcurrentSize() * 2;
 
         Set<Edge> writtenEdges = new HashSet<Edge>();
 
 
-        for(int i = 0; i < size; i ++){
-            Edge edge = createEdge( sourceId, edgeType, createId("target"+i));
+        for ( int i = 0; i < size; i++ ) {
+            Edge edge = createEdge( sourceId, edgeType, createId( "target" + i ) );
 
             edgeSerialization.writeEdge( scope, edge ).execute();
 
@@ -418,27 +413,27 @@ public class EdgeMetaRepairTest {
 
         UUID cleanupVersion = UUIDGenerator.newTimeUUID();
 
-        int value = edgeMetaRepair.repairSources( scope, sourceId, edgeType, cleanupVersion )
-                             .toBlockingObservable().single();
+        int value = edgeMetaRepair.repairSources( scope, sourceId, edgeType, cleanupVersion ).toBlockingObservable()
+                                  .single();
 
         assertEquals( "No subtypes removed, edges exist", size, value );
 
         //now delete the edge
 
-        for(Edge created: writtenEdges){
+        for ( Edge created : writtenEdges ) {
             edgeSerialization.deleteEdge( scope, created ).execute();
         }
 
 
-        value = edgeMetaRepair.repairSources( scope, sourceId, edgeType, cleanupVersion )
-                                     .toBlockingObservable().single();
+        value = edgeMetaRepair.repairSources( scope, sourceId, edgeType, cleanupVersion ).toBlockingObservable()
+                              .single();
 
         assertEquals( "Subtypes removed", 0, value );
 
         //now verify they're gone
 
-        Iterator<String> edgeTypes = edgeMetadataSerialization
-                .getEdgeTypesFromSource( scope, new SimpleSearchEdgeType( sourceId, null ) );
+        Iterator<String> edgeTypes =
+                edgeMetadataSerialization.getEdgeTypesFromSource( scope, new SimpleSearchEdgeType( sourceId, null ) );
 
         assertFalse( "No edge types exist", edgeTypes.hasNext() );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
index 3416421..c7c95a1 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
@@ -24,11 +24,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
@@ -69,8 +65,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
+@RunWith(JukitoRunner.class)
+@UseModules({ TestGraphModule.class })
 public class EdgeWriteRepairTest {
 
     private static final Logger LOG = LoggerFactory.getLogger( EdgeWriteRepairTest.class );
@@ -120,11 +116,9 @@ public class EdgeWriteRepairTest {
     }
 
 
-
     /**
-     * Test repairing with no edges
-     * TODO: TN.  There appears to be a race condition here with ordering.  Not sure if this is intentional as part of the impl
-     * or if it's an issue
+     * Test repairing with no edges TODO: TN.  There appears to be a race condition here with ordering.  Not sure if
+     * this is intentional as part of the impl or if it's an issue
      */
     @Test
     public void versionTest() throws ConnectionException {
@@ -149,11 +143,9 @@ public class EdgeWriteRepairTest {
 
             LOG.info( "Writing edge at index [{}] {}", i, edge );
 
-            if(i < deleteIndex){
+            if ( i < deleteIndex ) {
                 deletedEdges.add( edge );
             }
-
-
         }
 
 
@@ -165,38 +157,37 @@ public class EdgeWriteRepairTest {
 
         for ( MarkedEdge edge : edges ) {
 
-            LOG.info("Returned edge {} for repair", edge);
+            LOG.info( "Returned edge {} for repair", edge );
 
-           final boolean shouldBeDeleted = deletedEdges.contains( edge );
+            final boolean shouldBeDeleted = deletedEdges.contains( edge );
 
             assertTrue( "Removed matches saved index", shouldBeDeleted );
 
             deletedStream.add( edge );
-
         }
 
         deletedEdges.removeAll( deletedStream.elementSet() );
 
-        assertEquals(0, deletedEdges.size());
+        assertEquals( 0, deletedEdges.size() );
 
         //now verify we get all the versions we expect back
-        Iterator<MarkedEdge> iterator = edgeSerialization.getEdgeFromSource( scope,
+        Iterator<MarkedEdge> iterator = edgeSerialization.getEdgeVersions( scope,
                 new SimpleSearchByEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID(), null ) );
 
         int count = 0;
 
-        for(MarkedEdge edge: new IterableWrapper<MarkedEdge>( iterator )){
+        for ( MarkedEdge edge : new IterableWrapper<MarkedEdge>( iterator ) ) {
 
-            final Edge saved = versions.get( size - count -1 );
+            final Edge saved = versions.get( size - count - 1 );
 
-            assertEquals(saved, edge);
+            assertEquals( saved, edge );
 
             count++;
         }
 
-        final int keptCount = size-deleteIndex;
+        final int keptCount = size - deleteIndex;
 
-        assertEquals("Kept edge version was the minimum", keptCount, count);
+        assertEquals( "Kept edge version was the minimum", keptCount, count );
     }
 
 
@@ -214,7 +205,4 @@ public class EdgeWriteRepairTest {
             return this.sourceIterator;
         }
     }
-
-
-
 }


[03/27] git commit: Merge branch 'asyncqueue' into hystrix-integration

Posted by sn...@apache.org.
Merge branch 'asyncqueue' into hystrix-integration


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

Branch: refs/heads/entity-manager
Commit: df0091b4858cf583bcd2b3b5fffab75577723c90
Parents: c1e7a33 167f7a8
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Mar 20 10:03:06 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Mar 20 10:03:06 2014 -0700

----------------------------------------------------------------------
 .../rx/CassandraThreadSchedulerTest.java        | 86 ++++++++++++++++++++
 1 file changed, 86 insertions(+)
----------------------------------------------------------------------



[10/27] Merged hystrix into asyncqueue

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
deleted file mode 100644
index 6ee4183..0000000
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerTimeoutIT.java
+++ /dev/null
@@ -1,1562 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph;
-
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.UUID;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.jukito.All;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.google.inject.Inject;
-import com.netflix.hystrix.exception.HystrixRuntimeException;
-
-import rx.Observable;
-import rx.Subscriber;
-
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-@RunWith( JukitoRunner.class )
-@UseModules( { TestGraphModule.class } )
-//@UseModules( { TestGraphModule.class, EdgeManagerIT.InvalidInput.class } )
-public class EdgeManagerTimeoutIT {
-
-    /**
-     * Test timeout in millis
-     */
-    private static final long TIMEOUT = 30000;
-
-    @ClassRule
-    public static CassandraRule rule = new CassandraRule();
-
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-
-
-    @Inject
-    protected EdgeManagerFactory emf;
-
-    @Inject
-    protected GraphFig graphFig;
-
-    protected OrganizationScope scope;
-
-
-    @Before
-    public void setup() {
-        scope = mock( OrganizationScope.class );
-
-        Id orgId = mock( Id.class );
-
-        when( orgId.getType() ).thenReturn( "organization" );
-        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
-
-        when( scope.getOrganization() ).thenReturn( orgId );
-
-        if ( graphFig.getReadTimeout() > TIMEOUT ) {
-            fail( "Graph read timeout must be <= " + TIMEOUT + ".  Otherwise tests are invalid" );
-        }
-    }
-
-
-    //    @Test(timeout = TIMEOUT, expected = TimeoutException.class)
-    @Test
-    public void testWriteReadEdgeTypeSource( EdgeSerialization serialization ) throws InterruptedException {
-
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-
-        final MarkedEdge edge = createEdge( "source", "edge", "target" );
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-
-        final MockingIterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
-
-
-        when( serialization.getEdgesFromSource( scope, search ) ).thenReturn( itr );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //retrieve the edge, ensure that if we block indefinitely, it times out
-
-        final AtomicInteger onNextCounter = new AtomicInteger();
-        final CountDownLatch errorLatch = new CountDownLatch( 1 );
-
-        final Throwable[] thrown = new Throwable[1];
-
-
-
-        edges.subscribe( new Subscriber<Edge>() {
-            @Override
-            public void onCompleted() {
-
-            }
-
-
-            @Override
-            public void onError( final Throwable e ) {
-                thrown[0] = e;
-                errorLatch.countDown();
-            }
-
-
-            @Override
-            public void onNext( final Edge edge ) {
-                {
-                    onNextCounter.incrementAndGet();
-                }
-            }
-        } );
-
-
-        errorLatch.await();
-
-
-        assertEquals( "One lement was produced", 1,onNextCounter.intValue() );
-        assertTrue(thrown[0] instanceof HystrixRuntimeException);
-
-    }
-
-
-    private class MockingIterator<T> implements Iterator<T> {
-
-        private final Iterator<T> items;
-
-        private final Semaphore semaphore = new Semaphore( 0 );
-
-
-        private MockingIterator( final Collection<T> items ) {
-            this.items = items.iterator();
-        }
-
-
-        @Override
-        public boolean hasNext() {
-            return true;
-        }
-
-
-        @Override
-        public T next() {
-            if ( items.hasNext() ) {
-                return items.next();
-            }
-
-            //block indefinitely
-            try {
-                semaphore.acquire();
-            }
-            catch ( InterruptedException e ) {
-                throw new RuntimeException( e );
-            }
-
-            return null;
-        }
-
-
-        @Override
-        public void remove() {
-            throw new UnsupportedOperationException( "Cannot remove" );
-        }
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTarget() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionSource() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTarget() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    /**
-     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
-     */
-    @Test
-    public void testWriteReadEdgeTypeVersionSourceDistinct() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTargetDistinct() {
-
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingSource() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-        final Id sourceId = createId( "source" );
-
-
-        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge3, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingTarget() {
-
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        final Id targetId = createId( "target" );
-
-        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge3, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeSource() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeTarget() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteSource() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteTarget() {
-
-        EdgeManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypes() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        Observable<String> edges =
-                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-
-        //now get types for test2
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypes() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId1 = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get types for test2
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypesPaging() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
-
-        edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get the next page
-
-        edges = em.getIdTypesFromSource(
-                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypesPaging() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
-
-        edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now get the next page
-
-        edges = em.getIdTypesToTarget(
-                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testMarkSourceEdges() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdges() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges =
-                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkSourceEdgesType() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdgesType() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
-                        null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void markSourceNode() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( sourceId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void markTargetNode() {
-
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( targetId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void invalidEdgeTypesWrite( @All Edge edge ) {
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        em.writeEdge( edge );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void invalidEdgeTypesDelete( @All Edge edge ) {
-        final EdgeManager em = emf.createEdgeManager( scope );
-
-        em.deleteEdge( edge );
-    }
-
-    //
-    //    public static class InvalidInput extends JukitoModule {
-    //
-    //        @Override
-    //        protected void configureTest() {
-    //create all edge types of junk input
-    //
-    //            final UUID version = UUIDGenerator.newTimeUUID();
-    //
-    //            Id nullUuid = mock( Id.class );
-    //            when( nullUuid.getUuid() ).thenReturn( null );
-    //
-    //
-    //            Id nullType = mock( Id.class );
-    //            when( nullType.getType() ).thenReturn( "type" );
-    //
-    //            Edge[] edges = new Edge[] {
-    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( nullType, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullType, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
-    //            };
-    //
-    //
-    //            bindManyInstances( Edge.class, edges );
-    //
-    //        }
-    //
-    //
-    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
-    //            Edge edge = mock( Edge.class );
-    //
-    //            when( edge.getSourceNode() ).thenReturn( sourceId );
-    //            when( edge.getType() ).thenReturn( type );
-    //            when( edge.getTargetNode() ).thenReturn( targetId );
-    //            when( edge.getVersion() ).thenReturn( version );
-    //
-    //            return edge;
-    //        }
-    //    }
-}
-
-
-
-
-


[12/27] git commit: Merged hystrix into asyncqueue

Posted by sn...@apache.org.
Merged hystrix into asyncqueue


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

Branch: refs/heads/entity-manager
Commit: 136edaba0d9132282a097ca8ae743bf0075da7c2
Parents: 51381a3
Author: Todd Nine <tn...@apigee.com>
Authored: Tue Mar 25 13:18:51 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Tue Mar 25 13:18:51 2014 -0700

----------------------------------------------------------------------
 .../usergrid/persistence/graph/EdgeManager.java |  163 --
 .../persistence/graph/EdgeManagerFactory.java   |   40 -
 .../persistence/graph/GraphManager.java         |  169 ++
 .../persistence/graph/GraphManagerFactory.java  |   40 +
 .../graph/consistency/AsyncProcessorImpl.java   |    2 +-
 .../persistence/graph/guice/GraphModule.java    |   10 +-
 .../graph/impl/CollectionIndexObserver.java     |   14 +-
 .../graph/impl/EdgeDeleteListener.java          |   66 +-
 .../persistence/graph/impl/EdgeManagerImpl.java |  410 -----
 .../graph/impl/EdgeWriteListener.java           |  116 +-
 .../graph/impl/GraphManagerImpl.java            |  393 +++++
 .../graph/impl/NodeDeleteListener.java          |  139 +-
 .../graph/impl/stage/AbstractEdgeRepair.java    |   27 +-
 .../graph/serialization/EdgeSerialization.java  |   12 +-
 .../impl/EdgeSerializationImpl.java             |  221 ++-
 .../persistence/graph/EdgeManagerIT.java        |  110 +-
 .../graph/EdgeManagerStressTest.java            |   54 +-
 .../persistence/graph/EdgeManagerTimeoutIT.java | 1562 ------------------
 .../graph/GraphManagerTimeoutIT.java            | 1562 ++++++++++++++++++
 .../graph/consistency/AsyncProcessorTest.java   |   23 +-
 .../consistency/LocalTimeoutQueueTest.java      |    2 +-
 .../graph/guice/TestGraphModule.java            |    4 +-
 .../graph/impl/NodeDeleteListenerTest.java      |  210 ++-
 .../graph/impl/stage/EdgeDeleteRepairTest.java  |    6 +-
 .../graph/impl/stage/EdgeMetaRepairTest.java    |   83 +-
 .../graph/impl/stage/EdgeWriteRepairTest.java   |   40 +-
 .../EdgeSerializationChopTest.java              |   35 +-
 .../serialization/EdgeSerializationTest.java    |  163 +-
 .../serialization/NodeSerializationTest.java    |   13 +-
 .../serialization/util/EdgeHasherTest.java      |   14 +-
 stack/corepersistence/pom.xml                   |    1 +
 31 files changed, 2986 insertions(+), 2718 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManager.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManager.java
deleted file mode 100644
index 9f9c510..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManager.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph;
-
-
-import org.apache.usergrid.persistence.model.entity.Id;
-
-import rx.Observable;
-
-
-/**
- * Represents operations that can be performed on edges within our graph.  A graph should be within an
- * OrganizationScope
- *
- * An Edge: is defined as the following.
- *
- * The edge is directed It has 2 Identifiers (Id).  1 Id is the source node, 1 Id is the target node It has an edge type
- * (a string name)
- *
- * All edges are directed edges.  By definition, the direction is from Source to Target.
- *
- * I.E Source ---- type -----> Target Ex:
- *
- * Dave (user) ----"follows"---> Alex (user)
- *
- * Alex (user)  ----"likes"---> Guinness (beer)
- *
- * Todd (user) ----"worksfor"-----> Apigee (company)
- *
- * Note that edges are directed.  All implementations always have an implicit inverse of the directed edge. This can be
- * used to search both incoming and outgoing edges within the graph.
- *
- * @author tnine
- * @see Edge
- */
-public interface EdgeManager {
-
-
-    /**
-     * @param edge The edge to write
-     *
-     * Create or update an edge.  Note that the implementation should also create incoming (reversed) edges for this
-     * edge.
-     */
-    Observable<Edge> writeEdge( Edge edge );
-
-
-    /**
-     * @param edge The edge to delete
-     *
-     *
-     * EdgeDelete the edge. Implementation should also delete the incoming (reversed) edge.
-     */
-    Observable<Edge> deleteEdge( Edge edge );
-
-    /**
-     * TODO: This needs to mark a node as deleted while consistency processing occurs, our reads would need to check this filter on read
-     *
-     * Remove the node from the graph.
-     *
-     * @param node
-     * @return
-     */
-    Observable<Id> deleteNode(Id node);
-
-    /**
-     * Returns an observable that emits all edges where the specified node is the source node. The edges will match the
-     * search criteria of the edge type
-     *
-     * @param search The search parameters
-     *
-     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
-     */
-    Observable<Edge> loadEdgesFromSource( SearchByEdgeType search );
-
-    /**
-     * Returns an observable that emits all edges where the specified node is the target node. The edges will match the
-     * search criteria of the edge type
-     *
-     * @param search The search parameters
-     *
-     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
-     */
-    Observable<Edge> loadEdgesToTarget( SearchByEdgeType search );
-
-
-    /**
-     * Returns an observable that emits all edges where the specified node is the source node. The edges will match the
-     * search criteria of the edge type and the target type
-     *
-     * @param search The search parameters
-     *
-     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
-     */
-    Observable<Edge> loadEdgesFromSourceByType( SearchByIdType search );
-
-
-    /**
-     * Returns an observable that emits all edges where the specified node is the target node. The edges will match the
-     * search criteria of the edge type and the target type
-     *
-     * @param search The search parameters
-     *
-     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
-     */
-    Observable<Edge> loadEdgesToTargetByType( SearchByIdType search );
-
-    /**
-     * Get all edge types to this node.  The node provided by search is the target node.
-     *
-     * @param search The search
-     *
-     * @return An observable that emits strings for edge types
-     */
-    Observable<String> getEdgeTypesFromSource( SearchEdgeType search );
-
-
-    /**
-     * Get all id types to this node.  The node provided by search is the target node with the edge type to search.
-     *
-     * @param search The search criteria
-     *
-     * @return An observable of all source id types
-     */
-    Observable<String> getIdTypesFromSource( SearchIdType search );
-
-
-    /**
-     * Get all edge types from this node.  The node provided by search is the source node.
-     *
-     * @param search The search
-     *
-     * @return An observable that emits strings for edge types
-     */
-    Observable<String> getEdgeTypesToTarget( SearchEdgeType search );
-
-
-    /**
-     * Get all id types from this node.  The node provided by search is the source node with the edge type to search.
-     *
-     * @param search The search criteria
-     *
-     * @return An observable of all source id types
-     */
-    Observable<String> getIdTypesToTarget( SearchIdType search );
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManagerFactory.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManagerFactory.java
deleted file mode 100644
index f01f876..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/EdgeManagerFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph;
-
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-
-
-/**
- *
- * @author: tnine
- *
- */
-public interface EdgeManagerFactory
-{
-
-    /**
-     * Create an graph manager for the collection context
-     *
-     * @param collectionScope The context to use when creating the graph manager
-     */
-    public EdgeManager createEdgeManager( OrganizationScope collectionScope );
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
new file mode 100644
index 0000000..8af77d6
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph;
+
+
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import rx.Observable;
+
+
+/**
+ * Represents operations that can be performed on edges within our graph.  A graph should be within an
+ * OrganizationScope
+ *
+ * An Edge: is defined as the following.
+ *
+ * The edge is directed It has 2 Identifiers (Id).  1 Id is the source node, 1 Id is the target node It has an edge type
+ * (a string name)
+ *
+ * All edges are directed edges.  By definition, the direction is from Source to Target.
+ *
+ * I.E Source ---- type -----> Target Ex:
+ *
+ * Dave (user) ----"follows"---> Alex (user)
+ *
+ * Alex (user)  ----"likes"---> Guinness (beer)
+ *
+ * Todd (user) ----"worksfor"-----> Apigee (company)
+ *
+ * Note that edges are directed.  All implementations always have an implicit inverse of the directed edge. This can be
+ * used to search both incoming and outgoing edges within the graph.
+ *
+ * @author tnine
+ * @see Edge
+ */
+public interface GraphManager {
+
+
+    /**
+     * @param edge The edge to write
+     *
+     * Create or update an edge.  Note that the implementation should also create incoming (reversed) edges for this
+     * edge.
+     */
+    Observable<Edge> writeEdge( Edge edge );
+
+
+    /**
+     * @param edge The edge to delete
+     *
+     *
+     * EdgeDelete the edge. Implementation should also delete the incoming (reversed) edge. Only deletes the specific version
+     */
+    Observable<Edge> deleteEdge( Edge edge );
+
+    /**
+     *
+     * Remove the node from the graph.
+     *
+     * @param node
+     * @return
+     */
+    Observable<Id> deleteNode(Id node);
+
+    /**
+     * Get all versions of this edge where versions <= max version
+     * @param edge
+     * @return
+     */
+    Observable<Edge> loadEdgeVersions( SearchByEdge edge );
+
+    /**
+     * Returns an observable that emits all edges where the specified node is the source node. The edges will match the
+     * search criteria of the edge type
+     *
+     * @param search The search parameters
+     *
+     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
+     */
+    Observable<Edge> loadEdgesFromSource( SearchByEdgeType search );
+
+    /**
+     * Returns an observable that emits all edges where the specified node is the target node. The edges will match the
+     * search criteria of the edge type
+     *
+     * @param search The search parameters
+     *
+     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
+     */
+    Observable<Edge> loadEdgesToTarget( SearchByEdgeType search );
+
+
+    /**
+     * Returns an observable that emits all edges where the specified node is the source node. The edges will match the
+     * search criteria of the edge type and the target type
+     *
+     * @param search The search parameters
+     *
+     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
+     */
+    Observable<Edge> loadEdgesFromSourceByType( SearchByIdType search );
+
+
+    /**
+     * Returns an observable that emits all edges where the specified node is the target node. The edges will match the
+     * search criteria of the edge type and the target type
+     *
+     * @param search The search parameters
+     *
+     * @return An observable that emits Edges. The observer will need to unsubscribe when it has completed consumption.
+     */
+    Observable<Edge> loadEdgesToTargetByType( SearchByIdType search );
+
+    /**
+     * Get all edge types to this node.  The node provided by search is the target node.
+     *
+     * @param search The search
+     *
+     * @return An observable that emits strings for edge types
+     */
+    Observable<String> getEdgeTypesFromSource( SearchEdgeType search );
+
+
+    /**
+     * Get all id types to this node.  The node provided by search is the target node with the edge type to search.
+     *
+     * @param search The search criteria
+     *
+     * @return An observable of all source id types
+     */
+    Observable<String> getIdTypesFromSource( SearchIdType search );
+
+
+    /**
+     * Get all edge types from this node.  The node provided by search is the source node.
+     *
+     * @param search The search
+     *
+     * @return An observable that emits strings for edge types
+     */
+    Observable<String> getEdgeTypesToTarget( SearchEdgeType search );
+
+
+    /**
+     * Get all id types from this node.  The node provided by search is the source node with the edge type to search.
+     *
+     * @param search The search criteria
+     *
+     * @return An observable of all source id types
+     */
+    Observable<String> getIdTypesToTarget( SearchIdType search );
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManagerFactory.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManagerFactory.java
new file mode 100644
index 0000000..499259b
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManagerFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph;
+
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+
+
+/**
+ *
+ * @author: tnine
+ *
+ */
+public interface GraphManagerFactory
+{
+
+    /**
+     * Create an graph manager for the collection context
+     *
+     * @param collectionScope The context to use when creating the graph manager
+     */
+    public GraphManager createEdgeManager( OrganizationScope collectionScope );
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
index 2b00d1a..20411e7 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
@@ -45,7 +45,7 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
 
 
     @Inject
-    public AsyncProcessorImpl( final TimeoutQueue<T> queue, final GraphFig graphFig ) {
+    public AsyncProcessorImpl( final TimeoutQueue<T> queue,  final GraphFig graphFig ) {
         this.queue = queue;
         this.graphFig = graphFig;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
index b499e4c..d575471 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
@@ -24,15 +24,15 @@ import org.safehaus.guicyfig.GuicyFigModule;
 import org.apache.usergrid.persistence.collection.guice.CollectionModule;
 import org.apache.usergrid.persistence.collection.migration.Migration;
 import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
-import org.apache.usergrid.persistence.graph.EdgeManager;
-import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessorImpl;
 import org.apache.usergrid.persistence.graph.consistency.LocalTimeoutQueue;
 import org.apache.usergrid.persistence.graph.consistency.TimeoutQueue;
 import org.apache.usergrid.persistence.graph.impl.CollectionIndexObserver;
-import org.apache.usergrid.persistence.graph.impl.EdgeManagerImpl;
+import org.apache.usergrid.persistence.graph.impl.GraphManagerImpl;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepairImpl;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
@@ -74,8 +74,8 @@ public class GraphModule extends AbstractModule {
         bind( CassandraConfig.class).to( CassandraConfigImpl.class );
 
         // create a guice factory for getting our collection manager
-        install( new FactoryModuleBuilder().implement( EdgeManager.class, EdgeManagerImpl.class )
-                                           .build( EdgeManagerFactory.class ) );
+        install( new FactoryModuleBuilder().implement( GraphManager.class, GraphManagerImpl.class )
+                                           .build( GraphManagerFactory.class ) );
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/CollectionIndexObserver.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/CollectionIndexObserver.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/CollectionIndexObserver.java
index 6175b0b..a41cd4a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/CollectionIndexObserver.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/CollectionIndexObserver.java
@@ -24,8 +24,8 @@ import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
 import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
 import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.EdgeManager;
-import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 
 import com.google.common.base.Preconditions;
 import com.google.inject.Inject;
@@ -38,13 +38,13 @@ import com.google.inject.Singleton;
 @Singleton
 public class CollectionIndexObserver implements PostProcessObserver {
 
-    private final EdgeManagerFactory edgeManagerFactory;
+    private final GraphManagerFactory graphManagerFactory;
 
 
     @Inject
-    public CollectionIndexObserver( final EdgeManagerFactory edgeManagerFactory ) {
-        Preconditions.checkNotNull( edgeManagerFactory, "edgeManagerFactory cannot be null" );
-        this.edgeManagerFactory = edgeManagerFactory;
+    public CollectionIndexObserver( final GraphManagerFactory graphManagerFactory ) {
+        Preconditions.checkNotNull( graphManagerFactory, "graphManagerFactory cannot be null" );
+        this.graphManagerFactory = graphManagerFactory;
     }
 
 
@@ -53,7 +53,7 @@ public class CollectionIndexObserver implements PostProcessObserver {
     public void postCommit( final CollectionScope scope, final MvccEntity entity ) {
 
         //get the edge manager for the org scope
-        EdgeManager em = edgeManagerFactory.createEdgeManager( scope );
+        GraphManager em = graphManagerFactory.createEdgeManager( scope );
 
         /**
          * create an edge from owner->entity of the type name in the scope.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
index a5715c9..11c052b 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeDeleteListener.java
@@ -1,21 +1,18 @@
 package org.apache.usergrid.persistence.graph.impl;
 
 
-import java.util.Iterator;
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.EdgeManager;
-import org.apache.usergrid.persistence.graph.EdgeManagerFactory;
 import org.apache.usergrid.persistence.graph.GraphFig;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.MessageListener;
 import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.impl.parse.ObservableIterator;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -26,7 +23,7 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import rx.Observable;
 import rx.functions.Action1;
 import rx.functions.Func1;
-import rx.functions.Func5;
+import rx.functions.Func4;
 
 
 /**
@@ -38,7 +35,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
 
     private final EdgeSerialization edgeSerialization;
     private final EdgeMetadataSerialization edgeMetadataSerialization;
-    private final EdgeManagerFactory edgeManagerFactory;
+    private final GraphManagerFactory graphManagerFactory;
     private final Keyspace keyspace;
     private final GraphFig graphFig;
 
@@ -46,12 +43,11 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
     @Inject
     public EdgeDeleteListener( final EdgeSerialization edgeSerialization,
                                final EdgeMetadataSerialization edgeMetadataSerialization,
-                               final EdgeManagerFactory edgeManagerFactory, final Keyspace keyspace,
-                               final GraphFig graphFig,
-                               @EdgeDelete final AsyncProcessor edgeDelete ) {
+                               final GraphManagerFactory graphManagerFactory, final Keyspace keyspace,
+                               @EdgeDelete final AsyncProcessor edgeDelete, final GraphFig graphFig ) {
         this.edgeSerialization = edgeSerialization;
         this.edgeMetadataSerialization = edgeMetadataSerialization;
-        this.edgeManagerFactory = edgeManagerFactory;
+        this.graphManagerFactory = graphManagerFactory;
         this.keyspace = keyspace;
         this.graphFig = graphFig;
 
@@ -65,7 +61,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
         final Edge edge = delete.getData();
         final OrganizationScope scope = delete.getOrganizationScope();
         final UUID maxVersion = edge.getVersion();
-        final EdgeManager edgeManager = edgeManagerFactory.createEdgeManager( scope );
+        final GraphManager graphManager = graphManagerFactory.createEdgeManager( scope );
 
 
         return Observable.from( edge ).flatMap( new Func1<Edge, Observable<MutationBatch>>() {
@@ -75,26 +71,26 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
                 final MutationBatch batch = keyspace.prepareMutationBatch();
 
 
-                //go through every version of this edge <= the current version and remove it
-                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>( ) {
-                    @Override
-                    protected Iterator<MarkedEdge> getIterator() {
-                        return edgeSerialization.getEdgeToTarget( scope,
-                                new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(),
-                                        edge.getVersion(), null ) );
-                    }
-                } ).doOnNext( new Action1<MarkedEdge>() {
-                    @Override
-                    public void call( final MarkedEdge markedEdge ) {
-                        final MutationBatch delete = edgeSerialization.deleteEdge( scope, markedEdge );
-                        batch.mergeShallow( delete );
-                    }
-                } );
-
+//             TODO T.N. no longer needed since each version is explicity deleted
+//                //go through every version of this edge <= the current version and remove it
+//                Observable<MarkedEdge> edges = Observable.create( new ObservableIterator<MarkedEdge>() {
+//                    @Override
+//                    protected Iterator<MarkedEdge> getIterator() {
+//                        return edgeSerialization.getEdgeVersions( scope,
+//                                new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(),
+//                                        edge.getVersion(), null ) );
+//                    }
+//                } ).doOnNext( new Action1<MarkedEdge>() {
+//                    @Override
+//                    public void call( final MarkedEdge markedEdge ) {
+//                        final MutationBatch delete = edgeSerialization.deleteEdge( scope, markedEdge );
+//                        batch.mergeShallow( delete );
+//                    }
+//                } );
 
                 //search by edge type and target type.  If any other edges with this target type exist,
                 // we can't delete it
-                Observable<Integer> sourceIdType = edgeManager.loadEdgesFromSourceByType(
+                Observable<Integer> sourceIdType = graphManager.loadEdgesFromSourceByType(
                         new SimpleSearchByIdType( edge.getSourceNode(), edge.getType(), maxVersion,
                                 edge.getTargetNode().getType(), null ) ).take( 2 ).count()
                                                               .doOnNext( new Action1<Integer>() {
@@ -115,7 +111,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
                                                               } );
 
 
-                Observable<Integer> targetIdType = edgeManager.loadEdgesToTargetByType(
+                Observable<Integer> targetIdType = graphManager.loadEdgesToTargetByType(
                         new SimpleSearchByIdType( edge.getTargetNode(), edge.getType(), maxVersion,
                                 edge.getSourceNode().getType(), null ) ).take( 2 ).count()
                                                               .doOnNext( new Action1<Integer>() {
@@ -138,7 +134,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
 
                 //search by edge type and target type.  If any other edges with this target type exist,
                 // we can't delete it
-                Observable<Integer> sourceType = edgeManager.loadEdgesFromSource(
+                Observable<Integer> sourceType = graphManager.loadEdgesFromSource(
                         new SimpleSearchByEdgeType( edge.getSourceNode(), edge.getType(), maxVersion, null ) ).take( 2 )
                                                             .count().doOnNext( new Action1<Integer>() {
                             @Override
@@ -156,7 +152,7 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
                         } );
 
 
-                Observable<Integer> targetType = edgeManager.loadEdgesToTarget(
+                Observable<Integer> targetType = graphManager.loadEdgesToTarget(
                         new SimpleSearchByEdgeType( edge.getTargetNode(), edge.getType(), maxVersion, null ) ).take( 2 )
                                                             .count().doOnNext( new Action1<Integer>() {
                             @Override
@@ -175,10 +171,10 @@ public class EdgeDeleteListener implements MessageListener<EdgeEvent<Edge>, Edge
 
 
                 //no op, just wait for each observable to populate the mutation before returning it
-                return Observable.zip( edges, sourceIdType, targetIdType, sourceType, targetType,
-                        new Func5<MarkedEdge, Integer, Integer, Integer, Integer, MutationBatch>() {
+                return Observable.zip(sourceIdType, targetIdType, sourceType, targetType,
+                        new Func4<Integer, Integer, Integer, Integer, MutationBatch>() {
                             @Override
-                            public MutationBatch call( final MarkedEdge markedEdge, final Integer integer,
+                            public MutationBatch call( final Integer integer,
                                                        final Integer integer2, final Integer integer3,
                                                        final Integer integer4 ) {
                                 return batch;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
deleted file mode 100644
index 4e5746a..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.impl;
-
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
-import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.EdgeManager;
-import org.apache.usergrid.persistence.graph.GraphFig;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
-import org.apache.usergrid.persistence.graph.SearchByEdgeType;
-import org.apache.usergrid.persistence.graph.SearchByIdType;
-import org.apache.usergrid.persistence.graph.SearchEdgeType;
-import org.apache.usergrid.persistence.graph.SearchIdType;
-import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
-import org.apache.usergrid.persistence.graph.consistency.AsynchronousMessage;
-import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
-import org.apache.usergrid.persistence.graph.guice.EdgeWrite;
-import org.apache.usergrid.persistence.graph.guice.NodeDelete;
-import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.impl.parse.ObservableIterator;
-import org.apache.usergrid.persistence.graph.serialization.util.EdgeUtils;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.fasterxml.uuid.UUIDComparator;
-import com.google.inject.Inject;
-import com.google.inject.assistedinject.Assisted;
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-import rx.Observable;
-import rx.Scheduler;
-import rx.functions.Func1;
-import rx.schedulers.Schedulers;
-
-
-/**
- *
- *
- */
-public class EdgeManagerImpl implements EdgeManager {
-
-
-    private final OrganizationScope scope;
-
-    private final EdgeMetadataSerialization edgeMetadataSerialization;
-
-
-    private final EdgeSerialization edgeSerialization;
-
-    private final NodeSerialization nodeSerialization;
-
-    private final AsyncProcessor<Edge> edgeWriteAsyncProcessor;
-    private final AsyncProcessor<Edge> edgeDeleteAsyncProcessor;
-    private final AsyncProcessor<Id> nodeDeleteAsyncProcessor;
-
-    private final GraphFig graphFig;
-
-
-    @Inject
-    public EdgeManagerImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
-                            final EdgeSerialization edgeSerialization, final NodeSerialization nodeSerialization,
-                            final GraphFig graphFig, @EdgeWrite final AsyncProcessor edgeWrite,
-                            @EdgeDelete final AsyncProcessor edgeDelete, @NodeDelete final AsyncProcessor nodeDelete,
-                            @Assisted final OrganizationScope scope ) {
-
-        ValidationUtils.validateOrganizationScope( scope );
-
-
-        this.scope = scope;
-        this.edgeMetadataSerialization = edgeMetadataSerialization;
-        this.edgeSerialization = edgeSerialization;
-        this.nodeSerialization = nodeSerialization;
-        this.graphFig = graphFig;
-
-
-        this.edgeWriteAsyncProcessor = edgeWrite;
-
-
-        this.edgeDeleteAsyncProcessor = edgeDelete;
-
-
-        this.nodeDeleteAsyncProcessor = nodeDelete;
-    }
-
-
-    @Override
-    public Observable<Edge> writeEdge( final Edge edge ) {
-        EdgeUtils.validateEdge( edge );
-
-        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
-            @Override
-            public Edge call( final Edge edge ) {
-                final MutationBatch mutation = edgeMetadataSerialization.writeEdge( scope, edge );
-
-                final MutationBatch edgeMutation = edgeSerialization.writeEdge( scope, edge );
-
-                mutation.mergeShallow( edgeMutation );
-
-                final AsynchronousMessage<Edge> event = edgeWriteAsyncProcessor.setVerification( edge, getTimeout() );
-
-                try {
-                    mutation.execute();
-                }
-                catch ( ConnectionException e ) {
-                    throw new RuntimeException( "Unable to connect to cassandra", e );
-                }
-
-                edgeWriteAsyncProcessor.start( event );
-
-                return edge;
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<Edge> deleteEdge( final Edge edge ) {
-        EdgeUtils.validateEdge( edge );
-
-        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
-            @Override
-            public Edge call( final Edge edge ) {
-                final MutationBatch edgeMutation = edgeSerialization.markEdge( scope, edge );
-
-                final AsynchronousMessage<Edge> event = edgeDeleteAsyncProcessor.setVerification( edge, getTimeout() );
-
-
-                try {
-                    edgeMutation.execute();
-                }
-                catch ( ConnectionException e ) {
-                    throw new RuntimeException( "Unable to connect to cassandra", e );
-                }
-
-                edgeDeleteAsyncProcessor.start( event );
-
-
-                return edge;
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<Id> deleteNode( final Id node ) {
-        return Observable.from( node ).subscribeOn(  Schedulers.io() ).map( new Func1<Id, Id>() {
-            @Override
-            public Id call( final Id id ) {
-
-                //mark the node as deleted
-                final UUID deleteTime = UUIDGenerator.newTimeUUID();
-
-                final MutationBatch nodeMutation = nodeSerialization.mark( scope, id, deleteTime );
-
-                final AsynchronousMessage<Id> event = nodeDeleteAsyncProcessor.setVerification( node, getTimeout() );
-
-
-                try {
-                    nodeMutation.execute();
-                }
-                catch ( ConnectionException e ) {
-                    throw new RuntimeException( "Unable to connect to cassandra", e );
-                }
-
-                nodeDeleteAsyncProcessor.start( event );
-
-                return id;
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-
-
-        return
-
-                Observable.create( new ObservableIterator<MarkedEdge>() {
-                    @Override
-                    protected Iterator<MarkedEdge> getIterator() {
-                        return edgeSerialization.getEdgesFromSource( scope, search );
-                    }
-                } )//we intentionally use distinct until changed.  This way we won't store all the keys since this
-                        //would hog far too much memory.
-                        .distinctUntilChanged( new Func1<Edge, Id>() {
-                            @Override
-                            public Id call( final Edge edge ) {
-                                return edge.getTargetNode();
-                            }
-                        } ).buffer( graphFig.getScanPageSize() )
-                        .flatMap( new EdgeBufferFilter( search.getMaxVersion() ) ).cast( Edge.class );
-    }
-
-
-    @Override
-    public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-                return edgeSerialization.getEdgesToTarget( scope, search );
-            }
-        } )
-                //we intentionally use distinct until changed.  This way we won't store all the keys since this
-                //would hog far too much memory.
-                .distinctUntilChanged( new Func1<Edge, Id>() {
-                    @Override
-                    public Id call( final Edge edge ) {
-                        return edge.getSourceNode();
-                    }
-                } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                .cast( Edge.class );
-    }
-
-
-    @Override
-    public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-                return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
-            }
-        } ).distinctUntilChanged( new Func1<Edge, Id>() {
-            @Override
-            public Id call( final Edge edge ) {
-                return edge.getTargetNode();
-            }
-        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-
-                         .cast( Edge.class );
-    }
-
-
-    @Override
-    public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-                return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
-            }
-        } ).distinctUntilChanged( new Func1<Edge, Id>() {
-            @Override
-            public Id call( final Edge edge ) {
-                return edge.getSourceNode();
-            }
-        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                         .cast( Edge.class );
-    }
-
-
-    @Override
-    public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
-
-        return Observable.create( new ObservableIterator<String>() {
-            @Override
-            protected Iterator<String> getIterator() {
-                return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
-            @Override
-            protected Iterator<String> getIterator() {
-                return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
-
-        return Observable.create( new ObservableIterator<String>() {
-            @Override
-            protected Iterator<String> getIterator() {
-                return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
-            }
-        } );
-    }
-
-
-    @Override
-    public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
-            @Override
-            protected Iterator<String> getIterator() {
-                return edgeMetadataSerialization.getIdTypesToTarget( scope, search );
-            }
-        } );
-    }
-
-
-    /**
-     * Get our timeout for write consistency
-     */
-    private long getTimeout() {
-        return graphFig.getRepairTimeout() * 2;
-    }
-
-
-    /**
-     * Helper filter to perform mapping and return an observable of pre-filtered edges
-     */
-    private class EdgeBufferFilter implements Func1<List<MarkedEdge>, Observable<MarkedEdge>> {
-
-        private final UUID maxVersion;
-
-
-        private EdgeBufferFilter( final UUID maxVersion ) {
-            this.maxVersion = maxVersion;
-        }
-
-
-        /**
-         * Takes a buffered list of marked edges.  It then does a single round trip to fetch marked ids These are then
-         * used in conjunction with the max version filter to filter any edges that should not be returned
-         *
-         * @return An observable that emits only edges that can be consumed.  There could be multiple versions of the
-         *         same edge so those need de-duped.
-         */
-        @Override
-        public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
-
-            final Map<Id, UUID> markedVersions = nodeSerialization.getMaxVersions( scope, markedEdges );
-            return Observable.from( markedEdges ).subscribeOn(  Schedulers.io() )
-                             .filter( new EdgeFilter( this.maxVersion, markedVersions ) );
-        }
-    }
-
-
-    /**
-     * Filter the returned values based on the max uuid and if it's been marked for deletion or not
-     */
-    private static class EdgeFilter implements Func1<MarkedEdge, Boolean> {
-
-        private final UUID maxVersion;
-
-        private final Map<Id, UUID> markCache;
-
-
-        private EdgeFilter( final UUID maxVersion, Map<Id, UUID> markCache ) {
-            this.maxVersion = maxVersion;
-            this.markCache = markCache;
-        }
-
-
-        @Override
-        public Boolean call( final MarkedEdge edge ) {
-
-
-            final UUID edgeVersion = edge.getVersion();
-
-            //our edge needs to not be deleted and have a version that's > max Version
-            if ( edge.isDeleted() || UUIDComparator.staticCompare( edgeVersion, maxVersion ) > 0 ) {
-                return false;
-            }
-
-
-            final UUID sourceVersion = markCache.get( edge.getSourceNode() );
-
-            //the source Id has been marked for deletion.  It's version is <= to the marked version for deletion,
-            // so we need to discard it
-            if ( sourceVersion != null && UUIDComparator.staticCompare( edgeVersion, sourceVersion ) < 1 ) {
-                return false;
-            }
-
-            final UUID targetVersion = markCache.get( edge.getTargetNode() );
-
-            //the target Id has been marked for deletion.  It's version is <= to the marked version for deletion,
-            // so we need to discard it
-            if ( targetVersion != null && UUIDComparator.staticCompare( edgeVersion, targetVersion ) < 1 ) {
-                return false;
-            }
-
-
-            return true;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
index e146ba9..90146dc 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 package org.apache.usergrid.persistence.graph.impl;
 
 
@@ -52,52 +71,55 @@ public class EdgeWriteListener implements MessageListener<EdgeEvent<Edge>, EdgeE
         final OrganizationScope scope = write.getOrganizationScope();
         final UUID maxVersion = edge.getVersion();
 
-        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-
-                final SimpleSearchByEdge search =
-                        new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), maxVersion,
-                                null );
-
-                return edgeSerialization.getEdgeFromSource( scope, search );
-            }
-        } ).filter( new Func1<MarkedEdge, Boolean>() {
-
-            //TODO, reuse this for delete operation
-
-
-            /**
-             * We only want to return edges < this version so we remove them
-             * @param markedEdge
-             * @return
-             */
-            @Override
-            public Boolean call( final MarkedEdge markedEdge ) {
-                return UUIDComparator.staticCompare( markedEdge.getVersion(), maxVersion ) < 0;
-            }
-            //buffer the deletes and issue them in a single mutation
-        } ).buffer( graphFig.getScanPageSize() ).map( new Func1<List<MarkedEdge>, EdgeEvent<Edge>>() {
-            @Override
-            public EdgeEvent<Edge> call( final List<MarkedEdge> markedEdges ) {
-
-                final MutationBatch batch = keyspace.prepareMutationBatch();
-
-                for ( MarkedEdge edge : markedEdges ) {
-                    final MutationBatch delete = edgeSerialization.deleteEdge( scope, edge );
-
-                    batch.mergeShallow( delete );
-                }
-
-                try {
-                    batch.execute();
-                }
-                catch ( ConnectionException e ) {
-                    throw new RuntimeException( "Unable to issue write to cassandra", e );
-                }
-
-                return write;
-            }
-        } );
+        return Observable.empty();
+
+//      TODO T.N, some async processing for balancing here
+//  return Observable.create( new ObservableIterator<MarkedEdge>() {
+//            @Override
+//            protected Iterator<MarkedEdge> getIterator() {
+//
+//                final SimpleSearchByEdge search =
+//                        new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), maxVersion,
+//                                null );
+//
+//                return edgeSerialization.getEdgeVersions( scope, search );
+//            }
+//        } ).filter( new Func1<MarkedEdge, Boolean>() {
+//
+//            //TODO, reuse this for delete operation
+//
+//
+//            /**
+//             * We only want to return edges < this version so we remove them
+//             * @param markedEdge
+//             * @return
+//             */
+//            @Override
+//            public Boolean call( final MarkedEdge markedEdge ) {
+//                return UUIDComparator.staticCompare( markedEdge.getVersion(), maxVersion ) < 0;
+//            }
+//            //buffer the deletes and issue them in a single mutation
+//        } ).buffer( graphFig.getScanPageSize() ).map( new Func1<List<MarkedEdge>, EdgeEvent<Edge>>() {
+//            @Override
+//            public EdgeEvent<Edge> call( final List<MarkedEdge> markedEdges ) {
+//
+//                final MutationBatch batch = keyspace.prepareMutationBatch();
+//
+//                for ( MarkedEdge edge : markedEdges ) {
+//                    final MutationBatch delete = edgeSerialization.deleteEdge( scope, edge );
+//
+//                    batch.mergeShallow( delete );
+//                }
+//
+//                try {
+//                    batch.execute();
+//                }
+//                catch ( ConnectionException e ) {
+//                    throw new RuntimeException( "Unable to issue write to cassandra", e );
+//                }
+//
+//                return write;
+//            }
+//        } );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
new file mode 100644
index 0000000..94d4dc3
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
@@ -0,0 +1,393 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.persistence.graph.impl;
+
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphFig;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.MarkedEdge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.SearchByIdType;
+import org.apache.usergrid.persistence.graph.SearchEdgeType;
+import org.apache.usergrid.persistence.graph.SearchIdType;
+import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
+import org.apache.usergrid.persistence.graph.consistency.AsynchronousMessage;
+import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
+import org.apache.usergrid.persistence.graph.guice.EdgeWrite;
+import org.apache.usergrid.persistence.graph.guice.NodeDelete;
+import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
+import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
+import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
+import org.apache.usergrid.persistence.graph.serialization.impl.parse.ObservableIterator;
+import org.apache.usergrid.persistence.graph.serialization.util.EdgeUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.fasterxml.uuid.UUIDComparator;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+import rx.Observable;
+import rx.Scheduler;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+
+/**
+ * Implementation of graph edges
+ */
+public class GraphManagerImpl implements GraphManager {
+
+
+    private final OrganizationScope scope;
+
+    private final EdgeMetadataSerialization edgeMetadataSerialization;
+
+
+    private final EdgeSerialization edgeSerialization;
+
+    private final NodeSerialization nodeSerialization;
+
+    private final AsyncProcessor<Edge> edgeWriteAsyncProcessor;
+    private final AsyncProcessor<Edge> edgeDeleteAsyncProcessor;
+    private final AsyncProcessor<Id> nodeDeleteAsyncProcessor;
+
+    private final GraphFig graphFig;
+
+
+    @Inject
+    public GraphManagerImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
+                            final EdgeSerialization edgeSerialization, final NodeSerialization nodeSerialization,
+                            final GraphFig graphFig, @EdgeWrite final AsyncProcessor edgeWrite,
+                            @EdgeDelete final AsyncProcessor edgeDelete, @NodeDelete final AsyncProcessor nodeDelete,
+                            @Assisted final OrganizationScope scope ) {
+
+        ValidationUtils.validateOrganizationScope( scope );
+
+
+        this.scope = scope;
+        this.edgeMetadataSerialization = edgeMetadataSerialization;
+        this.edgeSerialization = edgeSerialization;
+        this.nodeSerialization = nodeSerialization;
+        this.graphFig = graphFig;
+
+
+        this.edgeWriteAsyncProcessor = edgeWrite;
+
+
+        this.edgeDeleteAsyncProcessor = edgeDelete;
+
+
+        this.nodeDeleteAsyncProcessor = nodeDelete;
+    }
+
+
+    @Override
+    public Observable<Edge> writeEdge( final Edge edge ) {
+        EdgeUtils.validateEdge( edge );
+
+        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
+            @Override
+            public Edge call( final Edge edge ) {
+                final MutationBatch mutation = edgeMetadataSerialization.writeEdge( scope, edge );
+
+                final MutationBatch edgeMutation = edgeSerialization.writeEdge( scope, edge );
+
+                mutation.mergeShallow( edgeMutation );
+
+                final AsynchronousMessage<Edge> event = edgeWriteAsyncProcessor.setVerification( edge, getTimeout() );
+
+                try {
+                    mutation.execute();
+                }
+                catch ( ConnectionException e ) {
+                    throw new RuntimeException( "Unable to connect to cassandra", e );
+                }
+
+                edgeWriteAsyncProcessor.start( event );
+
+                return edge;
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<Edge> deleteEdge( final Edge edge ) {
+        EdgeUtils.validateEdge( edge );
+
+        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
+            @Override
+            public Edge call( final Edge edge ) {
+                final MutationBatch edgeMutation = edgeSerialization.markEdge( scope, edge );
+
+                final AsynchronousMessage<Edge> event = edgeDeleteAsyncProcessor.setVerification( edge, getTimeout() );
+
+
+                try {
+                    edgeMutation.execute();
+                }
+                catch ( ConnectionException e ) {
+                    throw new RuntimeException( "Unable to connect to cassandra", e );
+                }
+
+                edgeDeleteAsyncProcessor.start( event );
+
+
+                return edge;
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<Id> deleteNode( final Id node ) {
+        return Observable.from( node ).subscribeOn(  Schedulers.io() ).map( new Func1<Id, Id>() {
+            @Override
+            public Id call( final Id id ) {
+
+                //mark the node as deleted
+                final UUID deleteTime = UUIDGenerator.newTimeUUID();
+
+                final MutationBatch nodeMutation = nodeSerialization.mark( scope, id, deleteTime );
+
+                final AsynchronousMessage<Id> event = nodeDeleteAsyncProcessor.setVerification( node, getTimeout() );
+
+
+                try {
+                    nodeMutation.execute();
+                }
+                catch ( ConnectionException e ) {
+                    throw new RuntimeException( "Unable to connect to cassandra", e );
+                }
+
+                nodeDeleteAsyncProcessor.start( event );
+
+                return id;
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<Edge> loadEdgeVersions( final SearchByEdge searchByEdge ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
+            @Override
+            protected Iterator<MarkedEdge> getIterator() {
+                return edgeSerialization.getEdgeVersions( scope, searchByEdge );
+            }
+        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( searchByEdge.getMaxVersion() ) )
+                         .cast( Edge.class );
+    }
+
+
+    @Override
+    public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
+            @Override
+            protected Iterator<MarkedEdge> getIterator() {
+                return edgeSerialization.getEdgesFromSource( scope, search );
+            }
+        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
+                         .cast( Edge.class );
+    }
+
+
+    @Override
+    public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
+            @Override
+            protected Iterator<MarkedEdge> getIterator() {
+                return edgeSerialization.getEdgesToTarget( scope, search );
+            }
+        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
+                         .cast( Edge.class );
+    }
+
+
+    @Override
+    public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
+            @Override
+            protected Iterator<MarkedEdge> getIterator() {
+                return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
+            }
+        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
+
+                         .cast( Edge.class );
+    }
+
+
+    @Override
+    public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>() {
+            @Override
+            protected Iterator<MarkedEdge> getIterator() {
+                return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
+            }
+        } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
+                         .cast( Edge.class );
+    }
+
+
+    @Override
+    public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
+
+        return Observable.create( new ObservableIterator<String>() {
+            @Override
+            protected Iterator<String> getIterator() {
+                return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
+        return Observable.create( new ObservableIterator<String>() {
+            @Override
+            protected Iterator<String> getIterator() {
+                return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
+
+        return Observable.create( new ObservableIterator<String>() {
+            @Override
+            protected Iterator<String> getIterator() {
+                return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
+            }
+        } );
+    }
+
+
+    @Override
+    public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
+        return Observable.create( new ObservableIterator<String>() {
+            @Override
+            protected Iterator<String> getIterator() {
+                return edgeMetadataSerialization.getIdTypesToTarget( scope, search );
+            }
+        } );
+    }
+
+
+    /**
+     * Get our timeout for write consistency
+     */
+    private long getTimeout() {
+        return graphFig.getRepairTimeout() * 2;
+    }
+
+
+    /**
+     * Helper filter to perform mapping and return an observable of pre-filtered edges
+     */
+    private class EdgeBufferFilter implements Func1<List<MarkedEdge>, Observable<MarkedEdge>> {
+
+        private final UUID maxVersion;
+
+
+        private EdgeBufferFilter( final UUID maxVersion ) {
+            this.maxVersion = maxVersion;
+        }
+
+
+        /**
+         * Takes a buffered list of marked edges.  It then does a single round trip to fetch marked ids These are then
+         * used in conjunction with the max version filter to filter any edges that should not be returned
+         *
+         * @return An observable that emits only edges that can be consumed.  There could be multiple versions of the
+         *         same edge so those need de-duped.
+         */
+        @Override
+        public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
+
+            final Map<Id, UUID> markedVersions = nodeSerialization.getMaxVersions( scope, markedEdges );
+            return Observable.from( markedEdges )
+                             .filter( new EdgeFilter( this.maxVersion, markedVersions ) );
+        }
+    }
+
+
+    /**
+     * Filter the returned values based on the max uuid and if it's been marked for deletion or not
+     */
+    private static class EdgeFilter implements Func1<MarkedEdge, Boolean> {
+
+        private final UUID maxVersion;
+
+        private final Map<Id, UUID> markCache;
+
+
+        private EdgeFilter( final UUID maxVersion, Map<Id, UUID> markCache ) {
+            this.maxVersion = maxVersion;
+            this.markCache = markCache;
+        }
+
+
+        @Override
+        public Boolean call( final MarkedEdge edge ) {
+
+
+            final UUID edgeVersion = edge.getVersion();
+
+            //our edge needs to not be deleted and have a version that's > max Version
+            if ( edge.isDeleted() || UUIDComparator.staticCompare( edgeVersion, maxVersion ) > 0 ) {
+                return false;
+            }
+
+
+            final UUID sourceVersion = markCache.get( edge.getSourceNode() );
+
+            //the source Id has been marked for deletion.  It's version is <= to the marked version for deletion,
+            // so we need to discard it
+            if ( sourceVersion != null && UUIDComparator.staticCompare( edgeVersion, sourceVersion ) < 1 ) {
+                return false;
+            }
+
+            final UUID targetVersion = markCache.get( edge.getTargetNode() );
+
+            //the target Id has been marked for deletion.  It's version is <= to the marked version for deletion,
+            // so we need to discard it
+            if ( targetVersion != null && UUIDComparator.staticCompare( edgeVersion, targetVersion ) < 1 ) {
+                return false;
+            }
+
+
+            return true;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index 190bbff..4ba0142 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -2,11 +2,14 @@ package org.apache.usergrid.persistence.graph.impl;
 
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.cassandra.thrift.Mutation;
+
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.GraphFig;
@@ -26,11 +29,13 @@ import org.apache.usergrid.persistence.model.entity.Id;
 
 import com.google.common.base.Optional;
 import com.google.inject.Inject;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Action0;
+import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
@@ -48,16 +53,30 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     private final EdgeMetadataSerialization edgeMetadataSerialization;
     private final EdgeDeleteRepair edgeDeleteRepair;
     private final EdgeMetaRepair edgeMetaRepair;
+<<<<<<< Updated upstream
+=======
+    private final GraphFig graphFig;
+    protected final Keyspace keyspace;
+>>>>>>> Stashed changes
 
 
     /**
      * Wire the serialization dependencies
      */
     @Inject
+<<<<<<< Updated upstream
     public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization, @NodeDelete final AsyncProcessor nodeDelete,
                                final EdgeMetadataSerialization edgeMetadataSerialization,
                                final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair
                                 ) {
+=======
+    public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,
+
+                               final EdgeMetadataSerialization edgeMetadataSerialization,
+                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair,
+                               final GraphFig graphFig, @NodeDelete final AsyncProcessor nodeDelete,
+                               final Keyspace keyspace ) {
+>>>>>>> Stashed changes
 
 
         this.nodeSerialization = nodeSerialization;
@@ -65,6 +84,8 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
         this.edgeMetadataSerialization = edgeMetadataSerialization;
         this.edgeDeleteRepair = edgeDeleteRepair;
         this.edgeMetaRepair = edgeMetaRepair;
+        this.graphFig = graphFig;
+        this.keyspace = keyspace;
 
         nodeDelete.addListener( this );
     }
@@ -72,8 +93,11 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
 
     /**
      * Removes this node from the graph.
+     *
      * @param edgeEvent The edge event that was fired.
-     * @return An observable that emits the total number of edges that have been removed with this node both as the target and source
+     *
+     * @return An observable that emits the total number of edges that have been removed with this node both as the
+     *         target and source
      */
     @Override
     public Observable<Integer> receive( final EdgeEvent<Id> edgeEvent ) {
@@ -112,17 +136,9 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                                             @Override
                                             public Observable<MarkedEdge> call( final String edgeType ) {
                                                 return loadEdgesToTarget( scope,
-                                                        new SimpleSearchByEdgeType( node, edgeType, version,
-                                                                null ) );
+                                                        new SimpleSearchByEdgeType( node, edgeType, version, null ) );
                                             }
-                                        } )
-                                        //filter "old" edges, since we'll be deleting them in 1 shot
-                                        .distinctUntilChanged( new Func1<Edge, Id>() {
-                                    @Override
-                                    public Id call( final Edge edge ) {
-                                        return edge.getSourceNode();
-                                    }
-                                } );
+                                        } );
 
 
                         //get all edges pointing to the source node and buffer them into groups for deletion
@@ -132,60 +148,71 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                                             @Override
                                             public Observable<MarkedEdge> call( final String edgeType ) {
                                                 return loadEdgesFromSource( scope,
-                                                        new SimpleSearchByEdgeType( node, edgeType, version,
-                                                                null ) );
+                                                        new SimpleSearchByEdgeType( node, edgeType, version, null ) );
                                             }
-                                        } )
-                                        //filter "old" edges, since we'll be deleting them in 1 shot
-                                        .distinctUntilChanged( new Func1<Edge, Id>() {
-                                    @Override
-                                    public Id call( final Edge edge ) {
-                                        return edge.getTargetNode();
-                                    }
-                                } );
+                                        } );
 
 
                         //each time an edge is emitted, delete it via batch mutation since we'll already be buffered
-                        return Observable.concat( targetEdges, sourceEdges );
+                        return Observable.merge( targetEdges, sourceEdges );
                     }
-                } ).flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
-                    @Override
-                    public Observable<MarkedEdge> call( final MarkedEdge edge ) {
-
-                        //delete the newest edge <= the version on the node delete
-                        LOG.debug( "Deleting edge {}", edge );
-                        return edgeDeleteRepair.repair( scope, edge );
-
-
-                    }
-                } ).flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
-                    @Override
-                    public Observable<MarkedEdge> call( final MarkedEdge edge ) {
+                } )
+                //buffer and delete marked edges in our buffer size
+                .buffer( graphFig.getScanPageSize() ).flatMap(
+                        new Func1<List<MarkedEdge>, Observable<MarkedEdge>>() {
+                            @Override
+                            public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
 
+                                final MutationBatch batch = keyspace.prepareMutationBatch();
 
+                                for(MarkedEdge edge: markedEdges){
 
-                        //delete both the source and target meta data in parallel for the edge we deleted in the previous step
-                        //if nothing else is using them
-                        Observable<Integer> sourceMetaRepaired =
-                                edgeMetaRepair.repairSources( scope, edge.getSourceNode(), edge.getType(), version );
+                                //delete the newest edge <= the version on the node delete
+                                    LOG.debug( "Deleting edge {}", edge );
+                                    final MutationBatch delete = edgeSerialization.deleteEdge( scope,  edge );
 
-                        Observable<Integer>  targetMetaRepaired = edgeMetaRepair.repairTargets( scope,
-                                edge.getTargetNode(), edge.getType(), version );
+                                    batch.mergeShallow( delete );
+                                }
 
-                        //sum up the number of subtypes we retain
-                        return Observable.concat(sourceMetaRepaired, targetMetaRepaired ).last().map( new Func1
-                                <Integer, MarkedEdge>() {
-                            @Override
-                            public MarkedEdge call( final Integer integer ) {
+                                try {
+                                    batch.execute();
+                                }
+                                catch ( ConnectionException e ) {
+                                    throw new RuntimeException( "Unable to delete edges", e );
+                                }
 
-                                LOG.debug( "Retained {} subtypes for edge {}", integer, edge );
-
-                                return edge;
+                                return Observable.from(markedEdges);
                             }
-                        } );
-                    }
-                } ).count()
-                //if nothing is ever emitted, emit 0 so that we know no operations took place. Finally remove the target node in the mark
+                        } )
+        .flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
+            @Override
+            public Observable<MarkedEdge> call( final MarkedEdge edge ) {
+
+
+                return Observable.just( edge );
+//                //delete both the source and target meta data in parallel for the edge we deleted in the previous step
+//                //if nothing else is using them
+//                Observable<Integer> sourceMetaRepaired =
+//                        edgeMetaRepair.repairSources( scope, edge.getSourceNode(), edge.getType(), version );
+//
+//                Observable<Integer> targetMetaRepaired =
+//                        edgeMetaRepair.repairTargets( scope, edge.getTargetNode(), edge.getType(), version );
+//
+//                //sum up the number of subtypes we retain
+//                return Observable.concat( sourceMetaRepaired, targetMetaRepaired ).last()
+//                                 .map( new Func1<Integer, MarkedEdge>() {
+//                                     @Override
+//                                     public MarkedEdge call( final Integer integer ) {
+//
+//                                         LOG.debug( "Retained {} subtypes for edge {}", integer, edge );
+//
+//                                         return edge;
+//                                     }
+//                                 } );
+            }
+        } ).count()
+                //if nothing is ever emitted, emit 0 so that we know no operations took place. Finally remove the
+                // target node in the mark
                 .defaultIfEmpty( 0 ).doOnCompleted( new Action0() {
                     @Override
                     public void call() {
@@ -193,7 +220,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                             nodeSerialization.delete( scope, node, version ).execute();
                         }
                         catch ( ConnectionException e ) {
-                            throw new RuntimeException("Unable to delete marked graph node " + node, e);
+                            throw new RuntimeException( "Unable to delete marked graph node " + node, e );
                         }
                     }
                 } );
@@ -254,6 +281,4 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
             }
         } ).subscribeOn( Schedulers.io() );
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/136edaba/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index 3ff7178..310fa1f 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -77,15 +77,13 @@ public abstract class AbstractEdgeRepair  {
         final UUID maxVersion = edge.getVersion();
 
         //get source edges
-        Observable<MarkedEdge> sourceEdges = getEdgeVersionsFromSource( scope, edge );
+        Observable<MarkedEdge> edgeVersions = getEdgeVersions( scope, edge );
 
-        //get target edges
-        Observable<MarkedEdge> targetEdges = getEdgeVersionsToTarget( scope, edge );
 
 
 
         //merge source and target then deal with the distinct values
-        return Observable.merge( sourceEdges, targetEdges ).filter( getFilter( maxVersion ) ).distinctUntilChanged().buffer( graphFig.getScanPageSize() )
+        return edgeVersions.filter( getFilter( maxVersion ) ).buffer( graphFig.getScanPageSize() )
                          .flatMap( new Func1<List<MarkedEdge>, Observable<MarkedEdge>>() {
                              @Override
                              public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
@@ -122,7 +120,7 @@ public abstract class AbstractEdgeRepair  {
     /**
      * Get all edge versions <= the specified max from the source
      */
-    private Observable<MarkedEdge> getEdgeVersionsFromSource( final OrganizationScope scope, final Edge edge ) {
+    private Observable<MarkedEdge> getEdgeVersions( final OrganizationScope scope, final Edge edge ) {
 
         return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
             @Override
@@ -130,24 +128,7 @@ public abstract class AbstractEdgeRepair  {
 
                 final SimpleSearchByEdge search = getSearchByEdge(edge);
 
-                return edgeSerialization.getEdgeFromSource( scope, search );
-            }
-        } ).subscribeOn( Schedulers.io() );
-    }
-
-
-    /**
-     * Get all edge versions <= the specified max from the source
-     */
-    private Observable<MarkedEdge> getEdgeVersionsToTarget( final OrganizationScope scope, final Edge edge ) {
-
-        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
-            @Override
-            protected Iterator<MarkedEdge> getIterator() {
-
-                final SimpleSearchByEdge search = getSearchByEdge(edge);
-
-                return edgeSerialization.getEdgeToTarget( scope, search );
+                return edgeSerialization.getEdgeVersions( scope, search );
             }
         } ).subscribeOn( Schedulers.io() );
     }


[21/27] Updated tests. Need to figure a work around for Mockito

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
index ed8c1b8..8685b65 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerTimeoutIT.java
@@ -132,6 +132,8 @@ public class GraphManagerTimeoutIT {
         final MockingIterator<MarkedEdge> itr = new MockingIterator<>( Collections.singletonList( edge ) );
 
 
+        //TODO, T.N. replace this with a different mock, the spies don't work with multi threading like RX
+        //https://code.google.com/p/mockito/wiki/FAQ#Is_Mockito_thread-safe?
         when( serialization.getEdgesFromSource( scope, search ) ).thenReturn( itr );
 
         Observable<Edge> edges = em.loadEdgesFromSource( search );
@@ -220,1340 +222,6 @@ public class GraphManagerTimeoutIT {
     }
 
 
-    @Test
-    public void testWriteReadEdgeTypeTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    /**
-     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
-     */
-    @Test
-    public void testWriteReadEdgeTypeVersionSourceDistinct() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTargetDistinct() {
-
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final Id sourceId = createId( "source" );
-
-
-        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge3, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingTarget() {
-
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        final Id targetId = createId( "target" );
-
-        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge3, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypes() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        Observable<String> edges =
-                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-
-        //now get types for test2
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypes() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId1 = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get types for test2
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypesPaging() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
-
-        edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get the next page
-
-        edges = em.getIdTypesFromSource(
-                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypesPaging() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
-
-        edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now get the next page
-
-        edges = em.getIdTypesToTarget(
-                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testMarkSourceEdges() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdges() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges =
-                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkSourceEdgesType() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdgesType() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
-                        null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void markSourceNode() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( sourceId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void markTargetNode() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( targetId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void invalidEdgeTypesWrite( @All Edge edge ) {
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        em.writeEdge( edge );
-    }
-
-
-    @Test( expected = NullPointerException.class )
-    public void invalidEdgeTypesDelete( @All Edge edge ) {
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        em.deleteEdge( edge );
-    }
-
-    //
-    //    public static class InvalidInput extends JukitoModule {
-    //
-    //        @Override
-    //        protected void configureTest() {
-    //create all edge types of junk input
-    //
-    //            final UUID version = UUIDGenerator.newTimeUUID();
-    //
-    //            Id nullUuid = mock( Id.class );
-    //            when( nullUuid.getUuid() ).thenReturn( null );
-    //
-    //
-    //            Id nullType = mock( Id.class );
-    //            when( nullType.getType() ).thenReturn( "type" );
-    //
-    //            Edge[] edges = new Edge[] {
-    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( nullType, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullType, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
-    //            };
-    //
-    //
-    //            bindManyInstances( Edge.class, edges );
-    //
-    //        }
-    //
-    //
-    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
-    //            Edge edge = mock( Edge.class );
-    //
-    //            when( edge.getSourceNode() ).thenReturn( sourceId );
-    //            when( edge.getType() ).thenReturn( type );
-    //            when( edge.getTargetNode() ).thenReturn( targetId );
-    //            when( edge.getVersion() ).thenReturn( version );
-    //
-    //            return edge;
-    //        }
-    //    }
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
index 14ab9c4..b106df3 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
@@ -54,8 +54,8 @@ public class NodeDeleteListenerTest {
 
     private static final Logger log = LoggerFactory.getLogger( NodeDeleteListenerTest.class );
 
-//    @ClassRule
-//    public static CassandraRule rule = new CassandraRule();
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
 
 
     @Inject


[19/27] git commit: Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.


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

Branch: refs/heads/entity-manager
Commit: b516f57899c8a53ddd2f170ca84faf10183b909a
Parents: 8f969d8
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 26 15:12:58 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 26 15:17:20 2014 -0400

----------------------------------------------------------------------
 .../persistence/query/tree/QueryFilter.g        |  311 ------
 .../persistence/exceptions/IndexException.java  |   41 -
 .../exceptions/JsonReadException.java           |   29 -
 .../exceptions/JsonWriteException.java          |   29 -
 .../exceptions/NoFullTextIndexException.java    |   52 -
 .../exceptions/NoIndexException.java            |   50 -
 .../exceptions/PersistenceException.java        |   47 -
 .../persistence/exceptions/QueryException.java  |   41 -
 .../exceptions/QueryParseException.java         |   65 --
 .../exceptions/QueryTokenException.java         |   54 -
 .../usergrid/persistence/query/EntityRef.java   |   30 -
 .../usergrid/persistence/query/Query.java       | 1015 ------------------
 .../usergrid/persistence/query/Results.java     |  126 ---
 .../persistence/query/SimpleEntityRef.java      |  131 ---
 .../persistence/query/tree/AndOperand.java      |   50 -
 .../persistence/query/tree/BooleanLiteral.java  |   50 -
 .../persistence/query/tree/BooleanOperand.java  |   50 -
 .../persistence/query/tree/ContainsOperand.java |   71 --
 .../query/tree/ContainsProperty.java            |   59 -
 .../usergrid/persistence/query/tree/Equal.java  |   54 -
 .../persistence/query/tree/EqualityOperand.java |   90 --
 .../persistence/query/tree/FloatLiteral.java    |   59 -
 .../persistence/query/tree/GreaterThan.java     |   55 -
 .../query/tree/GreaterThanEqual.java            |   59 -
 .../persistence/query/tree/LessThan.java        |   55 -
 .../persistence/query/tree/LessThanEqual.java   |   57 -
 .../persistence/query/tree/Literal.java         |   41 -
 .../persistence/query/tree/LiteralFactory.java  |   61 --
 .../persistence/query/tree/LongLiteral.java     |   67 --
 .../persistence/query/tree/NotOperand.java      |   45 -
 .../persistence/query/tree/NumericLiteral.java  |   27 -
 .../persistence/query/tree/Operand.java         |   50 -
 .../persistence/query/tree/OrOperand.java       |   56 -
 .../persistence/query/tree/Property.java        |   65 --
 .../persistence/query/tree/QueryVisitor.java    |  102 --
 .../persistence/query/tree/StringLiteral.java   |   85 --
 .../persistence/query/tree/UUIDLiteral.java     |   52 -
 .../persistence/query/tree/WithinOperand.java   |  111 --
 .../persistence/query/tree/WithinProperty.java  |   57 -
 .../org/apache/usergrid/utils/ClassUtils.java   |   58 -
 .../apache/usergrid/utils/ConversionUtils.java  |  765 -------------
 .../apache/usergrid/utils/EntityBuilder.java    |  177 ---
 .../org/apache/usergrid/utils/JsonUtils.java    |  329 ------
 .../org/apache/usergrid/utils/ListUtils.java    |  232 ----
 .../org/apache/usergrid/utils/MapUtils.java     |  377 -------
 .../org/apache/usergrid/utils/StringUtils.java  |  172 ---
 .../org/apache/usergrid/utils/UUIDUtils.java    |  412 -------
 47 files changed, 6071 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g b/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g
deleted file mode 100644
index d39069b..0000000
--- a/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g
+++ /dev/null
@@ -1,311 +0,0 @@
-grammar QueryFilter;
-//NOTES:  '^' denotes operator, all others in the string become operands
-
-options {
-    output=AST;
-//    ASTLabelType=CommonTree;
-}
-
-@rulecatch { }
-
-
-@header {
-package org.apache.usergrid.persistence.query.tree;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Query.SortPredicate;
-
-}
-
-
-@members {
-	Query query = new Query();
-
-  private static final Logger logger = LoggerFactory
-      .getLogger(QueryFilterLexer.class);
-
-	@Override
-	public void emitErrorMessage(String msg) {
-		logger.info(msg);
-	}
-}
-
-
-@lexer::header {
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.exceptions.QueryTokenException;
-
-}
-
-@lexer::members {
-
-
-
-  private static final Logger logger = LoggerFactory
-      .getLogger(QueryFilterLexer.class);
-
-
-
-
-	@Override
-	public void emitErrorMessage(String msg) {
-		logger.info(msg);
-	}
-
-	@Override
-    public void recover(RecognitionException e) {
-         //We don't want to recover, we want to re-throw to the user since they passed us invalid input
-         throw new QueryTokenException(e);
-    }
-
-
-}
-
-//these must come before ID. Otherwise lt, lte, eq, etc will be returned as id tokens
-LT  : '<' | 'lt';
-
-LTE : '<=' |  'lte';
-
-EQ  : '=' | 'eq';
-
-GT  : '>' | 'gt';
-
-GTE : '>=' |  'gte';  
-
-
-//keywords before var ids
-BOOLEAN : (TRUE|FALSE);
-
-AND : ('A'|'a')('N'|'n')('D'|'d') | '&&';
-
-OR  : ('O'|'o')('R'|'r') | '||' ;
-
-NOT : ('N'|'n')('O'|'o')('T'|'t');
-
-ASC : ('A'|'a')('S'|'s')('C'|'c');
-
-DESC : ('D'|'d')('E'|'e')('S'|'s')('C'|'c');
-
-CONTAINS : ('C'|'c')('O'|'o')('N'|'n')('T'|'t')('A'|'a')('I'|'i')('N'|'n')('S'|'s');
-
-WITHIN : ('W'|'w')('I'|'i')('T'|'t')('H'|'h')('I'|'i')('N'|'n');
-
-OF : ('O'|'o')('F'|'f');
-
-UUID :  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' 
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-  HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-  ;
-
-//ids and values
-ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|'-')*
-    ;
-
-LONG :	('-')? '0'..'9'+
-    ;
-
-FLOAT
-    :  ('-')? ( ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
-    |   '.' ('0'..'9')+ EXPONENT?
-    |   ('0'..'9')+ EXPONENT)
-    ;
-    
-STRING
-    :  '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
-    ;
-
-
-    
-WS : (' ' | '\t' | '\n' | '\r' | '\f')+  {$channel=HIDDEN;};
-
-
-
-    
-
-
-
-fragment TRUE : ('T'|'t')('R'|'r')('U'|'u')('E'|'e');
-
-fragment FALSE : ('F'|'f')('A'|'a')('L'|'l')('S'|'s')('E'|'e');
-
-
-fragment
-EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
-
-fragment
-HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
-
-fragment
-ESC_SEQ
-    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
-    |   UNICODE_ESC
-    |   OCTAL_ESC
-    ;
-
-fragment
-OCTAL_ESC
-    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
-    |   '\\' ('0'..'7') ('0'..'7')
-    |   '\\' ('0'..'7')
-    ;
-
-fragment
-UNICODE_ESC
-    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-    ;
-
-
-
-
-//NE : '!=';
-
-
-
-property :	ID<Property>;
-
-containsproperty : ID<ContainsProperty>;
-
-withinproperty : ID<WithinProperty>;
-	
-booleanliteral: BOOLEAN<BooleanLiteral>;
-
-
-longliteral :
-  LONG<LongLiteral> ;
-
-uuidliteral :
-  UUID<UUIDLiteral>;
-
-stringliteral :
-  STRING<StringLiteral>;
-  
-floatliteral :
-  FLOAT<FloatLiteral> ;
-
-//We delegate to each sub class literal so we can get each type	
-value : 
-  booleanliteral
-  | longliteral
-  | uuidliteral
-  | stringliteral
-  | floatliteral
-  ;
-  
-
-
-//Every operand returns with the name of 'op'.  This is used because all subtrees require operands,
-//this allows us to link the java code easily by using the same name as a converntion
-
-//begin search expressions
-  
-//mathmatical equality operations
-equalityop :
-  property LT<LessThan>^ value
-  |property LTE<LessThanEqual>^ value
-  |property EQ<Equal>^ value
-  |property GT<GreaterThan>^ value
-  |property GTE<GreaterThanEqual>^ value
-  ; 
-
-//geo location search
-locationop :
-  withinproperty WITHIN<WithinOperand>^ (floatliteral|longliteral) OF! (floatliteral|longliteral) ','! (floatliteral|longliteral);
-  
-//string search
-containsop :
-  containsproperty CONTAINS<ContainsOperand>^ stringliteral;
-
-//
-operation :
- '('! expression ')'!
-   | equalityop 
-   | locationop 
-   | containsop 
-   ;
-
-//negations of expressions
-notexp :
-//only link if we have the not
- NOT<NotOperand>^ operation  
- |operation 
- ;
-
-//and expressions contain operands.  These should always be closer to the leaves of a tree, it allows
-//for faster result intersection sooner in the query execution
-andexp :
- notexp (AND<AndOperand>^ notexp )*;
- 
- 
-//or expression should always be after AND expressions.  This will give us a smaller result set to union when evaluating trees
-//also a root level expression
-expression :
- andexp (OR<OrOperand>^ andexp )*;
-
-
-
-//end expressions
-
-//begin order clauses
-
-//direction for ordering
-direction  : (ASC | DESC);
-
-//order clause
-order
-  : (property direction?){
-		String property = $property.text; 
-		String direction = $direction.text;
-		query.addSort(new SortPredicate(property, direction));
-    
-  };
-
-//end order clauses
-  
-//Begin select clauses
-
-select_subject
-  : ID {
-
-  query.addSelect($ID.text);
-
-};
-
- 
-
-select_assign
-  : target=ID ':' source=ID {
-
-  query.addSelect($target.text, $source.text);
-
-};
-
-select_expr 
-  : ('*' | select_subject (',' select_subject) * | '{' select_assign (',' select_assign) * '}');  
-   
-//end select clauses
-
-ql returns [Query query]
-  : ('select'! select_expr!)? ('where'!? expression)? ('order by'! order! (','! order!)*)? {
-
-  if($expression.tree instanceof Operand){
-    query.setRootOperand((Operand)$expression.tree);
-  }
-  
-  retval.query = query;
-
-
-};
-
-
-

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/IndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/IndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/IndexException.java
deleted file mode 100644
index ab625d2..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/IndexException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-public class IndexException extends RuntimeException {
-
-    public IndexException() {
-        super();
-    }
-
-
-    public IndexException( String message, Throwable cause ) {
-        super( message, cause );
-    }
-
-
-    public IndexException( String message ) {
-        super( message );
-    }
-
-
-    public IndexException( Throwable cause ) {
-        super( cause );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java
deleted file mode 100644
index f060a2f..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.exceptions;
-
-
-public class JsonReadException extends RuntimeException {
-    private static final long serialVersionUID = 1L;
-
-
-    public JsonReadException( String msg, Throwable t ) {
-        super( msg, t );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java
deleted file mode 100644
index 20dcacb..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.exceptions;
-
-
-public class JsonWriteException extends RuntimeException {
-    private static final long serialVersionUID = 1L;
-
-
-    public JsonWriteException( String msg, Throwable t ) {
-        super( msg, t );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java
deleted file mode 100644
index b4eb0e6..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-/**
- * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed
- *
- * @author tnine
- */
-public class NoFullTextIndexException extends PersistenceException {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-    final String entityType;
-    final String propertyName;
-
-
-    public NoFullTextIndexException( String entityType, String propertyName ) {
-        super( "Entity '" + entityType + "' with property named '" + propertyName
-                + "' is not full text indexed.  You cannot use the 'contains' operand on this field" );
-        this.entityType = entityType;
-        this.propertyName = propertyName;
-    }
-
-
-    public String getEntityType() {
-        return entityType;
-    }
-
-
-    public String getPropertyName() {
-        return propertyName;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java
deleted file mode 100644
index 2ee5107..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.usergrid.persistence.exceptions;
-
-
-/**
- * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed
- *
- * @author tnine
- */
-public class NoIndexException extends PersistenceException {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-    final String entityType;
-    final String propertyName;
-
-
-    public NoIndexException( String entityType, String propertyName ) {
-        super( "Entity '" + entityType + "' with property named '" + propertyName
-                + "' is not indexed.  You cannot use the this field in queries." );
-        this.entityType = entityType;
-        this.propertyName = propertyName;
-    }
-
-
-    public String getEntityType() {
-        return entityType;
-    }
-
-
-    public String getPropertyName() {
-        return propertyName;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java
deleted file mode 100644
index 6b008e1..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-public class PersistenceException extends Exception {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-
-
-    public PersistenceException() {
-        super();
-    }
-
-
-    public PersistenceException( String message, Throwable cause ) {
-        super( message, cause );
-    }
-
-
-    public PersistenceException( String message ) {
-        super( message );
-    }
-
-
-    public PersistenceException( Throwable cause ) {
-        super( cause );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryException.java
deleted file mode 100644
index e8f9b43..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-public class QueryException extends RuntimeException {
-
-    public QueryException() {
-        super();
-    }
-
-
-    public QueryException( String message, Throwable cause ) {
-        super( message, cause );
-    }
-
-
-    public QueryException( String message ) {
-        super( message );
-    }
-
-
-    public QueryException( Throwable cause ) {
-        super( cause );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java
deleted file mode 100644
index 3c2524b..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-/**
- * An exception thrown when a query cannot be parsed
- *
- * @author tnine
- */
-public class QueryParseException extends RuntimeException {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-
-
-    /**
-     *
-     */
-    public QueryParseException() {
-        super();
-    }
-
-
-    /**
-     * @param arg0
-     * @param arg1
-     */
-    public QueryParseException( String arg0, Throwable arg1 ) {
-        super( arg0, arg1 );
-    }
-
-
-    /**
-     * @param arg0
-     */
-    public QueryParseException( String arg0 ) {
-        super( arg0 );
-    }
-
-
-    /**
-     * @param arg0
-     */
-    public QueryParseException( Throwable arg0 ) {
-        super( arg0 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java
deleted file mode 100644
index 864dfea..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.exceptions;
-
-
-/**
- * An exception thrown when a query encounters a token it doesn't recognize
- * @author tnine
- */
-public class QueryTokenException extends RuntimeException {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-
-
-
-
-    /**
-     * @param arg0
-     */
-    public QueryTokenException( Throwable arg0 ) {
-        super( arg0 );
-    }
-
-
-    @Override
-    public String getMessage() {
-        //antlr errors or strange.  We have to do this, there's no message
-        return getCause().toString();
-    }
-
-
-    @Override
-    public String getLocalizedMessage() {
-        return getMessage();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/EntityRef.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/EntityRef.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/EntityRef.java
deleted file mode 100644
index b05b442..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/EntityRef.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query;
-
-
-import java.util.UUID;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-public interface EntityRef {
-
-    public Id getId();
-
-    public UUID getVersion();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
deleted file mode 100644
index c82ff3b..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
+++ /dev/null
@@ -1,1015 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query;
-
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.UUID;
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RecognitionException;
-import org.antlr.runtime.Token;
-import org.antlr.runtime.TokenRewriteStream;
-import static org.apache.commons.codec.binary.Base64.decodeBase64;
-import org.apache.commons.lang.StringUtils;
-import static org.apache.commons.lang.StringUtils.isBlank;
-import static org.apache.commons.lang.StringUtils.split;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-import org.apache.usergrid.persistence.exceptions.QueryParseException;
-import org.apache.usergrid.persistence.index.impl.EsQueryVistor;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.tree.AndOperand;
-import org.apache.usergrid.persistence.query.tree.ContainsOperand;
-import org.apache.usergrid.persistence.query.tree.Equal;
-import org.apache.usergrid.persistence.query.tree.EqualityOperand;
-import org.apache.usergrid.persistence.query.tree.GreaterThan;
-import org.apache.usergrid.persistence.query.tree.GreaterThanEqual;
-import org.apache.usergrid.persistence.query.tree.LessThan;
-import org.apache.usergrid.persistence.query.tree.LessThanEqual;
-import org.apache.usergrid.persistence.query.tree.Operand;
-import org.apache.usergrid.persistence.query.tree.QueryFilterLexer;
-import org.apache.usergrid.persistence.query.tree.QueryFilterParser;
-import org.apache.usergrid.persistence.query.tree.QueryVisitor;
-import static org.apache.usergrid.utils.ClassUtils.cast;
-import org.apache.usergrid.utils.JsonUtils;
-import org.apache.usergrid.utils.ListUtils;
-import static org.apache.usergrid.utils.ListUtils.first;
-import static org.apache.usergrid.utils.ListUtils.firstBoolean;
-import static org.apache.usergrid.utils.ListUtils.firstInteger;
-import static org.apache.usergrid.utils.ListUtils.firstLong;
-import static org.apache.usergrid.utils.ListUtils.firstUuid;
-import static org.apache.usergrid.utils.ListUtils.isEmpty;
-import static org.apache.usergrid.utils.MapUtils.toMapList;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class Query {
-    private static final Logger logger = LoggerFactory.getLogger( Query.class );
-
-    public static final int PAGE_SIZE = 1000;
-
-    public static final int DEFAULT_LIMIT = 10;
-    public static final int MAX_LIMIT = 1000;
-    public static final String PROPERTY_ID = "id";
-
-    private String type;
-    private List<SortPredicate> sortPredicates = new ArrayList<SortPredicate>();
-    private Operand rootOperand;
-    private UUID startResult;
-    private String cursor;
-    private int limit = 0;
-
-    private Map<String, String> selectAssignments = new LinkedHashMap<String, String>();
-    private boolean mergeSelectResults = false;
-    private String connection;
-    private List<String> permissions;
-    private boolean reversed;
-    private boolean reversedSet = false;
-    private Long startTime;
-    private Long finishTime;
-    private boolean pad;
-    private List<Id> identifiers;
-    private String collection;
-    private String ql;
-
-
-    public Query() {
-    }
-
-
-    public Query( Query q ) {
-        if ( q != null ) {
-            type = q.type;
-            sortPredicates = q.sortPredicates != null 
-                    ? new ArrayList<SortPredicate>( q.sortPredicates ) : null;
-            startResult = q.startResult;
-            cursor = q.cursor;
-            limit = q.limit;
-            selectAssignments = q.selectAssignments != null 
-                    ? new LinkedHashMap<String, String>( q.selectAssignments ) : null;
-            mergeSelectResults = q.mergeSelectResults;
-            connection = q.connection;
-            permissions = q.permissions != null ? new ArrayList<String>( q.permissions ) : null;
-            reversed = q.reversed;
-            reversedSet = q.reversedSet;
-            startTime = q.startTime;
-            finishTime = q.finishTime;
-            pad = q.pad;
-            rootOperand = q.rootOperand;
-            identifiers = q.identifiers != null ? new ArrayList<Id>( q.identifiers ) : null;
-            collection = q.collection;
-        }
-    }
-
-
-    public QueryBuilder createQueryBuilder() {
-
-        QueryBuilder queryBuilder = null;
-
-        if ( getRootOperand() != null ) {
-            QueryVisitor v = new EsQueryVistor();
-            try {
-                getRootOperand().visit( v );
-
-            } catch ( PersistenceException ex ) {
-                throw new RuntimeException( "Error building ElasticSearch query", ex );
-            }
-            queryBuilder = v.getQueryBuilder();
-        } 
-
-		if ( queryBuilder == null ) {
-            queryBuilder = QueryBuilders.matchAllQuery();
-		}
-
-        return queryBuilder;
-    }
-
-
-	public FilterBuilder createFilterBuilder() {
-	    FilterBuilder filterBuilder = null;
-
-        if ( getRootOperand() != null ) {
-            QueryVisitor v = new EsQueryVistor();
-            try {
-                getRootOperand().visit( v );
-
-            } catch ( PersistenceException ex ) {
-                throw new RuntimeException( "Error building ElasticSearch query", ex );
-            }
-            filterBuilder = v.getFilterBuilder();
-        } 
-
-        return filterBuilder;	
-	}
-
-
-    public static Query fromQL( String ql ) throws QueryParseException {
-        if ( ql == null ) {
-            return null;
-        }
-        String originalQl = ql;
-        ql = ql.trim();
-
-        String qlt = ql.toLowerCase();
-        if ( !qlt.startsWith( "select" ) 
-                && !qlt.startsWith( "insert" ) 
-                && !qlt.startsWith( "update" ) 
-                && !qlt.startsWith( "delete" ) ) {
-            if ( qlt.startsWith( "order by" ) ) {
-                ql = "select * " + ql;
-            }
-            else {
-                ql = "select * where " + ql;
-            }
-        }
-
-        ANTLRStringStream in = new ANTLRStringStream( ql.trim() );
-        QueryFilterLexer lexer = new QueryFilterLexer( in );
-        CommonTokenStream tokens = new CommonTokenStream( lexer );
-        QueryFilterParser parser = new QueryFilterParser( tokens );
-
-        try {
-            Query q = parser.ql().query;
-            q.setQl( originalQl );
-            return q;
-
-        } catch ( RecognitionException e ) {
-            logger.error( "Unable to parse \"{}\"", ql, e );
-            int index = e.index;
-            int lineNumber = e.line;
-            Token token = e.token;
-            String message = String.format("The query cannot be parsed. "
-                    + "The token '%s' at column %d on line %d cannot be parsed", 
-                    token.getText(), index, lineNumber );
-            throw new QueryParseException( message, e );
-        }
-    }
-
-
-    private static Query newQueryIfNull( Query query ) {
-        if ( query == null ) {
-            query = new Query();
-        }
-        return query;
-    }
-
-
-    public static Query fromJsonString( String json ) throws QueryParseException {
-        Object o = JsonUtils.parse( json );
-        if ( o instanceof Map ) {
-            @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, List<String>> params =
-                    cast( toMapList( ( Map ) o ) );
-            return fromQueryParams( params );
-        }
-        return null;
-    }
-
-
-    public static Query fromQueryParams( 
-            Map<String, List<String>> params ) throws QueryParseException {
-
-        Query q = null;
-        List<Id> identifiers = null;
-
-        String ql = Query.queryStrFrom( params );
-        String type = first( params.get( "type" ) );
-        Boolean reversed = firstBoolean( params.get( "reversed" ) );
-        String connection = first( params.get( "connection" ) );
-        UUID start = firstUuid( params.get( "start" ) );
-        String cursor = first( params.get( "cursor" ) );
-        Integer limit = firstInteger( params.get( "limit" ) );
-        List<String> permissions = params.get( "permission" );
-        Long startTime = firstLong( params.get( "start_time" ) );
-        Long finishTime = firstLong( params.get( "end_time" ) );
-
-        Boolean pad = firstBoolean( params.get( "pad" ) );
-
-        for ( Entry<String, List<String>> param : params.entrySet() ) {
-            Id identifier = null;
-            if ( ( param.getValue() == null ) || ( param.getValue().size() == 0 ) ) {
-                if ( identifier != null ) {
-                    if ( identifiers == null ) {
-                        identifiers = new ArrayList<Id>();
-                    }
-                    identifiers.add( identifier );
-                }
-            }
-        }
-
-        if ( ql != null ) {
-            q = Query.fromQL( decode( ql ) );
-        }
-
-        List<String> l = params.get( "filter" );
-
-        if ( !isEmpty( l ) ) {
-            q = newQueryIfNull( q );
-            for ( String s : l ) {
-                q.addFilter( decode( s ) );
-            }
-        }
-
-        l = params.get( "sort" );
-        if ( !isEmpty( l ) ) {
-            q = newQueryIfNull( q );
-            for ( String s : l ) {
-                q.addSort( decode( s ) );
-            }
-        }
-
-        if ( type != null ) {
-            q = newQueryIfNull( q );
-            q.setEntityType( type );
-        }
-
-        if ( connection != null ) {
-            q = newQueryIfNull( q );
-            q.setConnectionType( connection );
-        }
-
-        if ( permissions != null ) {
-            q = newQueryIfNull( q );
-            q.setPermissions( permissions );
-        }
-
-        if ( start != null ) {
-            q = newQueryIfNull( q );
-            q.setStartResult( start );
-        }
-
-        if ( cursor != null ) {
-            q = newQueryIfNull( q );
-            q.setCursor( cursor );
-        }
-
-        if ( limit != null ) {
-            q = newQueryIfNull( q );
-            q.setLimit( limit );
-        }
-
-        if ( startTime != null ) {
-            q = newQueryIfNull( q );
-            q.setStartTime( startTime );
-        }
-
-        if ( finishTime != null ) {
-            q = newQueryIfNull( q );
-            q.setFinishTime( finishTime );
-        }
-
-        if ( pad != null ) {
-            q = newQueryIfNull( q );
-            q.setPad( pad );
-        }
-
-        if ( identifiers != null ) {
-            q = newQueryIfNull( q );
-            q.setIdentifiers( identifiers );
-        }
-
-        if ( reversed != null ) {
-            q = newQueryIfNull( q );
-            q.setReversed( reversed );
-        }
-
-        return q;
-    }
-
-
-    public static Query searchForProperty( String propertyName, Object propertyValue ) {
-        Query q = new Query();
-        q.addEqualityFilter( propertyName, propertyValue );
-        return q;
-    }
-
-
-    public static Query findForProperty( String propertyName, Object propertyValue ) {
-        Query q = new Query();
-        q.addEqualityFilter( propertyName, propertyValue );
-        q.setLimit( 1 );
-        return q;
-    }
-
-
-    public static Query fromId( Id id ) {
-        Query q = new Query();
-        q.addIdentifier( id );
-        return q;
-    }
-
-    public boolean hasQueryPredicates() {
-        return rootOperand != null;
-    }
-
-    public Query addSort( SortPredicate sort ) {
-        if ( sort == null ) {
-            return this;
-        }
-
-        for ( SortPredicate s : sortPredicates ) {
-            if ( s.getPropertyName().equals( sort.getPropertyName() ) ) {
-                throw new QueryParseException(
-                    String.format( 
-                        "Attempted to set sort order for %s more than once", s.getPropertyName()));
-            }
-        }
-        sortPredicates.add( sort );
-        return this;
-    }
-
-
-    public Query withReversed( boolean reversed ) {
-        setReversed( reversed );
-        return this;
-    }
-
-
-    public String getEntityType() {
-        return type;
-    }
-
-
-    public void setEntityType( String type ) {
-        this.type = type;
-    }
-
-
-    public String getConnectionType() {
-        return connection;
-    }
-
-
-    public void setConnectionType( String connection ) {
-        this.connection = connection;
-    }
-
-
-    public List<String> getPermissions() {
-        return permissions;
-    }
-
-
-    public void setPermissions( List<String> permissions ) {
-        this.permissions = permissions;
-    }
-
-
-    public Query addSelect( String select ) {
-
-        return addSelect( select, null );
-    }
-
-
-    public Query addSelect( String select, String output ) {
-        // be paranoid with the null checks because
-        // the query parser sometimes flakes out
-        if ( select == null ) {
-            return this;
-        }
-        select = select.trim();
-
-        if ( select.equals( "*" ) ) {
-            return this;
-        }
-
-        mergeSelectResults = StringUtils.isNotEmpty( output );
-
-        if ( output == null ) {
-            output = "";
-        }
-
-        selectAssignments.put( select, output );
-
-        return this;
-    }
-
-
-    public boolean hasSelectSubjects() {
-        return !selectAssignments.isEmpty();
-    }
-
-
-    @JsonIgnore
-    public Set<String> getSelectSubjects() {
-        return selectAssignments.keySet();
-    }
-
-
-    public Map<String, String> getSelectAssignments() {
-        return selectAssignments;
-    }
-
-
-    boolean isMergeSelectResults() {
-        return mergeSelectResults;
-    }
-
-
-    public Query addSort( String propertyName ) {
-        if ( isBlank( propertyName ) ) {
-            return this;
-        }
-        propertyName = propertyName.trim();
-        if ( propertyName.indexOf( ',' ) >= 0 ) {
-            String[] propertyNames = split( propertyName, ',' );
-            for ( String s : propertyNames ) {
-                addSort( s );
-            }
-            return this;
-        }
-
-        SortDirection direction = SortDirection.ASCENDING;
-        if ( propertyName.indexOf( ' ' ) >= 0 ) {
-            String[] parts = split( propertyName, ' ' );
-            if ( parts.length > 1 ) {
-                propertyName = parts[0];
-                direction = SortDirection.find( parts[1] );
-            }
-        }
-        else if ( propertyName.startsWith( "-" ) ) {
-            propertyName = propertyName.substring( 1 );
-            direction = SortDirection.DESCENDING;
-        }
-        else if ( propertyName.startsWith( "+" ) ) {
-            propertyName = propertyName.substring( 1 );
-            direction = SortDirection.ASCENDING;
-        }
-
-        return addSort( propertyName, direction );
-    }
-
-
-    public Query addSort( String propertyName, SortDirection direction ) {
-        if ( isBlank( propertyName ) ) {
-            return this;
-        }
-        propertyName = propertyName.trim();
-        for ( SortPredicate s : sortPredicates ) {
-            if ( s.getPropertyName().equals( propertyName ) ) {
-                logger.error(
-                        "Attempted to set sort order for " + s.getPropertyName() + " more than once, discarding..." );
-                return this;
-            }
-        }
-        sortPredicates.add( new SortPredicate( propertyName, direction ) );
-        return this;
-    }
-
-
-    @JsonIgnore
-    public boolean isSortSet() {
-        return !sortPredicates.isEmpty();
-    }
-
-
-    public List<SortPredicate> getSortPredicates() {
-        return sortPredicates;
-    }
-
-
-    public Query addFilter( String filter ) {
-
-        ANTLRStringStream in = new ANTLRStringStream( filter );
-        QueryFilterLexer lexer = new QueryFilterLexer( in );
-        TokenRewriteStream tokens = new TokenRewriteStream( lexer );
-        QueryFilterParser parser = new QueryFilterParser( tokens );
-        Operand root = null;
-
-        try {
-            root = parser.ql().query.getRootOperand();
-        }
-        catch ( RecognitionException e ) {
-            // TODO: should we create a specific Exception for this? checked?
-            throw new RuntimeException( "Unknown operation: " + filter, e );
-        }
-
-        if ( root != null ) {
-            addClause( root );
-        }
-
-        return this;
-    }
-
-
-    /** Add a less than filter to this query. && with existing clauses */
-    public Query addLessThanFilter( String propName, Object value ) {
-        LessThan equality = new LessThan( null );
-
-        addClause( equality, propName, value );
-
-        return this;
-    }
-
-
-    /** Add a less than equal filter to this query. && with existing clauses */
-    public Query addLessThanEqualFilter( String propName, Object value ) {
-        LessThanEqual equality = new LessThanEqual( null );
-
-        addClause( equality, propName, value );
-
-        return this;
-    }
-
-
-    /** Add a equal filter to this query. && with existing clauses */
-    public Query addEqualityFilter( String propName, Object value ) {
-        Equal equality = new Equal( new ClassicToken( 0, "=" ) );
-
-        addClause( equality, propName, value );
-
-        return this;
-    }
-
-
-    /** Add a greater than equal filter to this query. && with existing clauses */
-    public Query addGreaterThanEqualFilter( String propName, Object value ) {
-        GreaterThanEqual equality = new GreaterThanEqual( null );
-
-        addClause( equality, propName, value );
-
-        return this;
-    }
-
-
-    /** Add a less than filter to this query. && with existing clauses */
-    public Query addGreaterThanFilter( String propName, Object value ) {
-        GreaterThan equality = new GreaterThan( null );
-
-        addClause( equality, propName, value );
-
-        return this;
-    }
-
-
-    public Query addContainsFilter( String propName, String keyword ) {
-        ContainsOperand equality = new ContainsOperand( new ClassicToken( 0, "contains" ) );
-
-        equality.setProperty( propName );
-        equality.setLiteral( keyword );
-
-        addClause( equality );
-
-        return this;
-    }
-
-
-    private void addClause( EqualityOperand equals, String propertyName, Object value ) {
-        equals.setProperty( propertyName );
-        equals.setLiteral( value );
-        addClause( equals );
-    }
-
-
-    private void addClause( Operand equals ) {
-
-        if ( rootOperand == null ) {
-            rootOperand = equals;
-            return;
-        }
-
-        AndOperand and = new AndOperand();
-        and.addChild( rootOperand );
-        and.addChild( equals );
-
-        // redirect the root to new && clause
-        rootOperand = and;
-    }
-
-
-    @JsonIgnore
-    public Operand getRootOperand() {
-        if ( rootOperand == null ) { // attempt deserialization
-            if ( ql != null ) {
-                try {
-                    Query q = Query.fromQL( ql );
-                    rootOperand = q.rootOperand;
-                }
-                catch ( QueryParseException e ) {
-                    logger.error( "error parsing sql for rootOperand", e ); // shouldn't happen
-                }
-            }
-        }
-        return rootOperand;
-    }
-
-
-    public void setRootOperand( Operand root ) {
-        this.rootOperand = root;
-    }
-
-
-    void setStartResult( UUID startResult ) {
-        this.startResult = startResult;
-    }
-
-
-    public Query withStartResult( UUID startResult ) {
-        this.startResult = startResult;
-        return this;
-    }
-
-
-    public UUID getStartResult() {
-        if ( ( startResult == null ) && ( cursor != null ) ) {
-            byte[] cursorBytes = decodeBase64( cursor );
-            if ( ( cursorBytes != null ) && ( cursorBytes.length == 16 ) ) {
-                startResult = null; 
-            }
-        }
-        return startResult;
-    }
-
-
-    public String getCursor() {
-        return cursor;
-    }
-
-
-    public void setCursor( String cursor ) {
-        this.cursor = cursor;
-    }
-
-
-    public Query withCursor( String cursor ) {
-        setCursor( cursor );
-        return this;
-    }
-
-
-    public int getLimit() {
-        return getLimit( DEFAULT_LIMIT );
-    }
-
-
-    public int getLimit( int defaultLimit ) {
-        if ( limit <= 0 ) {
-            if ( defaultLimit > 0 ) {
-                return defaultLimit;
-            }
-            else {
-                return DEFAULT_LIMIT;
-            }
-        }
-        return limit;
-    }
-
-
-    public void setLimit( int limit ) {
-
-        //      tnine.  After users have had time to change their query limits,
-        // this needs to be uncommented and enforced.
-        //        if(limit > MAX_LIMIT){
-        //          throw new IllegalArgumentException(String.format("Query limit must be <= to %d", MAX_LIMIT));
-        //        }
-
-        if ( limit > MAX_LIMIT ) {
-            limit = MAX_LIMIT;
-        }
-
-        this.limit = limit;
-    }
-
-
-    public Query withLimit( int limit ) {
-        setLimit( limit );
-        return this;
-    }
-
-
-    public boolean isReversed() {
-        return reversed;
-    }
-
-
-    public void setReversed( boolean reversed ) {
-        reversedSet = true;
-        this.reversed = reversed;
-    }
-
-
-    public boolean isReversedSet() {
-        return reversedSet;
-    }
-
-
-    public Long getStartTime() {
-        return startTime;
-    }
-
-
-    public void setStartTime( Long startTime ) {
-        this.startTime = startTime;
-    }
-
-
-    public Long getFinishTime() {
-        return finishTime;
-    }
-
-
-    public void setFinishTime( Long finishTime ) {
-        this.finishTime = finishTime;
-    }
-
-
-    public boolean isPad() {
-        return pad;
-    }
-
-
-    public void setPad( boolean pad ) {
-        this.pad = pad;
-    }
-
-
-    public void addIdentifier( Id id ) {
-        if ( identifiers == null ) {
-            identifiers = new ArrayList<Id>();
-        }
-        identifiers.add( id );
-    }
-
-
-    void setIdentifiers( List<Id> identifiers ) {
-        this.identifiers = identifiers;
-    }
-
-
-    @Override
-    public String toString() {
-        if ( ql != null ) {
-            return ql;
-        }
-        StringBuilder s = new StringBuilder( "select " );
-        if ( selectAssignments.isEmpty() ) {
-            s.append( "*" );
-        }
-        else {
-            if ( mergeSelectResults ) {
-                s.append( "{ " );
-                boolean first = true;
-                for ( Map.Entry<String, String> select : selectAssignments.entrySet() ) {
-                    if ( !first ) {
-                        s.append( ", " );
-                    }
-                    s.append( select.getValue() ).append( " : " ).append( select.getKey() );
-                    first = false;
-                }
-                s.append( " }" );
-            }
-            else {
-                boolean first = true;
-                for ( String select : selectAssignments.keySet() ) {
-                    if ( !first ) {
-                        s.append( ", " );
-                    }
-                    s.append( select );
-                    first = false;
-                }
-            }
-        }
-        s.append( " from " );
-        s.append( type );
-        if ( !sortPredicates.isEmpty() ) {
-            boolean first = true;
-            s.append( " order by " );
-            for ( SortPredicate sp : sortPredicates ) {
-                if ( !first ) {
-                    s.append( ", " );
-                }
-                s.append( sp );
-                first = false;
-            }
-        }
-        return s.toString();
-    }
-
-
-    public static enum SortDirection {
-        ASCENDING, DESCENDING;
-
-
-        public static SortDirection find( String s ) {
-            if ( s == null ) {
-                return ASCENDING;
-            }
-            s = s.toLowerCase();
-            if ( s.startsWith( "asc" ) ) {
-                return ASCENDING;
-            }
-            if ( s.startsWith( "des" ) ) {
-                return DESCENDING;
-            }
-            if ( s.equals( "+" ) ) {
-                return ASCENDING;
-            }
-            if ( s.equals( "-" ) ) {
-                return DESCENDING;
-            }
-            return ASCENDING;
-        }
-    }
-
-
-    public static final class SortPredicate implements Serializable {
-        private static final long serialVersionUID = 1L;
-        private final String propertyName;
-        private final Query.SortDirection direction;
-
-
-        public SortPredicate( String propertyName, Query.SortDirection direction ) {
-            if ( propertyName == null ) {
-                throw new NullPointerException( "Property name was null" );
-            }
-
-            if ( direction == null ) {
-                direction = SortDirection.ASCENDING;
-            }
-
-            this.propertyName = propertyName.trim();
-            this.direction = direction;
-        }
-
-
-        public SortPredicate( String propertyName, String direction ) {
-            this( propertyName, SortDirection.find( direction ) );
-        }
-
-
-        public String getPropertyName() {
-            return propertyName;
-        }
-
-
-        public Query.SortDirection getDirection() {
-            return direction;
-        }
-
-
-        @Override
-        public boolean equals( Object o ) {
-            if ( this == o ) {
-                return true;
-            }
-            if ( ( o == null ) || ( super.getClass() != o.getClass() ) ) {
-                return false;
-            }
-
-            SortPredicate that = ( SortPredicate ) o;
-
-            if ( direction != that.direction ) {
-                return false;
-            }
-
-            return ( propertyName.equals( that.propertyName ) );
-        }
-
-
-        @Override
-        public int hashCode() {
-            int result = propertyName.hashCode();
-            result = ( 31 * result ) + direction.hashCode();
-            return result;
-        }
-
-
-        @Override
-        public String toString() {
-            return propertyName + ( ( direction == Query.SortDirection.DESCENDING ) ? " DESC" : "" );
-        }
-    }
-
-
-    private static String decode( String input ) {
-        try {
-            return URLDecoder.decode( input, "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException e ) {
-            // shouldn't happen, but just in case
-            throw new RuntimeException( e );
-        }
-    }
-
-
-    // note: very likely to be null
-    public String getCollection() {
-        return collection;
-    }
-
-
-    public void setCollection( String collection ) {
-        this.collection = collection;
-    }
-
-
-    // may be null
-    public String getQl() {
-        return ql;
-    }
-
-
-    public void setQl( String ql ) {
-        this.ql = ql;
-    }
-
-
-    public List<Id> getIdentifiers() {
-        return identifiers;
-    }
-
-
-    public String getConnection() {
-        return connection;
-    }
-
-
-    public String getType() {
-        return type;
-    }
-
-    
-    public static final String PARAM_QL = "ql";
-    public static final String PARAM_Q = "q";
-    public static final String PARAM_QUERY = "query";
-
-    public static String queryStrFrom( Map<String, List<String>> params ) {
-        if ( params.containsKey( PARAM_QL ) ) {
-            return ListUtils.first( params.get( PARAM_QL ) );
-        }
-        else if ( params.containsKey( PARAM_Q ) ) {
-            return ListUtils.first( params.get( PARAM_Q ) );
-        }
-        else if ( params.containsKey( PARAM_QUERY ) ) {
-            return ListUtils.first( params.get( PARAM_QUERY ) );
-        }
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
deleted file mode 100644
index 2dd3101..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.exceptions.IndexException;
-
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-@XmlRootElement
-public class Results implements Iterable<Entity> {
-
-    final List<Id> ids;
-    final Query query;
-    final EntityCollectionManager ecm;
-
-    String cursor = null;
-    List<Entity> entities = null;
-    List<EntityRef> refs = null;
-
-    public Results( EntityCollectionManager ecm, Query query, List<Id> ids ) {
-        this.ecm = ecm;
-        this.query = query;
-        this.ids = ids;
-    }
-
-
-    public boolean hasCursor() {
-        return cursor != null;
-    }
-
-
-    public String getCursor() {
-        return cursor;
-    }
-
-
-    public void setCursor(String cursor) {
-        this.cursor = cursor;
-    }
-
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Query getQuery() {
-        return query;
-    }
-
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public List<Id> getIds() {
-        return Collections.unmodifiableList( ids );
-    }
-
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    @SuppressWarnings("unchecked")
-    public List<EntityRef> getRefs() {
-        if ( entities == null ) {
-            getEntities();
-        }
-        return Collections.unmodifiableList( refs );
-    }
-
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public List<Entity> getEntities() {
-        if ( entities == null ) {
-            entities = new ArrayList<Entity>();
-            refs = new ArrayList<EntityRef>();
-            for ( Id id : ids ) {
-                Entity entity = ecm.load( id ).toBlockingObservable().last();
-                if (entity == null) {
-                    throw new IndexException("Entity id [" + id + "] not found");
-                }
-                entities.add( entity );
-                refs.add( new SimpleEntityRef( entity.getId(), entity.getVersion() ));
-            }
-        }
-        return Collections.unmodifiableList( entities );
-    }
-
-
-    public int size() {
-        return ids.size();
-    }
-
-
-    public boolean isEmpty() {
-        return ids.isEmpty();
-    }
-
-
-    @Override
-    public Iterator<Entity> iterator() {
-        return getEntities().iterator();
-    }
-
-    public void setIds(List<Id> ids) {
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/SimpleEntityRef.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/SimpleEntityRef.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/SimpleEntityRef.java
deleted file mode 100644
index e4cfcf7..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/SimpleEntityRef.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query;
-
-
-import java.util.UUID;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-public class SimpleEntityRef implements EntityRef {
-
-    private final Id id;
-
-    private final UUID version;
-
-
-    public SimpleEntityRef( Id id, UUID version ) {
-        this.id = id;
-        this.version = version;
-    }
-
-
-    public SimpleEntityRef( EntityRef entityRef ) {
-        this.id = entityRef.getId();
-        this.version = entityRef.getVersion(); 
-    }
-
-
-    public static EntityRef ref() {
-        return new SimpleEntityRef( null, null );
-    }
-
-    public static EntityRef ref( Id id ) {
-        return new SimpleEntityRef( id, null );
-    }
-
-    public static EntityRef ref( Id id, UUID version ) {
-        return new SimpleEntityRef(  id, version );
-    }
-
-
-    public static EntityRef ref( EntityRef ref ) {
-        return new SimpleEntityRef( ref );
-    }
-
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
-        result = prime * result + ( ( version == null ) ? 0 : version.hashCode() );
-        return result;
-    }
-
-
-    @Override
-    public boolean equals( Object obj ) {
-        if ( this == obj ) {
-            return true;
-        }
-        if ( obj == null ) {
-            return false;
-        }
-        if ( getClass() != obj.getClass() ) {
-            return false;
-        }
-        SimpleEntityRef other = ( SimpleEntityRef ) obj;
-        if ( id == null ) {
-            if ( other.id != null ) {
-                return false;
-            }
-        }
-        else if ( !id.equals( other.id ) ) {
-            return false;
-        }
-        if ( version == null ) {
-            if ( other.version != null ) {
-                return false;
-            }
-        }
-        else if ( !version.equals( other.version ) ) {
-            return false;
-        }
-        return true;
-    }
-
-
-    @Override
-    public String toString() {
-        return id.toString() + "|" + version.toString();
-    }
-
-    public static Id getId( EntityRef ref ) {
-        if ( ref == null ) {
-            return null;
-        }
-        return ref.getId();
-    }
-
-
-    public static String getType( EntityRef ref ) {
-        if ( ref == null ) {
-            return null;
-        }
-        return ref.getId().getType();
-    }
-
-    public Id getId() {
-        return id;
-    }
-
-    public UUID getVersion() {
-        return version;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/AndOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/AndOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/AndOperand.java
deleted file mode 100644
index 3377073..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/AndOperand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class AndOperand extends BooleanOperand {
-
-    public AndOperand() {
-        super( new CommonToken( 0, "and" ) );
-    }
-
-
-    public AndOperand( Token t ) {
-        super( t );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws PersistenceException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanLiteral.java
deleted file mode 100644
index b2d4a36..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanLiteral.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class BooleanLiteral extends Literal<Boolean> {
-
-    private boolean value;
-
-
-    /**
-     * @param t
-     */
-    protected BooleanLiteral( Token t ) {
-        super( t );
-        value = Boolean.valueOf( t.getText() );
-    }
-
-
-    /** The boolean literal */
-    public BooleanLiteral( boolean value ) {
-        super( new ClassicToken( 0, String.valueOf( value ) ) );
-        this.value = value;
-    }
-
-
-    public Boolean getValue() {
-        return value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanOperand.java
deleted file mode 100644
index 84e6951..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/BooleanOperand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-
-
-/**
- * A base class for any equality expression.  Expressions must have a property and a value. Examples are >=, >, =, <,
- * <=,
- *
- * @author tnine
- */
-public abstract class BooleanOperand extends Operand {
-
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public BooleanOperand( Token t ) {
-        super( t );
-    }
-
-
-    public Operand getLeft() {
-        return ( Operand ) this.children.get( 0 );
-    }
-
-
-    public Operand getRight() {
-        return ( Operand ) this.children.get( 1 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsOperand.java
deleted file mode 100644
index f63745b..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsOperand.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class ContainsOperand extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public ContainsOperand( Token t ) {
-        super( t );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws PersistenceException {
-        visitor.visit( this );
-    }
-
-
-    public StringLiteral getString() {
-        return ( StringLiteral ) getLiteral();
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#newProperty(java.lang.String)
-     */
-    @Override
-    protected Property newProperty( String name ) {
-        return new ContainsProperty( name );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#getProperty()
-     */
-    @Override
-    public ContainsProperty getProperty() {
-        return ( ContainsProperty ) this.children.get( 0 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsProperty.java
deleted file mode 100644
index c588c77..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/ContainsProperty.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/**
- * A property for full text searching that requires special renaming
- *
- * @author tnine
- */
-public class ContainsProperty extends Property {
-
-    private String indexedName = null;
-
-
-    public ContainsProperty( Token t ) {
-        super( t );
-        this.indexedName = String.format( "%s.keywords", super.getValue() );
-    }
-
-
-    public ContainsProperty( String property ) {
-        this( new ClassicToken( 0, property ) );
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.usergrid.persistence.query.tree.Property#getIndexedValue()
-     */
-    @Override
-    public String getIndexedValue() {
-        return this.indexedName;
-    }
-
-
-    /** @return the property */
-    public ContainsProperty getProperty() {
-        return ( ContainsProperty ) this.children.get( 0 );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Equal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Equal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Equal.java
deleted file mode 100644
index eedfbf0..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Equal.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class Equal extends EqualityOperand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public Equal( Token t ) {
-        super( t );
-    }
-
-
-    public Equal() {
-        super( new ClassicToken( 0, "=" ) );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
-     * .query.tree.QueryVisitor)
-     */
-    @Override
-    public void visit( QueryVisitor visitor ) throws NoIndexException {
-        visitor.visit( this );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/EqualityOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/EqualityOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/EqualityOperand.java
deleted file mode 100644
index 121b1e9..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/EqualityOperand.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-
-
-/**
- * A base class for any equality expression. Expressions must have a property and a value. Examples are >=, >, =, <,
- * <=,
- *
- * @author tnine
- */
-public abstract class EqualityOperand extends Operand {
-
-    /**
-     * @param property
-     * @param literal
-     */
-    public EqualityOperand( Token t ) {
-        super( t );
-    }
-
-
-    public EqualityOperand( String propName, Literal<?> value ) {
-        super( null );
-    }
-
-
-    /** Set the property on this operand */
-    public void setProperty( String name ) {
-        setAtIndex( 0, newProperty( name ) );
-    }
-
-
-    /** Get the property to set into the equality. Allows subclasses to override the type */
-    protected Property newProperty( String name ) {
-        return new Property( name );
-    }
-
-
-    /** Set the literal on this operand from the given value */
-    public void setLiteral( Object value ) {
-        setAtIndex( 1, LiteralFactory.getLiteral( value ) );
-    }
-
-
-    /** Set the child at the specified index. If it doesn't exist, it's added until it does */
-    @SuppressWarnings("unchecked")
-    private void setAtIndex( int index, Literal<?> value ) {
-
-        if ( children == null ) {
-            children = createChildrenList();
-        }
-
-        while ( children.size() - 1 < index ) {
-            children.add( null );
-        }
-
-        setChild( index, value );
-    }
-
-
-    /** @return the property */
-    public Property getProperty() {
-        return ( Property ) this.children.get( 0 );
-    }
-
-
-    /** @return the literal */
-    public Literal<?> getLiteral() {
-        return ( Literal<?> ) this.children.get( 1 );
-    }
-}


[23/27] git commit: Updated tests. Need to figure a work around for Mockito

Posted by sn...@apache.org.
Updated tests.  Need to figure a work around for Mockito


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

Branch: refs/heads/entity-manager
Commit: 5ded6b52943bf9c8bd6c72090a04337196e9ce0e
Parents: 16721c8
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Mar 26 13:43:37 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Mar 26 13:43:37 2014 -0700

----------------------------------------------------------------------
 .../graph/consistency/AsyncProcessorImpl.java   |   46 +-
 .../graph/impl/GraphManagerImpl.java            |   49 +-
 .../graph/impl/SimpleSearchByEdgeType.java      |   38 +
 .../graph/impl/stage/AbstractEdgeRepair.java    |    2 +
 .../persistence/graph/EdgeManagerIT.java        | 1498 ------------------
 .../graph/EdgeManagerStressTest.java            |  317 ----
 .../persistence/graph/GraphManagerIT.java       | 1497 +++++++++++++++++
 .../graph/GraphManagerStressTest.java           |  317 ++++
 .../graph/GraphManagerTimeoutIT.java            | 1336 +---------------
 .../graph/impl/NodeDeleteListenerTest.java      |    4 +-
 10 files changed, 1908 insertions(+), 3196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
index 20411e7..000eaeb 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/consistency/AsyncProcessorImpl.java
@@ -10,14 +10,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.graph.GraphFig;
+import org.apache.usergrid.persistence.graph.hystrix.HystrixGraphObservable;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
 import rx.Observable;
-import rx.Scheduler;
-import rx.functions.Action0;
-import rx.functions.Action1;
+import rx.Subscriber;
 import rx.functions.FuncN;
 import rx.schedulers.Schedulers;
 
@@ -45,13 +44,14 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
 
 
     @Inject
-    public AsyncProcessorImpl( final TimeoutQueue<T> queue,  final GraphFig graphFig ) {
+    public AsyncProcessorImpl( final TimeoutQueue<T> queue, final GraphFig graphFig ) {
         this.queue = queue;
         this.graphFig = graphFig;
 
         //we purposefully use a new thread.  We don't want to use one of the I/O threads to run this task
         //in the event the scheduler is full, we'll end up rejecting the reschedule of this task
-        Schedulers.newThread().schedulePeriodically( new TimeoutTask<T>(this, graphFig), graphFig.getTaskLoopTime(),  graphFig.getTaskLoopTime(), TimeUnit.MILLISECONDS );
+        Schedulers.newThread().schedulePeriodically( new TimeoutTask<T>( this, graphFig ), graphFig.getTaskLoopTime(),
+                graphFig.getTaskLoopTime(), TimeUnit.MILLISECONDS );
     }
 
 
@@ -70,37 +70,43 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
         List<Observable<?>> observables = new ArrayList<Observable<?>>( listeners.size() );
 
         for ( MessageListener<T, T> listener : listeners ) {
-            observables.add( listener.receive( data ).subscribeOn( Schedulers.io() ) );
+            observables.add( HystrixGraphObservable.async( listener.receive( data ) ) );
         }
 
+        LOG.debug( "About to start {} observables for event {}", listeners.size(), event );
+
         //run everything in parallel and zip it up
         Observable.zip( observables, new FuncN<AsynchronousMessage<T>>() {
             @Override
             public AsynchronousMessage<T> call( final Object... args ) {
                 return event;
             }
-        } ).doOnError( new Action1<Throwable>() {
-            @Override
-            public void call( final Throwable throwable ) {
-                LOG.error( "Unable to process async event", throwable );
+        } ).subscribe( new Subscriber<AsynchronousMessage<T>>() {
 
-                for ( ErrorListener listener : errorListeners ) {
-                    listener.onError( event, throwable );
-                }
-            }
-        } ).doOnCompleted( new Action0() {
             @Override
-            public void call() {
+            public void onCompleted() {
+                LOG.debug( "Successfully completed processing for event {}", event );
                 queue.remove( event );
 
                 for ( CompleteListener<T> listener : completeListeners ) {
                     listener.onComplete( event );
                 }
             }
-        } ).subscribe( new Action1<AsynchronousMessage<T>>() {
+
+
+            @Override
+            public void onError( final Throwable throwable ) {
+                LOG.error( "Unable to process async event", throwable );
+
+                for ( ErrorListener listener : errorListeners ) {
+                    listener.onError( event, throwable );
+                }
+            }
+
+
             @Override
-            public void call( final AsynchronousMessage<T> asynchronousMessage ) {
-             //no op
+            public void onNext( final AsynchronousMessage<T> tAsynchronousMessage ) {
+                //no op
             }
         } );
     }
@@ -130,6 +136,4 @@ public class AsyncProcessorImpl<T> implements AsyncProcessor<T> {
     public void addCompleteListener( final CompleteListener<T> listener ) {
         this.completeListeners.add( listener );
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
index ff63a60..ad7f67b 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
@@ -40,6 +40,7 @@ import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.AsynchronousMessage;
 import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
 import org.apache.usergrid.persistence.graph.guice.NodeDelete;
+import org.apache.usergrid.persistence.graph.hystrix.HystrixGraphObservable;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
 import org.apache.usergrid.persistence.graph.serialization.NodeSerialization;
@@ -108,7 +109,7 @@ public class GraphManagerImpl implements GraphManager {
     public Observable<Edge> writeEdge( final Edge edge ) {
         EdgeUtils.validateEdge( edge );
 
-        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
+        return HystrixGraphObservable.user(Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
             @Override
             public Edge call( final Edge edge ) {
                 final MutationBatch mutation = edgeMetadataSerialization.writeEdge( scope, edge );
@@ -126,7 +127,7 @@ public class GraphManagerImpl implements GraphManager {
 
                 return edge;
             }
-        } );
+        } ));
     }
 
 
@@ -134,7 +135,7 @@ public class GraphManagerImpl implements GraphManager {
     public Observable<Edge> deleteEdge( final Edge edge ) {
         EdgeUtils.validateEdge( edge );
 
-        return Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
+        return HystrixGraphObservable.user(Observable.from( edge ).subscribeOn(  Schedulers.io() ).map( new Func1<Edge, Edge>() {
             @Override
             public Edge call( final Edge edge ) {
                 final MutationBatch edgeMutation = edgeSerialization.markEdge( scope, edge );
@@ -154,13 +155,13 @@ public class GraphManagerImpl implements GraphManager {
 
                 return edge;
             }
-        } );
+        } ));
     }
 
 
     @Override
     public Observable<Id> deleteNode( final Id node ) {
-        return Observable.from( node ).subscribeOn(  Schedulers.io() ).map( new Func1<Id, Id>() {
+        return HystrixGraphObservable.user(Observable.from( node ).subscribeOn(  Schedulers.io() ).map( new Func1<Id, Id>() {
             @Override
             public Id call( final Id id ) {
 
@@ -183,114 +184,114 @@ public class GraphManagerImpl implements GraphManager {
 
                 return id;
             }
-        } );
+        } ));
     }
 
 
     @Override
     public Observable<Edge> loadEdgeVersions( final SearchByEdge searchByEdge ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgeVersions" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<MarkedEdge>( "getEdgeVersions" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgeVersions( scope, searchByEdge );
             }
         } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( searchByEdge.getMaxVersion() ) )
-                         .cast( Edge.class );
+                         .cast( Edge.class ));
     }
 
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSource" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSource" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
             }
         } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                         .cast( Edge.class );
+                         .cast( Edge.class ));
     }
 
 
     @Override
     public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTarget" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTarget" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
             }
         } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                         .cast( Edge.class );
+                         .cast( Edge.class ));
     }
 
 
     @Override
     public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSourceByTargetType" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSourceByTargetType" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
             }
         } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
 
-                         .cast( Edge.class );
+                         .cast( Edge.class ));
     }
 
 
     @Override
     public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTargetBySourceType" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTargetBySourceType" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
             }
         } ).buffer( graphFig.getScanPageSize() ).flatMap( new EdgeBufferFilter( search.getMaxVersion() ) )
-                         .cast( Edge.class );
+                         .cast( Edge.class ));
     }
 
 
     @Override
     public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( "getEdgeTypesFromSource" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<String>( "getEdgeTypesFromSource" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
             }
-        } );
+        } ));
     }
 
 
     @Override
     public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( "getIdTypesFromSource" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<String>( "getIdTypesFromSource" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
             }
-        } );
+        } ));
     }
 
 
     @Override
     public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>( "getEdgeTypesToTarget" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<String>( "getEdgeTypesToTarget" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
             }
-        } );
+        } ));
     }
 
 
     @Override
     public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>( "getIdTypesToTarget" ) {
+        return  HystrixGraphObservable.user(Observable.create( new ObservableIterator<String>( "getIdTypesToTarget" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesToTarget( scope, search );
             }
-        } );
+        } ));
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdgeType.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdgeType.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdgeType.java
index d56c538..a7a79e3 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdgeType.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdgeType.java
@@ -84,4 +84,42 @@ public class SimpleSearchByEdgeType implements SearchByEdgeType{
     public Optional<Edge> last() {
         return last;
     }
+
+
+    @Override
+    public boolean equals( final Object o ) {
+        if ( this == o ) {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() ) {
+            return false;
+        }
+
+        final SimpleSearchByEdgeType that = ( SimpleSearchByEdgeType ) o;
+
+        if ( !last.equals( that.last ) ) {
+            return false;
+        }
+        if ( !maxVersion.equals( that.maxVersion ) ) {
+            return false;
+        }
+        if ( !node.equals( that.node ) ) {
+            return false;
+        }
+        if ( !type.equals( that.type ) ) {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    @Override
+    public int hashCode() {
+        int result = node.hashCode();
+        result = 31 * result + type.hashCode();
+        result = 31 * result + maxVersion.hashCode();
+        result = 31 * result + last.hashCode();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index 898a04d..7fc571a 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -49,6 +49,8 @@ import rx.schedulers.Schedulers;
 /**
  * SimpleRepair operation
  *
+ * TODO T.N. this is still valid code, just not used ATM.  DO NOT REMOVE IT.  Needs to refactor it to read all
+ * versions of an edge and remove them.
  */
 @Singleton
 public abstract class AbstractEdgeRepair  {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
deleted file mode 100644
index 379f56a..0000000
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerIT.java
+++ /dev/null
@@ -1,1498 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.usergrid.persistence.graph;
-
-
-import java.util.Iterator;
-import java.util.UUID;
-
-import org.jukito.All;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.google.inject.Inject;
-
-import rx.Observable;
-
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdgeAndId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules({ TestGraphModule.class })
-//@UseModules( { TestGraphModule.class, EdgeManagerIT.InvalidInput.class } )
-public class EdgeManagerIT {
-
-
-    @ClassRule
-    public static CassandraRule rule = new CassandraRule();
-
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-
-
-    @Inject
-    protected GraphManagerFactory emf;
-
-    protected OrganizationScope scope;
-
-
-    @Before
-    public void setup() {
-        scope = mock( OrganizationScope.class );
-
-        Id orgId = mock( Id.class );
-
-        when( orgId.getType() ).thenReturn( "organization" );
-        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
-
-        when( scope.getOrganization() ).thenReturn( orgId );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().last();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getSourceNode(), edge.getType() + "invalid", edge.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Earlier version should not be returned", returned );
-    }
-
-
-    /**
-     * Tests that if multiple versions of an edge exist, only the distinct edges with a version <= max are returned
-     */
-    @Test
-    public void testWriteReadEdgeTypeVersionSourceDistinct() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesFromSource( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeVersionTargetDistinct() {
-
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final UUID earlyVersion = UUIDGenerator.newTimeUUID();
-
-
-        Edge edge1 = createEdge( "source", "test", "target" );
-
-        final Id sourceId = edge1.getSourceNode();
-        final Id targetId = edge1.getTargetNode();
-
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, edge1.getType(), targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it, we should only get edge3, since it's the latest
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //now test with an earlier version, we shouldn't get the edge back
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge2.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge1.getVersion(), null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-        assertFalse( "No more edges", returned.hasNext() );
-
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), earlyVersion, null );
-
-        edges = em.loadEdgesToTarget( search );
-
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-        final Id sourceId = createId( "source" );
-
-
-        Edge edge1 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( sourceId, "test", createId( "target" ) );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        //still edge 3 is our max version, but we start with edge 2 as our last read
-        search = createSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge1, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypePagingTarget() {
-
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        final Id targetId = createId( "target" );
-
-        Edge edge1 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-        Edge edge3 = createEdge( createId( "source" ), "test", targetId );
-
-        em.writeEdge( edge3 ).toBlockingObservable().last();
-
-
-        //now test retrieving it
-
-        SearchByEdgeType search =
-                createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Iterator<Edge> returned = edges.toBlockingObservable().getIterator();
-
-
-        //we have 3 edges, but we specified our first edge as the max, we shouldn't get any more results than the first
-        assertEquals( "Correct edge returned", edge3, returned.next() );
-
-        assertEquals( "Correct edge returned", edge2, returned.next() );
-
-        assertEquals( "Correct edge returned", edge1, returned.next() );
-
-
-        assertFalse( "No more edges", returned.hasNext() );
-
-        search = createSearchByEdge( edge1.getTargetNode(), edge1.getType(), edge3.getVersion(), edge2 );
-
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Paged correctly", edge1, returned.next() );
-
-        assertFalse( "End of stream", returned.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesFromSourceByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypeTargetTypeTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-        SearchByIdType search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //change edge type to be invalid, shouldn't get a result
-        search = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType() + "invalid", null );
-
-        edges = em.loadEdgesToTargetByType( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "Invalid type should not be returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteSource() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getVersion(),
-                edge.getTargetNode().getType(), null );
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        final SearchByEdge searchByEdge = createGetByEdge(edge.getSourceNode(), edge.getType(), edge.getTargetNode(), edge.getVersion(), null);
-
-        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().single();
-
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        returned = em.deleteEdge( edge ).toBlockingObservable().last();
-
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesFromSource( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesFromSourceByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-        returned = em.loadEdgeVersions(searchByEdge).toBlockingObservable().singleOrDefault(null);
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeDeleteTarget() {
-
-        GraphManager em = emf.createEdgeManager( scope );
-
-
-        Edge edge = createEdge( "source", "test", "target" );
-
-        em.writeEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieving it
-
-
-        SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getVersion(), null );
-
-        Observable<Edge> edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        Edge returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-        SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getVersion(),
-                edge.getSourceNode().getType(), null );
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().single();
-
-        assertEquals( "Correct edge returned", edge, returned );
-
-
-        //now delete it
-        em.deleteEdge( edge ).toBlockingObservable().last();
-
-        //now test retrieval, should be null
-        edges = em.loadEdgesToTarget( search );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-
-
-        //no search by type, should be null as well
-
-        edges = em.loadEdgesToTargetByType( searchById );
-
-        //implicitly blows up if more than 1 is returned from "single"
-        returned = edges.toBlockingObservable().singleOrDefault( null );
-
-        assertNull( "No edge returned", returned );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypes() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge testTargetEdge = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        Observable<String> edges =
-                em.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null ) );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-
-        //now get types for test2
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-
-        assertFalse( "No results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypes() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId1 = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-        Edge testTarget2Edge = createEdge( sourceId2, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTarget2Edge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get types for test2
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test2", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesSourceTypesPaging() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId1, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge test2TargetEdge = createEdge( sourceId1, "test2", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test" );
-
-        edges = em.getEdgeTypesFromSource( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now test sub edges
-
-        edges = em.getIdTypesFromSource( new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId1.getType(), results.next() );
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now get the next page
-
-        edges = em.getIdTypesFromSource(
-                new SimpleSearchIdType( testTargetEdge.getSourceNode(), "test", targetId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", targetId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testWriteReadEdgeTypesTargetTypesPaging() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-
-        Edge testTargetEdge = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        Edge testTargetEdge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( testTargetEdge2 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge test2TargetEdge = createEdge( sourceId2, "test2", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( test2TargetEdge ).toBlockingObservable().singleOrDefault( null );
-
-
-        //get our 2 edge types
-        SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null );
-
-        Observable<String> edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        Iterator<String> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test", results.next() );
-        assertEquals( "Edges correct", "test2", results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now load the next page
-
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), "test" );
-
-        edges = em.getEdgeTypesToTarget( edgeTypes );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", "test2", results.next() );
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now test sub edges
-
-        edges = em.getIdTypesToTarget( new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId1.getType(), results.next() );
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now get the next page
-
-        edges = em.getIdTypesToTarget(
-                new SimpleSearchIdType( testTargetEdge.getTargetNode(), "test", sourceId1.getType() ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Types correct", sourceId2.getType(), results.next() );
-
-        assertFalse( "No more results", results.hasNext() );
-    }
-
-
-    @Test
-    public void testMarkSourceEdges() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesFromSource(
-                createSearchByEdge( edge1.getSourceNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdges() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges =
-                em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-        edges = em.loadEdgesToTarget( createSearchByEdge( edge1.getTargetNode(), edge1.getType(), maxVersion, null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkSourceEdgesType() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void testMarkTargetEdgesType() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().last();
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().last();
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        //get our 2 edges
-        Observable<Edge> edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) );
-
-
-        Iterator<Edge> results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge1 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( edge1.getSourceNode(), edge1.getType(), maxVersion, sourceId1.getType(),
-                        null ) );
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-
-        em.deleteEdge( edge2 ).toBlockingObservable().last();
-
-
-        edges = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId2.getType(), null ) );
-
-
-        results = edges.toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //now delete one of the edges
-
-    }
-
-
-    @Test
-    public void markSourceNode() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId = new SimpleId( "source" );
-        Id targetId1 = new SimpleId( "target" );
-        Id targetId2 = new SimpleId( "target2" );
-
-        Edge edge1 = createEdge( sourceId, "test", targetId1, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId, "test", targetId2, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( sourceId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesFromSource( createSearchByEdge( sourceId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge1.getType(), maxVersion, targetId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesFromSourceByType(
-                createSearchByEdgeAndId( sourceId, edge2.getType(), maxVersion, targetId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test
-    public void markTargetNode() {
-
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        Id sourceId1 = new SimpleId( "source" );
-        Id sourceId2 = new SimpleId( "source2" );
-        Id targetId = new SimpleId( "target" );
-
-        Edge edge1 = createEdge( sourceId1, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge1 ).toBlockingObservable().singleOrDefault( null );
-
-        Edge edge2 = createEdge( sourceId2, "test", targetId, UUIDGenerator.newTimeUUID() );
-
-        em.writeEdge( edge2 ).toBlockingObservable().singleOrDefault( null );
-
-
-        final UUID maxVersion = UUIDGenerator.newTimeUUID();
-
-        Iterator<Edge> results =
-                em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                  .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edge found", edge2, results.next() );
-
-        assertEquals( "Edge found", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge1, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertEquals( "Edges correct", edge2, results.next() );
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //mark the source node
-        em.deleteNode( targetId ).toBlockingObservable().last();
-
-
-        //now re-read, nothing should be there since they're marked
-
-        results = em.loadEdgesToTarget( createSearchByEdge( targetId, edge1.getType(), maxVersion, null ) )
-                    .toBlockingObservable().getIterator();
-
-        assertFalse( "No more edges", results.hasNext() );
-
-
-        //get our 2 edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge1.getType(), maxVersion, sourceId1.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-
-        //now delete one of the edges
-        results = em.loadEdgesToTargetByType(
-                createSearchByEdgeAndId( targetId, edge2.getType(), maxVersion, sourceId2.getType(), null ) )
-                    .toBlockingObservable().getIterator();
-
-
-        assertFalse( "No more edges", results.hasNext() );
-    }
-
-
-    @Test(expected = NullPointerException.class)
-    public void invalidEdgeTypesWrite( @All Edge edge ) {
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        em.writeEdge( edge );
-    }
-
-
-    @Test(expected = NullPointerException.class)
-    public void invalidEdgeTypesDelete( @All Edge edge ) {
-        final GraphManager em = emf.createEdgeManager( scope );
-
-        em.deleteEdge( edge );
-    }
-
-    //
-    //    public static class InvalidInput extends JukitoModule {
-    //
-    //        @Override
-    //        protected void configureTest() {
-    //create all edge types of junk input
-    //
-    //            final UUID version = UUIDGenerator.newTimeUUID();
-    //
-    //            Id nullUuid = mock( Id.class );
-    //            when( nullUuid.getUuid() ).thenReturn( null );
-    //
-    //
-    //            Id nullType = mock( Id.class );
-    //            when( nullType.getType() ).thenReturn( "type" );
-    //
-    //            Edge[] edges = new Edge[] {
-    //                    mockEdge( nullUuid, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( nullType, "test", createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), null, createId( "target" ), version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullUuid, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", nullType, version ),
-    //
-    //                    mockEdge( createId( "source" ), "test", createId( "target" ), null )
-    //            };
-    //
-    //
-    //            bindManyInstances( Edge.class, edges );
-    //
-    //        }
-    //
-    //
-    //        private Edge mockEdge( final Id sourceId, final String type, final Id targetId, final UUID version ) {
-    //            Edge edge = mock( Edge.class );
-    //
-    //            when( edge.getSourceNode() ).thenReturn( sourceId );
-    //            when( edge.getType() ).thenReturn( type );
-    //            when( edge.getTargetNode() ).thenReturn( targetId );
-    //            when( edge.getVersion() ).thenReturn( version );
-    //
-    //            return edge;
-    //        }
-    //    }
-}
-
-
-
-
-

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5ded6b52/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
deleted file mode 100644
index 9d8db6e..0000000
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/EdgeManagerStressTest.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.usergrid.persistence.graph;
-
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.CountDownLatch;
-
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang3.time.StopWatch;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.google.inject.Inject;
-
-import rx.Observable;
-import rx.Subscriber;
-
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules(TestGraphModule.class)
-public class EdgeManagerStressTest {
-    private static final Logger log = LoggerFactory.getLogger( EdgeManagerStressTest.class );
-
-    @Inject
-    private GraphManagerFactory factory;
-
-    @ClassRule
-    public static CassandraRule rule = new CassandraRule();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-
-
-    protected OrganizationScope scope;
-
-
-    @Before
-    public void setup() {
-        scope = mock( OrganizationScope.class );
-
-        Id orgId = mock( Id.class );
-
-        when( orgId.getType() ).thenReturn( "organization" );
-        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
-
-        when( scope.getOrganization() ).thenReturn( orgId );
-    }
-
-
-    @Test
-    @Ignore
-    public void writeThousands() throws InterruptedException {
-        EdgeGenerator generator = new EdgeGenerator() {
-
-            private Set<Id> sourceIds = new HashSet<Id>();
-
-
-            @Override
-            public Edge newEdge() {
-                Edge edge = createEdge( "source", "test", "target" );
-
-                sourceIds.add( edge.getSourceNode() );
-
-                return edge;
-            }
-
-
-            @Override
-            public Observable<Edge> doSearch( final GraphManager manager ) {
-
-
-                final UUID uuid = UUIDGenerator.newTimeUUID();
-
-
-                return Observable.create( new Observable.OnSubscribe<Edge>() {
-
-                    @Override
-                    public void call( final Subscriber<? super Edge> subscriber ) {
-                        try {
-                            for ( Id sourceId : sourceIds ) {
-
-                                final Iterable<Edge> edges = manager.loadEdgesFromSource(
-                                        new SimpleSearchByEdgeType( sourceId, "test", uuid, null ) )
-                                                                    .toBlockingObservable().toIterable();
-
-                                for ( Edge edge : edges ) {
-                                    log.debug( "Firing on next for edge {}", edge );
-
-                                    subscriber.onNext( edge );
-                                }
-                            }
-                        }
-                        catch ( Throwable throwable ) {
-                            subscriber.onError( throwable );
-                        }
-                    }
-                } );
-
-
-                //TODO T.N keep this code it's exhibiting a failure /exception swallowing with RX when our scheduler
-                // is full
-                //
-                //              return  Observable.create( new Observable.OnSubscribe<Edge>() {
-                //
-                //                    @Override
-                //                    public void call( final Subscriber<? super Edge> subscriber ) {
-                //                        for ( Id sourceId : sourceIds ) {
-                //
-                //                                            final Observable<Edge> edges =
-                //                                                    manager.loadEdgesFromSource( new
-                // SimpleSearchByEdgeType( sourceId, "test", uuid, null ) );
-                //
-                //                            edges.subscribe( new Action1<Edge>() {
-                //                                @Override
-                //                                public void call( final Edge edge ) {
-                //                                    subscriber.onNext( edge );
-                //                                }
-                //                            },
-                //
-                //                            new Action1<Throwable>() {
-                //                                @Override
-                //                                public void call( final Throwable throwable ) {
-                //                                    subscriber.onError( throwable );
-                //                                }
-                //                            });
-                //                         }
-                //                    }
-                //                } ) ;
-
-
-            }
-        };
-
-        doTest( generator );
-    }
-
-
-    @Ignore
-    @Test
-    public void writeThousandsSingleSource() throws InterruptedException {
-        EdgeGenerator generator = new EdgeGenerator() {
-
-            private Id sourceId = createId( "source" );
-
-
-            @Override
-            public Edge newEdge() {
-                Edge edge = createEdge( sourceId, "test", createId( "target" ) );
-
-
-                return edge;
-            }
-
-
-            @Override
-            public Observable<Edge> doSearch( final GraphManager manager ) {
-                UUID uuid = UUIDGenerator.newTimeUUID();
-
-                return manager.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceId, "test", uuid, null ) );
-            }
-        };
-
-        doTest( generator );
-    }
-
-
-    @Test
-    @Ignore
-    public void writeThousandsSingleTarget() throws InterruptedException {
-        EdgeGenerator generator = new EdgeGenerator() {
-
-            private Id targetId = createId( "target" );
-
-
-            @Override
-            public Edge newEdge() {
-                Edge edge = createEdge( createId( "source" ), "test", targetId );
-
-
-                return edge;
-            }
-
-
-            @Override
-            public Observable<Edge> doSearch( final GraphManager manager ) {
-                UUID uuid = UUIDGenerator.newTimeUUID();
-
-                return manager.loadEdgesToTarget( new SimpleSearchByEdgeType( targetId, "test", uuid, null ) );
-            }
-        };
-
-        doTest( generator );
-    }
-
-
-    /**
-     * Execute the test with the generator
-     */
-    private void doTest( EdgeGenerator generator ) throws InterruptedException {
-        GraphManager manager = factory.createEdgeManager( scope );
-
-        int limit = 10000;
-
-        final StopWatch timer = new StopWatch();
-        timer.start();
-        final Set<Edge> ids = new HashSet<Edge>( limit );
-
-        for ( int i = 0; i < limit; i++ ) {
-
-            Edge edge = generator.newEdge();
-
-            Edge returned = manager.writeEdge( edge ).toBlockingObservable().last();
-
-
-            assertNotNull( "Returned has a version", returned.getVersion() );
-
-            ids.add( returned );
-
-            if ( i % 1000 == 0 ) {
-                log.info( "   Wrote: " + i );
-            }
-        }
-
-        timer.stop();
-        log.info( "Total time to write {} entries {}ms", limit, timer.getTime() );
-        timer.reset();
-
-        timer.start();
-
-        final CountDownLatch latch = new CountDownLatch( 1 );
-
-
-        generator.doSearch( manager ).subscribe( new Subscriber<Edge>() {
-            @Override
-            public void onCompleted() {
-                timer.stop();
-                latch.countDown();
-            }
-
-
-            @Override
-            public void onError( final Throwable throwable ) {
-                fail( "Exception occurced " + throwable );
-            }
-
-
-            @Override
-            public void onNext( final Edge edge ) {
-                ids.remove( edge );
-            }
-        } );
-
-
-        latch.await();
-
-
-        assertEquals( 0, ids.size() );
-
-
-        log.info( "Total time to read {} entries {}ms", limit, timer.getTime() );
-    }
-
-
-    private interface EdgeGenerator {
-
-        /**
-         * Create a new edge to persiste
-         */
-        public Edge newEdge();
-
-        public Observable<Edge> doSearch( final GraphManager manager );
-    }
-}


[06/27] git commit: Merge branch 'two-dot-o' into hystrix-integration

Posted by sn...@apache.org.
Merge branch 'two-dot-o' into hystrix-integration


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

Branch: refs/heads/entity-manager
Commit: b1d12a17176dbcaa518cc41430322bad11550557
Parents: 58f7f43 fc10597
Author: Todd Nine <tn...@apigee.com>
Authored: Mon Mar 24 08:16:49 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Mon Mar 24 08:16:49 2014 -0700

----------------------------------------------------------------------
 stack/awscluster/README.md                      |  2 +-
 .../src/main/groovy/wait_for_instances.groovy   |  2 +-
 stack/corepersistence/perftest1/pom.xml         |  9 ++---
 .../persistence/Usergrid1PerformanceTest.java   | 36 +++++++++++---------
 4 files changed, 24 insertions(+), 25 deletions(-)
----------------------------------------------------------------------



[24/27] git commit: Merge branch 'asyncqueue' into two-dot-o

Posted by sn...@apache.org.
Merge branch 'asyncqueue' into two-dot-o


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

Branch: refs/heads/entity-manager
Commit: 17c2ac42f1ad0b1523a42d0105a67cbfe5566dc4
Parents: b516f57 5ded6b5
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Mar 26 13:43:59 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Mar 26 13:43:59 2014 -0700

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml        |   13 +
 .../collection/guice/CollectionModule.java      |    8 +-
 .../impl/EntityCollectionManagerImpl.java       |   19 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |   14 +-
 .../collection/rx/CassandraThreadScheduler.java |  107 --
 .../persistence/collection/rx/RxFig.java        |   42 -
 .../stage/write/WriteUniqueVerifyStageTest.java |    3 +-
 .../mvcc/stage/write/WriteUniqueVerifyTest.java |    6 +-
 .../rx/CassandraThreadSchedulerTest.java        |  413 -----
 .../persistence/collection/rx/ParallelTest.java |    6 +-
 .../usergrid/persistence/graph/EdgeManager.java |  163 --
 .../persistence/graph/EdgeManagerFactory.java   |   40 -
 .../usergrid/persistence/graph/GraphFig.java    |   39 +-
 .../persistence/graph/GraphManager.java         |  169 ++
 .../persistence/graph/GraphManagerFactory.java  |   40 +
 .../graph/consistency/AsyncProcessorImpl.java   |   48 +-
 .../graph/consistency/TimeoutTask.java          |    2 +-
 .../persistence/graph/guice/EdgeWrite.java      |   37 -
 .../persistence/graph/guice/GraphModule.java    |   14 +-
 .../graph/hystrix/HystrixGraphObservable.java   |   71 +
 .../graph/impl/CollectionIndexObserver.java     |   14 +-
 .../graph/impl/EdgeDeleteListener.java          |   68 +-
 .../persistence/graph/impl/EdgeManagerImpl.java |  408 -----
 .../graph/impl/EdgeWriteListener.java           |  103 --
 .../graph/impl/GraphManagerImpl.java            |  384 +++++
 .../graph/impl/NodeDeleteListener.java          |  216 ++-
 .../graph/impl/SimpleSearchByEdgeType.java      |   38 +
 .../graph/impl/stage/AbstractEdgeRepair.java    |   47 +-
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |    4 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |   33 +-
 .../graph/impl/stage/EdgeWriteRepair.java       |   44 -
 .../graph/impl/stage/EdgeWriteRepairImpl.java   |   76 -
 .../graph/serialization/EdgeSerialization.java  |   12 +-
 .../impl/EdgeMetadataSerializationImpl.java     |   19 +-
 .../impl/EdgeSerializationImpl.java             |  256 +--
 .../impl/parse/ColumnNameIterator.java          |   38 +-
 .../impl/parse/ObservableIterator.java          |   26 +-
 .../persistence/graph/EdgeManagerIT.java        | 1468 -----------------
 .../graph/EdgeManagerStressTest.java            |  313 ----
 .../persistence/graph/GraphManagerIT.java       | 1497 ++++++++++++++++++
 .../graph/GraphManagerStressTest.java           |  317 ++++
 .../graph/GraphManagerTimeoutIT.java            |  230 +++
 .../graph/consistency/AsyncProcessorTest.java   |   25 +-
 .../consistency/LocalTimeoutQueueTest.java      |    2 +-
 .../graph/guice/TestGraphModule.java            |    4 +-
 .../graph/impl/NodeDeleteListenerTest.java      |  221 ++-
 .../graph/impl/stage/EdgeDeleteRepairTest.java  |    6 +-
 .../graph/impl/stage/EdgeMetaRepairTest.java    |   83 +-
 .../graph/impl/stage/EdgeWriteRepairTest.java   |  220 ---
 .../EdgeSerializationChopTest.java              |   35 +-
 .../serialization/EdgeSerializationTest.java    |  206 ++-
 .../serialization/NodeSerializationTest.java    |   13 +-
 .../graph/serialization/TestCount.java          |  125 ++
 .../serialization/util/EdgeHasherTest.java      |   14 +-
 .../graph/test/util/EdgeTestUtils.java          |    7 +-
 .../graph/src/test/resources/log4j.properties   |   36 +
 stack/corepersistence/pom.xml                   |    3 +
 57 files changed, 3858 insertions(+), 4007 deletions(-)
----------------------------------------------------------------------



[07/27] git commit: Merge branch 'hystrix-integration' into asyncqueue

Posted by sn...@apache.org.
Merge branch 'hystrix-integration' into asyncqueue


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

Branch: refs/heads/entity-manager
Commit: 51381a36e5dbdda7830ac13e2b2e5df0f32bdc20
Parents: aae2a8d b1d12a1
Author: Todd Nine <tn...@apigee.com>
Authored: Tue Mar 25 12:35:13 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Tue Mar 25 12:35:13 2014 -0700

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml        |    6 +
 .../collection/guice/CollectionModule.java      |    8 +-
 .../impl/EntityCollectionManagerImpl.java       |   19 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |   14 +-
 .../collection/rx/CassandraThreadScheduler.java |  107 --
 .../persistence/collection/rx/RxFig.java        |   42 -
 .../stage/write/WriteUniqueVerifyStageTest.java |    3 +-
 .../mvcc/stage/write/WriteUniqueVerifyTest.java |    6 +-
 .../rx/CassandraThreadSchedulerTest.java        |  413 -----
 .../persistence/collection/rx/ParallelTest.java |    6 +-
 .../usergrid/persistence/graph/GraphFig.java    |   42 +-
 .../graph/consistency/AsyncProcessorImpl.java   |    6 +-
 .../graph/consistency/TimeoutTask.java          |    2 +-
 .../graph/hystrix/HystrixGraphObservable.java   |   52 +
 .../graph/impl/EdgeDeleteListener.java          |    6 +-
 .../persistence/graph/impl/EdgeManagerImpl.java |   46 +-
 .../graph/impl/EdgeWriteListener.java           |    2 +-
 .../graph/impl/NodeDeleteListener.java          |   33 +-
 .../graph/impl/stage/AbstractEdgeRepair.java    |   21 +-
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |    4 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |   22 +-
 .../graph/impl/stage/EdgeWriteRepairImpl.java   |    4 +-
 .../impl/EdgeMetadataSerializationImpl.java     |   17 +-
 .../impl/EdgeSerializationImpl.java             |   21 +-
 .../impl/parse/ColumnNameIterator.java          |   55 +-
 .../persistence/graph/EdgeManagerTimeoutIT.java | 1562 ++++++++++++++++++
 .../graph/consistency/AsyncProcessorTest.java   |    2 +-
 .../graph/test/util/EdgeTestUtils.java          |   17 +-
 stack/corepersistence/pom.xml                   |    1 +
 29 files changed, 1806 insertions(+), 733 deletions(-)
----------------------------------------------------------------------



[20/27] git commit: Updated Cassandra to Resolve issue

Posted by sn...@apache.org.
Updated Cassandra to Resolve issue


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

Branch: refs/heads/entity-manager
Commit: 16721c87921100bbfafa3697801a6579c6a1cb6e
Parents: 029c065
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Mar 26 13:02:30 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Mar 26 13:02:30 2014 -0700

----------------------------------------------------------------------
 stack/corepersistence/collection/pom.xml        |   7 +
 .../usergrid/persistence/graph/GraphFig.java    |  31 ++-
 .../persistence/graph/guice/EdgeWrite.java      |  37 ----
 .../persistence/graph/guice/GraphModule.java    |   6 +-
 .../graph/hystrix/HystrixGraphObservable.java   |  53 +++--
 .../graph/impl/EdgeWriteListener.java           | 125 -----------
 .../graph/impl/GraphManagerImpl.java            |  30 +--
 .../graph/impl/NodeDeleteListener.java          | 193 ++++++++++-------
 .../graph/impl/stage/AbstractEdgeRepair.java    |   3 +-
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |  27 +--
 .../graph/impl/stage/EdgeWriteRepair.java       |  44 ----
 .../graph/impl/stage/EdgeWriteRepairImpl.java   |  76 -------
 .../impl/EdgeMetadataSerializationImpl.java     |   2 +-
 .../impl/EdgeSerializationImpl.java             |  22 +-
 .../impl/parse/ColumnNameIterator.java          |  19 +-
 .../impl/parse/ObservableIterator.java          |  18 +-
 .../graph/impl/NodeDeleteListenerTest.java      |  26 ++-
 .../graph/impl/stage/EdgeWriteRepairTest.java   | 208 -------------------
 .../graph/serialization/TestCount.java          |  36 ++--
 .../graph/src/test/resources/log4j.properties   |  36 ++++
 stack/corepersistence/pom.xml                   |   1 +
 21 files changed, 316 insertions(+), 684 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/collection/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml
index 808347e..038fb67 100644
--- a/stack/corepersistence/collection/pom.xml
+++ b/stack/corepersistence/collection/pom.xml
@@ -101,6 +101,12 @@
         </dependency>
 
         <dependency>
+               <groupId>org.apache.cassandra</groupId>
+               <artifactId>cassandra-all</artifactId>
+               <version>${cassandra.version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.safehaus.guicyfig</groupId>
             <artifactId>guicyfig</artifactId>
             <version>${guicyfig.version}</version>
@@ -176,6 +182,7 @@
              </dependency>
 
 
+
       <!-- Re-add once this is done
       https://github.com/Netflix/Hystrix/pull/209-->
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
index de7f72f..80e87f6 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
@@ -19,7 +19,6 @@ public interface GraphFig extends GuicyFig {
 
     public static final String REPAIR_TIMEOUT = "usergrid.graph.repair.timeout";
 
-
     public static final String TIMEOUT_SIZE = "usergrid.graph.timeout.page.size";
 
     public static final String TIMEOUT_TASK_TIME = "usergrid.graph.timeout.task.time";
@@ -32,11 +31,11 @@ public interface GraphFig extends GuicyFig {
 
     public static final String READ_TIMEOUT = "usergrid.graph.read.timeout";
 
-    @Default("1000")
+    @Default( "1000" )
     @Key(SCAN_PAGE_SIZE)
     int getScanPageSize();
 
-    @Default("CL_ONE")
+    @Default("CL_QUORUM")
     @Key(READ_CL)
     String getReadCL();
 
@@ -44,31 +43,31 @@ public interface GraphFig extends GuicyFig {
     @Key(WRITE_CL)
     String getWriteCL();
 
-//    @Default("10000")
-//    @Key(WRITE_TIMEOUT)
-//    int getWriteTimeout();
+    @Default( "10000" )
+    @Key( WRITE_TIMEOUT )
+    int getWriteTimeout();
 
     /**
      * Get the read timeout (in milliseconds) that we should allow when reading from the data source
      */
-    @Default( "10000" )
-    @Key( READ_TIMEOUT )
+    @Default("10000")
+    @Key(READ_TIMEOUT)
     int getReadTimeout();
 
-    @Default( "100" )
-    @Key( TIMEOUT_SIZE )
+    @Default("100")
+    @Key(TIMEOUT_SIZE)
     int getTimeoutReadSize();
 
-    @Default( "500" )
-    @Key( TIMEOUT_TASK_TIME )
+    @Default("500")
+    @Key(TIMEOUT_TASK_TIME)
     long getTaskLoopTime();
 
-    @Default( "10" )
-    @Key( REPAIR_CONCURRENT_SIZE )
+    @Default("5")
+    @Key(REPAIR_CONCURRENT_SIZE)
     int getRepairConcurrentSize();
 
     @Default("10000")
-      @Key(WRITE_TIMEOUT)
-      int getRepairTimeout();
+    @Key(REPAIR_TIMEOUT)
+    int getRepairTimeout();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/EdgeWrite.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/EdgeWrite.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/EdgeWrite.java
deleted file mode 100644
index b8afb13..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/EdgeWrite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.guice;
-
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import com.google.inject.BindingAnnotation;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-
-@BindingAnnotation
-@Target( { FIELD, PARAMETER, METHOD } )
-@Retention( RUNTIME )
-public @interface EdgeWrite {}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
index d575471..072cefc 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
@@ -24,9 +24,9 @@ import org.safehaus.guicyfig.GuicyFigModule;
 import org.apache.usergrid.persistence.collection.guice.CollectionModule;
 import org.apache.usergrid.persistence.collection.migration.Migration;
 import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessObserver;
+import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.GraphManager;
 import org.apache.usergrid.persistence.graph.GraphManagerFactory;
-import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessorImpl;
 import org.apache.usergrid.persistence.graph.consistency.LocalTimeoutQueue;
@@ -37,8 +37,6 @@ import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepairImpl;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepairImpl;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeWriteRepair;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeWriteRepairImpl;
 import org.apache.usergrid.persistence.graph.serialization.CassandraConfig;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
@@ -97,13 +95,11 @@ public class GraphModule extends AbstractModule {
         bind(TimeoutQueue.class).to( LocalTimeoutQueue.class );
 
         bind(AsyncProcessor.class).annotatedWith( EdgeDelete.class ).to( AsyncProcessorImpl.class );
-        bind(AsyncProcessor.class).annotatedWith( EdgeWrite.class ).to( AsyncProcessorImpl.class );
         bind(AsyncProcessor.class).annotatedWith( NodeDelete.class ).to( AsyncProcessorImpl.class );
 
         //Repair/cleanup classes
         bind( EdgeMetaRepair.class).to( EdgeMetaRepairImpl.class );
 
-        bind( EdgeWriteRepair.class).to( EdgeWriteRepairImpl.class );
 
         bind( EdgeDeleteRepair.class).to( EdgeDeleteRepairImpl.class );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
index 8a44389..209dfbd 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/hystrix/HystrixGraphObservable.java
@@ -20,33 +20,52 @@
 package org.apache.usergrid.persistence.graph.hystrix;
 
 
-import com.netflix.hystrix.HystrixCommand;
 import com.netflix.hystrix.HystrixCommandGroupKey;
 import com.netflix.hystrix.HystrixObservableCommand;
 
 import rx.Observable;
-import rx.schedulers.Schedulers;
 
 
 /**
- *
- *
+ * A utility class that creates graph observables wrapped in Hystrix for timeouts and circuit breakers.
  */
 public class HystrixGraphObservable {
 
     /**
-     * Wrap the observable in the timeout
-     * @param observable
-     * @param <T>
-     * @return
+     * Command group used for realtime user commands
+     */
+    private static final HystrixCommandGroupKey USER_GROUP = HystrixCommandGroupKey.Factory.asKey( "Graph-User" );
+
+    /**
+     * Command group for asynchronous operations
+     */
+    private static final HystrixCommandGroupKey ASYNC_GROUP = HystrixCommandGroupKey.Factory.asKey( "Graph-Async" );
+
+
+    /**
+     * Wrap the observable in the timeout for user facing operation.  This is for user reads and deletes.
      */
-    public static <T> Observable<T> wrap(final Observable<T> observable){
-            return new HystrixObservableCommand<T>( HystrixCommandGroupKey.Factory.asKey( "Graph" ) ){
-
-                @Override
-                protected Observable<T> run() {
-                    return observable;
-                }
-            }.toObservable( Schedulers.io() );
-        }
+    public static <T> Observable<T> user( final Observable<T> observable ) {
+        return new HystrixObservableCommand<T>( USER_GROUP ) {
+
+            @Override
+            protected Observable<T> run() {
+                return observable;
+            }
+        }.observe();
+    }
+
+
+    /**
+      * Wrap the observable in the timeout for asynchronous operations.  This is for compaction and cleanup processing.
+      */
+     public static <T> Observable<T> async( final Observable<T> observable ) {
+         return new HystrixObservableCommand<T>( ASYNC_GROUP ) {
+
+             @Override
+             protected Observable<T> run() {
+                 return observable;
+             }
+         }.observe();
+     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
deleted file mode 100644
index 90146dc..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeWriteListener.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.impl;
-
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.GraphFig;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
-import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
-import org.apache.usergrid.persistence.graph.consistency.MessageListener;
-import org.apache.usergrid.persistence.graph.guice.EdgeWrite;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.graph.serialization.impl.parse.ObservableIterator;
-
-import com.fasterxml.uuid.UUIDComparator;
-import com.google.inject.Singleton;
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-import rx.Observable;
-import rx.functions.Func1;
-
-
-/**
- * Construct the asynchronous edge lister for the repair operation.
- */
-@Singleton
-public class EdgeWriteListener implements MessageListener<EdgeEvent<Edge>, EdgeEvent<Edge>> {
-
-    private final EdgeSerialization edgeSerialization;
-    private final GraphFig graphFig;
-    private final Keyspace keyspace;
-
-
-    public EdgeWriteListener( final EdgeSerialization edgeSerialization, final GraphFig graphFig,
-                              final Keyspace keyspace, @EdgeWrite final AsyncProcessor edgeWrite ) {
-        this.edgeSerialization = edgeSerialization;
-        this.graphFig = graphFig;
-        this.keyspace = keyspace;
-        edgeWrite.addListener( this );
-    }
-
-
-    @Override
-    public Observable<EdgeEvent<Edge>> receive( final EdgeEvent<Edge> write ) {
-
-        final Edge edge = write.getData();
-        final OrganizationScope scope = write.getOrganizationScope();
-        final UUID maxVersion = edge.getVersion();
-
-        return Observable.empty();
-
-//      TODO T.N, some async processing for balancing here
-//  return Observable.create( new ObservableIterator<MarkedEdge>() {
-//            @Override
-//            protected Iterator<MarkedEdge> getIterator() {
-//
-//                final SimpleSearchByEdge search =
-//                        new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), maxVersion,
-//                                null );
-//
-//                return edgeSerialization.getEdgeVersions( scope, search );
-//            }
-//        } ).filter( new Func1<MarkedEdge, Boolean>() {
-//
-//            //TODO, reuse this for delete operation
-//
-//
-//            /**
-//             * We only want to return edges < this version so we remove them
-//             * @param markedEdge
-//             * @return
-//             */
-//            @Override
-//            public Boolean call( final MarkedEdge markedEdge ) {
-//                return UUIDComparator.staticCompare( markedEdge.getVersion(), maxVersion ) < 0;
-//            }
-//            //buffer the deletes and issue them in a single mutation
-//        } ).buffer( graphFig.getScanPageSize() ).map( new Func1<List<MarkedEdge>, EdgeEvent<Edge>>() {
-//            @Override
-//            public EdgeEvent<Edge> call( final List<MarkedEdge> markedEdges ) {
-//
-//                final MutationBatch batch = keyspace.prepareMutationBatch();
-//
-//                for ( MarkedEdge edge : markedEdges ) {
-//                    final MutationBatch delete = edgeSerialization.deleteEdge( scope, edge );
-//
-//                    batch.mergeShallow( delete );
-//                }
-//
-//                try {
-//                    batch.execute();
-//                }
-//                catch ( ConnectionException e ) {
-//                    throw new RuntimeException( "Unable to issue write to cassandra", e );
-//                }
-//
-//                return write;
-//            }
-//        } );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
index 94d4dc3..ff63a60 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/GraphManagerImpl.java
@@ -39,7 +39,6 @@ import org.apache.usergrid.persistence.graph.SearchIdType;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.AsynchronousMessage;
 import org.apache.usergrid.persistence.graph.guice.EdgeDelete;
-import org.apache.usergrid.persistence.graph.guice.EdgeWrite;
 import org.apache.usergrid.persistence.graph.guice.NodeDelete;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
@@ -56,7 +55,6 @@ import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
@@ -76,7 +74,6 @@ public class GraphManagerImpl implements GraphManager {
 
     private final NodeSerialization nodeSerialization;
 
-    private final AsyncProcessor<Edge> edgeWriteAsyncProcessor;
     private final AsyncProcessor<Edge> edgeDeleteAsyncProcessor;
     private final AsyncProcessor<Id> nodeDeleteAsyncProcessor;
 
@@ -86,7 +83,7 @@ public class GraphManagerImpl implements GraphManager {
     @Inject
     public GraphManagerImpl( final EdgeMetadataSerialization edgeMetadataSerialization,
                             final EdgeSerialization edgeSerialization, final NodeSerialization nodeSerialization,
-                            final GraphFig graphFig, @EdgeWrite final AsyncProcessor edgeWrite,
+                            final GraphFig graphFig,
                             @EdgeDelete final AsyncProcessor edgeDelete, @NodeDelete final AsyncProcessor nodeDelete,
                             @Assisted final OrganizationScope scope ) {
 
@@ -100,9 +97,6 @@ public class GraphManagerImpl implements GraphManager {
         this.graphFig = graphFig;
 
 
-        this.edgeWriteAsyncProcessor = edgeWrite;
-
-
         this.edgeDeleteAsyncProcessor = edgeDelete;
 
 
@@ -123,8 +117,6 @@ public class GraphManagerImpl implements GraphManager {
 
                 mutation.mergeShallow( edgeMutation );
 
-                final AsynchronousMessage<Edge> event = edgeWriteAsyncProcessor.setVerification( edge, getTimeout() );
-
                 try {
                     mutation.execute();
                 }
@@ -132,8 +124,6 @@ public class GraphManagerImpl implements GraphManager {
                     throw new RuntimeException( "Unable to connect to cassandra", e );
                 }
 
-                edgeWriteAsyncProcessor.start( event );
-
                 return edge;
             }
         } );
@@ -199,7 +189,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<Edge> loadEdgeVersions( final SearchByEdge searchByEdge ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgeVersions" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgeVersions( scope, searchByEdge );
@@ -211,7 +201,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSource" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
@@ -223,7 +213,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<Edge> loadEdgesToTarget( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTarget" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
@@ -235,7 +225,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSourceByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSourceByTargetType" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSourceByTargetType( scope, search );
@@ -248,7 +238,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<Edge> loadEdgesToTargetByType( final SearchByIdType search ) {
-        return Observable.create( new ObservableIterator<MarkedEdge>() {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTargetBySourceType" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTargetBySourceType( scope, search );
@@ -261,7 +251,7 @@ public class GraphManagerImpl implements GraphManager {
     @Override
     public Observable<String> getEdgeTypesFromSource( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( "getEdgeTypesFromSource" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
@@ -272,7 +262,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<String> getIdTypesFromSource( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( "getIdTypesFromSource" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesFromSource( scope, search );
@@ -284,7 +274,7 @@ public class GraphManagerImpl implements GraphManager {
     @Override
     public Observable<String> getEdgeTypesToTarget( final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( "getEdgeTypesToTarget" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
@@ -295,7 +285,7 @@ public class GraphManagerImpl implements GraphManager {
 
     @Override
     public Observable<String> getIdTypesToTarget( final SearchIdType search ) {
-        return Observable.create( new ObservableIterator<String>() {
+        return Observable.create( new ObservableIterator<String>( "getIdTypesToTarget" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getIdTypesToTarget( scope, search );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
index d0c0bec..aa4f94e 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListener.java
@@ -1,17 +1,16 @@
 package org.apache.usergrid.persistence.graph.impl;
 
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.cassandra.thrift.Mutation;
-
 import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.GraphFig;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
@@ -19,7 +18,6 @@ import org.apache.usergrid.persistence.graph.SearchEdgeType;
 import org.apache.usergrid.persistence.graph.consistency.AsyncProcessor;
 import org.apache.usergrid.persistence.graph.consistency.MessageListener;
 import org.apache.usergrid.persistence.graph.guice.NodeDelete;
-import org.apache.usergrid.persistence.graph.impl.stage.EdgeDeleteRepair;
 import org.apache.usergrid.persistence.graph.impl.stage.EdgeMetaRepair;
 import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
 import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
@@ -35,7 +33,6 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
 import rx.functions.Action0;
-import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
@@ -51,7 +48,6 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     private final NodeSerialization nodeSerialization;
     private final EdgeSerialization edgeSerialization;
     private final EdgeMetadataSerialization edgeMetadataSerialization;
-    private final EdgeDeleteRepair edgeDeleteRepair;
     private final EdgeMetaRepair edgeMetaRepair;
     private final GraphFig graphFig;
     protected final Keyspace keyspace;
@@ -63,8 +59,7 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
     @Inject
     public NodeDeleteListener( final NodeSerialization nodeSerialization, final EdgeSerialization edgeSerialization,
 
-                               final EdgeMetadataSerialization edgeMetadataSerialization,
-                               final EdgeDeleteRepair edgeDeleteRepair, final EdgeMetaRepair edgeMetaRepair,
+                               final EdgeMetadataSerialization edgeMetadataSerialization, final EdgeMetaRepair edgeMetaRepair,
                                final GraphFig graphFig, @NodeDelete final AsyncProcessor nodeDelete,
                                final Keyspace keyspace ) {
 
@@ -72,7 +67,6 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
         this.nodeSerialization = nodeSerialization;
         this.edgeSerialization = edgeSerialization;
         this.edgeMetadataSerialization = edgeMetadataSerialization;
-        this.edgeDeleteRepair = edgeDeleteRepair;
         this.edgeMetaRepair = edgeMetaRepair;
         this.graphFig = graphFig;
         this.keyspace = keyspace;
@@ -121,7 +115,8 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
 
                         //get all edges pointing to the target node and buffer then into groups for deletion
                         Observable<MarkedEdge> targetEdges =
-                                getEdgesTypesToTarget( scope, new SimpleSearchEdgeType( node, null ) )
+                                getEdgesTypesToTarget( scope, new SimpleSearchEdgeType( node, null ) ).subscribeOn(
+                                        Schedulers.io() )
                                         .flatMap( new Func1<String, Observable<MarkedEdge>>() {
                                             @Override
                                             public Observable<MarkedEdge> call( final String edgeType ) {
@@ -133,7 +128,8 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
 
                         //get all edges pointing to the source node and buffer them into groups for deletion
                         Observable<MarkedEdge> sourceEdges =
-                                getEdgesTypesFromSource( scope, new SimpleSearchEdgeType( node, null ) )
+                                getEdgesTypesFromSource( scope, new SimpleSearchEdgeType( node, null ) ).subscribeOn(
+                                        Schedulers.io() )
                                         .flatMap( new Func1<String, Observable<MarkedEdge>>() {
                                             @Override
                                             public Observable<MarkedEdge> call( final String edgeType ) {
@@ -142,78 +138,87 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
                                             }
                                         } );
 
-
-                        //each time an edge is emitted, delete it via batch mutation since we'll already be buffered
+                        //merge both source and target into 1 observable.  We'll need to check them all regardless of order
                         return Observable.merge( targetEdges, sourceEdges );
                     }
                 } )
-                //buffer and delete marked edges in our buffer size
-                .buffer( graphFig.getScanPageSize() ).flatMap(
-                        new Func1<List<MarkedEdge>, Observable<MarkedEdge>>() {
-                            @Override
-                            public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
+                //buffer and delete marked edges in our buffer size so we're making less trips to cassandra
+                .buffer( graphFig.getScanPageSize() ).flatMap( new Func1<List<MarkedEdge>, Observable<MarkedEdge>>() {
+                    @Override
+                    public Observable<MarkedEdge> call( final List<MarkedEdge> markedEdges ) {
 
-                                LOG.debug( "Batching {} edges for deletion" , markedEdges.size());
+                        LOG.debug( "Batching {} edges for node {} for deletion", markedEdges.size(), node );
 
-                                final MutationBatch batch = keyspace.prepareMutationBatch();
+                        final MutationBatch batch = keyspace.prepareMutationBatch();
 
-                                for(MarkedEdge edge: markedEdges){
+                        Set<TargetPair> sourceNodes = new HashSet<TargetPair>( markedEdges.size() );
+                        Set<TargetPair> targetNodes = new HashSet<TargetPair>( markedEdges.size() );
 
-                                    //delete the newest edge <= the version on the node delete
-                                    LOG.debug( "Deleting edge {}", edge );
-                                    final MutationBatch delete = edgeSerialization.deleteEdge( scope,  edge );
+                        for ( MarkedEdge edge : markedEdges ) {
 
-                                    batch.mergeShallow( delete );
-                                }
+                            //delete the newest edge <= the version on the node delete
+                            final MutationBatch delete = edgeSerialization.deleteEdge( scope, edge );
 
-                                try {
-                                    batch.execute();
-                                }
-                                catch ( ConnectionException e ) {
-                                    throw new RuntimeException( "Unable to delete edges", e );
-                                }
+                            batch.mergeShallow( delete );
 
-                                return Observable.from(markedEdges);
-                            }
-                        } )
-                        //TODO Fix this
-//        .flatMap( new Func1<MarkedEdge, Observable<MarkedEdge>>() {
-//            @Override
-//            public Observable<MarkedEdge> call( final MarkedEdge edge ) {
-//
-//
-//                return Observable.just( edge );
+                            sourceNodes.add( new TargetPair( edge.getSourceNode(), edge.getType() ) );
+                            targetNodes.add( new TargetPair( edge.getTargetNode(), edge.getType() ) );
+                        }
 
+                        try {
+                            batch.execute();
+                        }
+                        catch ( ConnectionException e ) {
+                            throw new RuntimeException( "Unable to delete edges", e );
+                        }
 
+                        //now  delete meta data
 
 
-//                //delete both the source and target meta data in parallel for the edge we deleted in the previous step
-//                //if nothing else is using them
-//                Observable<Integer> sourceMetaRepaired =
-//                        edgeMetaRepair.repairSources( scope, edge.getSourceNode(), edge.getType(), version );
-//
-//                Observable<Integer> targetMetaRepaired =
-//                        edgeMetaRepair.repairTargets( scope, edge.getTargetNode(), edge.getType(), version );
-//
-//                //sum up the number of subtypes we retain
-//                return Observable.concat( sourceMetaRepaired, targetMetaRepaired ).last()
-//                                 .map( new Func1<Integer, MarkedEdge>() {
-//                                     @Override
-//                                     public MarkedEdge call( final Integer integer ) {
-//
-//                                         LOG.debug( "Retained {} subtypes for edge {}", integer, edge );
+                        //delete both the source and target meta data in parallel for the edge we deleted in the
+                        // previous step
+                        //if nothing else is using them.  We purposefully do not schedule them on a new scheduler
+                        //we want them running on the i/o thread from the Observable emitting all the edges
+
 //
-//                                         return edge;
-//                                     }
-//                                 } );
+                        LOG.debug( "About to audit {} source types", sourceNodes.size() );
+
+                        Observable<Integer> sourceMetaCleanup = Observable.from( sourceNodes ).flatMap(
+                                new Func1<TargetPair, Observable<Integer>>() {
+                                    @Override
+                                    public Observable<Integer> call( final TargetPair targetPair ) {
+                                        return edgeMetaRepair
+                                                .repairSources( scope, targetPair.id, targetPair.edgeType, version );
+                                    }
+                                } ).last();
+
+
+                        LOG.debug( "About to audit {} target types", targetNodes.size() );
+
+                        Observable<Integer> targetMetaCleanup =  Observable.from( targetNodes ).flatMap( new Func1<TargetPair, Observable<Integer>>() {
+                            @Override
+                            public Observable<Integer> call( final TargetPair targetPair ) {
+                                return edgeMetaRepair
+                                        .repairTargets( scope, targetPair.id, targetPair.edgeType, version );
+                            }
+                        } ).last();
 
 
-//            }
-//        })
+                        //run both the source/target edge type cleanup, then proceed
+                        return Observable.merge( sourceMetaCleanup, targetMetaCleanup ).last().flatMap(  new Func1<Integer,
+                                Observable<MarkedEdge>>() {
+                            @Override
+                            public Observable<MarkedEdge> call( final Integer integer ) {
+                                return Observable.from( markedEdges );
+                            }
+                        } );
+                    }
+                } )
 
-    .count()
-                //if nothing is ever emitted, emit 0 so that we know no operations took place. Finally remove the
-                // target node in the mark
+                .count()
+                        //if nothing is ever emitted, emit 0 so that we know no operations took place. Finally remove
+                        // the
+                        // target node in the mark
                 .defaultIfEmpty( 0 ).doOnCompleted( new Action0() {
                     @Override
                     public void call() {
@@ -233,12 +238,12 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesToTarget( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>(  ) {
+        return Observable.create( new ObservableIterator<String>( "getEdgeTypesToTarget" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesToTarget( scope, search );
             }
-        } ).subscribeOn( Schedulers.io() );
+        } );
     }
 
 
@@ -247,12 +252,12 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<String> getEdgesTypesFromSource( final OrganizationScope scope, final SearchEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<String>(  ) {
+        return Observable.create( new ObservableIterator<String>( "getEdgeTypesFromSource" ) {
             @Override
             protected Iterator<String> getIterator() {
                 return edgeMetadataSerialization.getEdgeTypesFromSource( scope, search );
             }
-        } ).subscribeOn( Schedulers.io() );
+        } );
     }
 
 
@@ -261,12 +266,12 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesToTarget( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesToTarget" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesToTarget( scope, search );
             }
-        } ).subscribeOn( Schedulers.io() );
+        } );
     }
 
 
@@ -275,11 +280,53 @@ public class NodeDeleteListener implements MessageListener<EdgeEvent<Id>, Intege
      */
     private Observable<MarkedEdge> loadEdgesFromSource( final OrganizationScope scope, final SearchByEdgeType search ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "getEdgesFromSource" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
             }
-        } ).subscribeOn( Schedulers.io() );
+        } );
+    }
+
+
+    private static class TargetPair {
+        protected final Id id;
+        protected final String edgeType;
+
+
+        private TargetPair( final Id id, final String edgeType ) {
+            this.id = id;
+            this.edgeType = edgeType;
+        }
+
+
+        @Override
+        public boolean equals( final Object o ) {
+            if ( this == o ) {
+                return true;
+            }
+            if ( o == null || getClass() != o.getClass() ) {
+                return false;
+            }
+
+            final TargetPair that = ( TargetPair ) o;
+
+            if ( !edgeType.equals( that.edgeType ) ) {
+                return false;
+            }
+            if ( !id.equals( that.id ) ) {
+                return false;
+            }
+
+            return true;
+        }
+
+
+        @Override
+        public int hashCode() {
+            int result = id.hashCode();
+            result = 31 * result + edgeType.hashCode();
+            return result;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
index 310fa1f..898a04d 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/AbstractEdgeRepair.java
@@ -42,7 +42,6 @@ import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
@@ -122,7 +121,7 @@ public abstract class AbstractEdgeRepair  {
      */
     private Observable<MarkedEdge> getEdgeVersions( final OrganizationScope scope, final Edge edge ) {
 
-        return Observable.create( new ObservableIterator<MarkedEdge>(  ) {
+        return Observable.create( new ObservableIterator<MarkedEdge>( "edgeVersions" ) {
             @Override
             protected Iterator<MarkedEdge> getIterator() {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
index 8b81d0a..022548c 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeMetaRepairImpl.java
@@ -47,7 +47,6 @@ import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
-import rx.Scheduler;
 import rx.functions.Action1;
 import rx.functions.Func1;
 import rx.observables.MathObservable;
@@ -123,7 +122,8 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                             LOG.debug( "Checking for edges with nodeId {}, type {}, and subtype {}", node, edgeType, subType );
 
                             Observable<Integer> search =
-                                    serialization.loadEdges( scope, node, edgeType, subType, version ).take( 1 ).count()
+                                    //load each edge in it's own thread
+                                    serialization.loadEdges( scope, node, edgeType, subType, version ).subscribeOn( Schedulers.io() ).take( 1 ).count()
                                                  .doOnNext( new Action1<Integer>() {
 
                                                      @Override
@@ -145,7 +145,7 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
 
 
 
-                                                         LOG.debug( "No edges with nodeId {}, type {}, and subtype {}. Removing", node, edgeType, subType );
+                                                         LOG.debug( "No edges with nodeId {}, type {}, and subtype {}. Removing subtype.", node, edgeType, subType );
                                                          batch.mergeShallow( serialization
                                                                  .removeEdgeSubType( scope, node, edgeType, subType,
                                                                          version ) );
@@ -166,7 +166,10 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
                                                  public void call( final Integer count ) {
 
 
-                                                     LOG.debug( "Executing batch for subtype deletion with type {}.  Mutation has {} rows to mutate ", edgeType, batch.getRowCount() );
+                                                     LOG.debug(
+                                                             "Executing batch for subtype deletion with type {}.  " +
+                                                                     "Mutation has {} rows to mutate ",
+                                                             edgeType, batch.getRowCount() );
 
                                                      try {
                                                          batch.execute();
@@ -250,26 +253,26 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>( ) {
+            return Observable.create( new ObservableIterator<String>( "edgeTargetIdTypes" ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
                             .getIdTypesToTarget( scope, new SimpleSearchIdType( nodeId, edgeType, null ) );
                 }
-            } ).subscribeOn( Schedulers.io() );
+            } );
         }
 
 
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>( ) {
+            return Observable.create( new ObservableIterator<MarkedEdge>( "edgeTargetSubTypes" ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesToTargetBySourceType( scope,
                             new SimpleSearchByIdType( nodeId, edgeType, version, subType, null ) );
                 }
-            } ).subscribeOn( Schedulers.io() );
+            } );
         }
 
 
@@ -295,26 +298,26 @@ public class EdgeMetaRepairImpl implements EdgeMetaRepair {
         @Override
         public Observable<String> loadEdgeSubTypes( final OrganizationScope scope, final Id nodeId,
                                                     final String edgeType, final UUID version ) {
-            return Observable.create( new ObservableIterator<String>( ) {
+            return Observable.create( new ObservableIterator<String>( "edgeSourceIdTypes" ) {
                 @Override
                 protected Iterator<String> getIterator() {
                     return edgeMetadataSerialization
                             .getIdTypesFromSource( scope, new SimpleSearchIdType( nodeId, edgeType, null ) );
                 }
-            } ).subscribeOn( Schedulers.io() );
+            } );
         }
 
 
         @Override
         public Observable<MarkedEdge> loadEdges( final OrganizationScope scope, final Id nodeId, final String edgeType,
                                                  final String subType, final UUID version ) {
-            return Observable.create( new ObservableIterator<MarkedEdge>( ) {
+            return Observable.create( new ObservableIterator<MarkedEdge>( "edgeSourceSubTypes" ) {
                 @Override
                 protected Iterator<MarkedEdge> getIterator() {
                     return edgeSerialization.getEdgesFromSourceByTargetType( scope,
                             new SimpleSearchByIdType( nodeId, edgeType, version, subType, null ) );
                 }
-            } ).subscribeOn( Schedulers.io() );
+            } );
         }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepair.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepair.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepair.java
deleted file mode 100644
index 92be7a7..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepair.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.impl.stage;
-
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
-
-import rx.Observable;
-
-
-/**
- * Interface to perform repair operations on an edge when it is written
- */
-public interface EdgeWriteRepair {
-
-    /**
-     * Repair this edge.  Remove previous entries
-     * @param scope The scope to use
-     * @param edge The last edge to retain.  All versions  < this edge's version  will be deleted
-     *
-     * @return An observable that emits every version of the edge we delete.  Note that it may emit duplicates
-     * since this is a streaming API.
-     */
-    public Observable<MarkedEdge> repair( OrganizationScope scope, Edge edge );
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
deleted file mode 100644
index f77ef95..0000000
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairImpl.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.impl.stage;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.GraphFig;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-
-import com.fasterxml.uuid.UUIDComparator;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.netflix.astyanax.Keyspace;
-
-import rx.Observable;
-import rx.Scheduler;
-import rx.functions.Func1;
-
-
-/**
- * SimpleRepair operation
- */
-@Singleton
-public class EdgeWriteRepairImpl extends AbstractEdgeRepair implements EdgeWriteRepair {
-
-
-    @Inject
-    public EdgeWriteRepairImpl( final EdgeSerialization edgeSerialization, final GraphFig graphFig,
-                                final Keyspace keyspace) {
-        super( edgeSerialization, graphFig, keyspace );
-    }
-
-
-    @Override
-    public Observable<MarkedEdge> repair( final OrganizationScope scope, final Edge edge ) {
-
-        return super.repair( scope, edge );
-    }
-
-
-    @Override
-    protected Func1<MarkedEdge, Boolean> getFilter( final UUID maxVersion ) {
-        return new Func1<MarkedEdge, Boolean>() {
-            /**
-             * We only want to return edges < this version so we remove them
-             * @param markedEdge
-             * @return
-             */
-            @Override
-            public Boolean call( final MarkedEdge markedEdge ) {
-                return UUIDComparator.staticCompare( markedEdge.getVersion(), maxVersion ) < 0;
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
index b230399..38893e2 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeMetadataSerializationImpl.java
@@ -132,7 +132,7 @@ public class EdgeMetadataSerializationImpl implements EdgeMetadataSerialization,
         EdgeUtils.validateEdge( edge );
 
 
-        MutationBatch batch = keyspace.prepareMutationBatch();
+        MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() );
 
         final Id source = edge.getSourceNode();
         final Id target = edge.getTargetNode();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
index 0341cac..790c386 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
@@ -299,7 +299,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         final String type = search.getType();
         final UUID maxVersion = search.getMaxVersion();
 
-        return getEdges( GRAPH_SOURCE_NODE_EDGES, new EdgeSearcher<RowKey>( scope, search.last() ) {
+        return getEdges( GRAPH_SOURCE_NODE_EDGES, new EdgeSearcher<RowKey>( scope, maxVersion, search.last() ) {
 
 
             @Override
@@ -345,8 +345,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
         final Id sourceId = edgeType.getNode();
         final String type = edgeType.getType();
+        final UUID maxVersion = edgeType.getMaxVersion();
 
-        return getEdges( GRAPH_SOURCE_NODE_EDGES, new EdgeSearcher<RowKey>( scope, edgeType.last() ) {
+        return getEdges( GRAPH_SOURCE_NODE_EDGES, new EdgeSearcher<RowKey>( scope, maxVersion, edgeType.last() ) {
             @Override
             protected RowKey generateRowKey() {
                 return new RowKey( sourceId, type );
@@ -377,8 +378,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         final Id targetId = edgeType.getNode();
         final String type = edgeType.getType();
         final String targetType = edgeType.getIdType();
+        final UUID maxVersion = edgeType.getMaxVersion();
 
-        return getEdges( GRAPH_SOURCE_NODE_TARGET_TYPE, new EdgeSearcher<RowKeyType>( scope, edgeType.last() ) {
+        return getEdges( GRAPH_SOURCE_NODE_TARGET_TYPE, new EdgeSearcher<RowKeyType>( scope, maxVersion, edgeType.last() ) {
             @Override
             protected RowKeyType generateRowKey() {
                 return new RowKeyType( targetId, type, targetType );
@@ -407,8 +409,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
         final Id targetId = edgeType.getNode();
         final String type = edgeType.getType();
+        final UUID maxVersion = edgeType.getMaxVersion();
 
-        return getEdges( GRAPH_TARGET_NODE_EDGES, new EdgeSearcher<RowKey>( scope, edgeType.last() ) {
+        return getEdges( GRAPH_TARGET_NODE_EDGES, new EdgeSearcher<RowKey>( scope, maxVersion, edgeType.last() ) {
 
 
             @Override
@@ -441,8 +444,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         final Id targetId = edgeType.getNode();
         final String sourceType = edgeType.getIdType();
         final String type = edgeType.getType();
+        final UUID maxVersion = edgeType.getMaxVersion();
 
-        return getEdges( GRAPH_TARGET_NODE_SOURCE_TYPE, new EdgeSearcher<RowKeyType>( scope, edgeType.last() ) {
+        return getEdges( GRAPH_TARGET_NODE_SOURCE_TYPE, new EdgeSearcher<RowKeyType>( scope, maxVersion, edgeType.last()) {
             @Override
             protected RowKeyType generateRowKey() {
                 return new RowKeyType( targetId, type, sourceType );
@@ -672,11 +676,13 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
     private static abstract class EdgeSearcher<R> implements ColumnParser<DirectedEdge, MarkedEdge> {
 
         protected final Optional<Edge> last;
+        protected final UUID maxVersion;
         protected final OrganizationScope scope;
 
 
-        protected EdgeSearcher( final OrganizationScope scope, final Optional<Edge> last ) {
+        protected EdgeSearcher( final OrganizationScope scope, final UUID maxVersion , final Optional<Edge> last) {
             this.scope = scope;
+            this.maxVersion = maxVersion;
             this.last = last;
         }
 
@@ -692,7 +698,11 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
                 builder.setStart( sourceEdge, EDGE_SERIALIZER );
+            }else{
+
+
             }
+
         }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
index b6d17c6..1287dbb 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ColumnNameIterator.java
@@ -4,6 +4,7 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.Column;
 import com.netflix.astyanax.query.RowQuery;
 import com.netflix.hystrix.HystrixCommand;
@@ -87,17 +88,11 @@ public class ColumnNameIterator<C, T> implements Iterable<T>, Iterator<T> {
     private void advanceIterator() {
 
         //run producing the values within a hystrix command.  This way we'll time out if the read takes too long
-        sourceIterator = new HystrixCommand<Iterator<Column<C>>>( HystrixCommand.Setter.withGroupKey( GROUP_KEY )
-                                                                                .andCommandPropertiesDefaults(
-                                                                                        HystrixCommandProperties
-                                                                                                .Setter()
-                                                                                                .withExecutionIsolationThreadTimeoutInMilliseconds(
-                                                                                                        executionTimeout ) ) ) {
-
-            @Override
-            protected Iterator<Column<C>> run() throws Exception {
-                return rowQuery.execute().getResult().iterator();
-            }
-        }.execute();
+        try {
+            sourceIterator = rowQuery.execute().getResult().iterator();
+        }
+        catch ( ConnectionException e ) {
+            throw new RuntimeException( "Unable to get next page", e );
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
index 2d2456b..a222bac 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/parse/ObservableIterator.java
@@ -3,15 +3,11 @@ package org.apache.usergrid.persistence.graph.serialization.impl.parse;
 
 import java.util.Iterator;
 
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import rx.Observable;
-import rx.Observer;
 import rx.Subscriber;
-import rx.Subscription;
-import rx.subscriptions.Subscriptions;
 
 
 /**
@@ -23,6 +19,14 @@ public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T>
 
     private static final Logger log = LoggerFactory.getLogger( ObservableIterator.class );
 
+    private final String name;
+
+
+    /**
+     * @param name  The simple name of the iterator, used for debugging
+     */
+    protected ObservableIterator( final String name ) {this.name = name;}
+
 
     @Override
     public void call( final Subscriber<? super T> subscriber ) {
@@ -37,11 +41,15 @@ public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T>
             while ( itr.hasNext() && !subscriber.isUnsubscribed()) {
                 final T next = itr.next();
 
-                log.debug( "Emitting {}", next );
+                log.trace( "Iterator '{}' emitting item '{}'",  name, next );
+
+                assert next != null;
 
                 subscriber.onNext( next );
             }
 
+
+
             subscriber.onCompleted();
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
index 48890ca..14ab9c4 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/NodeDeleteListenerTest.java
@@ -54,8 +54,8 @@ public class NodeDeleteListenerTest {
 
     private static final Logger log = LoggerFactory.getLogger( NodeDeleteListenerTest.class );
 
-    @ClassRule
-    public static CassandraRule rule = new CassandraRule();
+//    @ClassRule
+//    public static CassandraRule rule = new CassandraRule();
 
 
     @Inject
@@ -317,13 +317,13 @@ public class NodeDeleteListenerTest {
      * since it has no other targets
      */
     @Test
-    public void testMultiDelete() throws ConnectionException {
+    public void testMultiDelete() throws ConnectionException, InterruptedException {
 
         GraphManager em = emf.createEdgeManager( scope );
 
 
         //create loads of edges to easily delete.  We'll keep all the types of "test"
-        final int edgeCount = graphFig.getScanPageSize() * 4;
+        final int edgeCount = graphFig.getScanPageSize() * 2;
         Id toDelete = createId( "toDelete" );
         final String edgeType = "test";
 
@@ -360,9 +360,10 @@ public class NodeDeleteListenerTest {
         log.info( "Saved {} target edges", targetCount );
 
 
-        //mark the node so
-        UUID deleteVersion = UUIDGenerator.newTimeUUID();
+        //mark the node for deletion
+//        UUID deleteVersion = UUIDGenerator.newTimeUUID();
 
+        UUID deleteVersion = UUID.fromString( "ffffffff-ffff-1fff-bfff-ffffffffffff" );
 
         nodeSerialization.mark( scope, toDelete, deleteVersion ).execute();
 
@@ -371,6 +372,7 @@ public class NodeDeleteListenerTest {
 
         int count = deleteListener.receive( deleteEvent ).toBlockingObservable().last();
 
+        //TODO T.N. THIS SHOULD WORK!!!!  It fails intermittently with RX 0.17.1 with too many scheduler threads (which was wrong), try this again after the next release
         assertEquals( edgeCount, count );
 
         //now verify we can't get any of the info back
@@ -378,17 +380,19 @@ public class NodeDeleteListenerTest {
         UUID now = UUIDGenerator.newTimeUUID();
 
 
-        Iterator<MarkedEdge> returned =
+           //validate it's not returned by the
+
+        Iterator<MarkedEdge>  returned = edgeSerialization.getEdgesToTarget( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
+
+        assertFalse( "No target should be returned", returned.hasNext() );
+
+        returned =
                 edgeSerialization.getEdgesFromSource( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
 
         //no edge from source node should be returned
         assertFalse( "No source should be returned", returned.hasNext() );
 
-        //validate it's not returned by the
-
-        returned = edgeSerialization.getEdgesToTarget( scope, createSearchByEdge( toDelete, edgeType, now, null ) );
 
-        assertFalse( "No target should be returned", returned.hasNext() );
 
 
         //no types from source

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
deleted file mode 100644
index c7c95a1..0000000
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/impl/stage/EdgeWriteRepairTest.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.graph.impl.stage;
-
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.collection.OrganizationScope;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.graph.MarkedEdge;
-import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
-import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
-import org.apache.usergrid.persistence.graph.serialization.EdgeSerialization;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-import com.google.inject.Inject;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
-import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-/**
- *
- *
- */
-@RunWith(JukitoRunner.class)
-@UseModules({ TestGraphModule.class })
-public class EdgeWriteRepairTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger( EdgeWriteRepairTest.class );
-
-    @ClassRule
-    public static CassandraRule rule = new CassandraRule();
-
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-
-
-    @Inject
-    protected EdgeSerialization edgeSerialization;
-
-    @Inject
-    protected EdgeWriteRepair edgeWriteRepair;
-
-
-    protected OrganizationScope scope;
-
-
-    @Before
-    public void setup() {
-        scope = mock( OrganizationScope.class );
-
-        Id orgId = mock( Id.class );
-
-        when( orgId.getType() ).thenReturn( "organization" );
-        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
-
-        when( scope.getOrganization() ).thenReturn( orgId );
-    }
-
-
-    /**
-     * Test repairing with no edges
-     */
-    @Test
-    public void noEdges() {
-        Edge edge = createEdge( "source", "test", "target" );
-
-        Iterator<MarkedEdge> edges = edgeWriteRepair.repair( scope, edge ).toBlockingObservable().getIterator();
-
-        assertFalse( "No edges cleaned", edges.hasNext() );
-    }
-
-
-    /**
-     * Test repairing with no edges TODO: TN.  There appears to be a race condition here with ordering.  Not sure if
-     * this is intentional as part of the impl or if it's an issue
-     */
-    @Test
-    public void versionTest() throws ConnectionException {
-        final int size = 20;
-
-        final List<Edge> versions = new ArrayList<Edge>( size );
-
-        final Id sourceId = createId( "source" );
-        final Id targetId = createId( "target" );
-        final String edgeType = "edge";
-
-        int deleteIndex = size / 2;
-
-        Set<Edge> deletedEdges = new HashSet<Edge>();
-
-        for ( int i = 0; i < size; i++ ) {
-            final Edge edge = createEdge( sourceId, edgeType, targetId );
-
-            versions.add( edge );
-
-            edgeSerialization.writeEdge( scope, edge ).execute();
-
-            LOG.info( "Writing edge at index [{}] {}", i, edge );
-
-            if ( i < deleteIndex ) {
-                deletedEdges.add( edge );
-            }
-        }
-
-
-        Edge keep = versions.get( deleteIndex );
-
-        Iterable<MarkedEdge> edges = edgeWriteRepair.repair( scope, keep ).toBlockingObservable().toIterable();
-
-        Multiset<Edge> deletedStream = HashMultiset.create();
-
-        for ( MarkedEdge edge : edges ) {
-
-            LOG.info( "Returned edge {} for repair", edge );
-
-            final boolean shouldBeDeleted = deletedEdges.contains( edge );
-
-            assertTrue( "Removed matches saved index", shouldBeDeleted );
-
-            deletedStream.add( edge );
-        }
-
-        deletedEdges.removeAll( deletedStream.elementSet() );
-
-        assertEquals( 0, deletedEdges.size() );
-
-        //now verify we get all the versions we expect back
-        Iterator<MarkedEdge> iterator = edgeSerialization.getEdgeVersions( scope,
-                new SimpleSearchByEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID(), null ) );
-
-        int count = 0;
-
-        for ( MarkedEdge edge : new IterableWrapper<MarkedEdge>( iterator ) ) {
-
-            final Edge saved = versions.get( size - count - 1 );
-
-            assertEquals( saved, edge );
-
-            count++;
-        }
-
-        final int keptCount = size - deleteIndex;
-
-        assertEquals( "Kept edge version was the minimum", keptCount, count );
-    }
-
-
-    private class IterableWrapper<T> implements Iterable<T> {
-        private final Iterator<T> sourceIterator;
-
-
-        private IterableWrapper( final Iterator<T> sourceIterator ) {
-            this.sourceIterator = sourceIterator;
-        }
-
-
-        @Override
-        public Iterator<T> iterator() {
-            return this.sourceIterator;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
index 7af55da..2548864 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/TestCount.java
@@ -6,6 +6,8 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import rx.Observable;
 import rx.Subscriber;
@@ -21,14 +23,27 @@ import static org.junit.Assert.assertEquals;
  */
 public class TestCount {
 
+    private static final Logger log = LoggerFactory.getLogger(TestCount.class);
 
     @Test
     public void mergeTest(){
 
         final int sizePerObservable = 2000;
 
-        Observable<Integer> input1 = getObservables( sizePerObservable );
-        Observable<Integer> input2 = getObservables( sizePerObservable );
+        Observable<Integer> input1 = getObservables( sizePerObservable ).flatMap( new Func1<Integer, Observable<?
+                extends Integer>>() {
+            @Override
+            public Observable<? extends Integer> call( final Integer integer ) {
+                return getObservables( 100 );
+            }
+        } );
+        Observable<Integer> input2 = getObservables( sizePerObservable ).flatMap( new Func1<Integer, Observable<?
+                extends Integer>>() {
+            @Override
+            public Observable<? extends Integer> call( final Integer integer ) {
+                return getObservables( 100 );
+            }
+        } );
 
        int returned =  Observable.merge(input1, input2).buffer( 1000 ).flatMap(
                new Func1<List<Integer>, Observable<Integer>>() {
@@ -50,7 +65,7 @@ public class TestCount {
                } ).count().defaultIfEmpty( 0 ).toBlockingObservable().last();
 
 
-        assertEquals("Count was correct", sizePerObservable*2, returned);
+        assertEquals("Count was correct", sizePerObservable*2*100, returned);
     }
 
 
@@ -92,19 +107,12 @@ public class TestCount {
                         }
                     }
 
-                    //Sleep for a very long time before emitting the last value
-                    if(i == size -1){
-                        try {
-                            Thread.sleep(5000);
-                        }
-                        catch ( InterruptedException e ) {
-                            subscriber.onError( e );
-                            return;
-                        }
-                    }
+                    final Integer value = values.get( i );
+
+                    log.info( "Emitting {}", value  );
 
 
-                    subscriber.onNext( values.get( i ) );
+                    subscriber.onNext( value );
                 }
 
                 subscriber.onCompleted();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/graph/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/resources/log4j.properties b/stack/corepersistence/graph/src/test/resources/log4j.properties
new file mode 100644
index 0000000..849b280
--- /dev/null
+++ b/stack/corepersistence/graph/src/test/resources/log4j.properties
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# suppress inspection "UnusedProperty" for whole file
+log4j.rootLogger=INFO,stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c{3}.%M(%L)<%t>- %m%n
+
+log4j.logger.org.safehaus.chop.plugin=DEBUG
+log4j.logger.org.safehaus.guicyfig=ERROR
+log4j.logger.org.safehaus.chop.api.store.amazon=DEBUG
+log4j.logger.org.apache.http=ERROR
+log4j.logger.com.amazonaws.request=ERROR
+log4j.logger.cassandra.db=ERROR
+
+log4j.logger.org.apache.usergrid=DEBUG
+
+log4j.logger.org.apache.usergrid.persistence.graph.serialization.impl.parse=TRACE

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16721c87/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 9b7b1e1..9a9b7d3 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -40,6 +40,7 @@
         <surefire.version>2.16</surefire.version>
         <rx.version>0.17.1</rx.version>
         <hystrix.version>1.4.0-RC1</hystrix.version>
+        <cassandra.version>1.2.15</cassandra.version>
 
     </properties>
 


[17/27] Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ListUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ListUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ListUtils.java
deleted file mode 100644
index db56cdd..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ListUtils.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.commons.lang.math.NumberUtils;
-import org.apache.usergrid.persistence.collection.util.EntityUtils;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class ListUtils extends org.apache.commons.collections.ListUtils {
-    private static final Logger LOG = LoggerFactory.getLogger( ListUtils.class );
-
-
-    public static <A> A first( List<A> list ) {
-        if ( list == null ) {
-            return null;
-        }
-        if ( list.size() == 0 ) {
-            return null;
-        }
-        return list.get( 0 );
-    }
-
-
-    public static <A> A last( List<A> list ) {
-        if ( list == null ) {
-            return null;
-        }
-        if ( list.size() == 0 ) {
-            return null;
-        }
-        return list.get( list.size() - 1 );
-    }
-
-
-    public static <A> Integer firstInteger( List<A> list ) {
-        A a = first( list );
-        if ( a == null ) {
-            return null;
-        }
-
-        if ( a instanceof Integer ) {
-            return ( Integer ) a;
-        }
-
-        try {
-            return NumberUtils.toInt( ( String ) a );
-        }
-        catch ( Exception e ) {
-            LOG.warn( "Could not convert list item {} to int", a, e );
-        }
-        return null;
-    }
-
-
-    public static <A> Long firstLong( List<A> list ) {
-        A a = first( list );
-        if ( a == null ) {
-            return null;
-        }
-
-        if ( a instanceof Long ) {
-            return ( Long ) a;
-        }
-
-        try {
-            return NumberUtils.toLong( ( String ) a );
-        }
-        catch ( Exception e ) {
-            LOG.warn( "Could not convert list item {} to long", a, e );
-        }
-        return null;
-    }
-
-
-    public static <A> Boolean firstBoolean( List<A> list ) {
-        A a = first( list );
-        if ( a == null ) {
-            return null;
-        }
-
-        if ( a instanceof Boolean ) {
-            return ( Boolean ) a;
-        }
-
-        try {
-            return Boolean.parseBoolean( ( String ) a );
-        }
-        catch ( Exception e ) {
-            LOG.warn( "Could not convert list item {} to boolean", a, e );
-        }
-        return null;
-    }
-
-
-    public static <A> UUID firstUuid( List<A> list ) {
-        A i = first( list );
-        if ( i == null ) {
-            return null;
-        }
-
-        if ( i instanceof UUID ) {
-            return ( UUID ) i;
-        }
-
-        try {
-            return UUIDUtils.tryGetUUID( ( String ) i );
-        }
-        catch ( Exception e ) {
-            LOG.warn( "Could not convert list item {} to UUID", i, e );
-        }
-        return null;
-    }
-
-
-    public static boolean isEmpty( List<?> list ) {
-        return ( list == null ) || ( list.size() == 0 );
-    }
-
-
-    public static <T> List<T> dequeueCopy( List<T> list ) {
-        if ( !isEmpty( list ) ) {
-            list = list.subList( 1, list.size() );
-        }
-        return list;
-    }
-
-
-    public static <T> List<T> initCopy( List<T> list ) {
-        if ( !isEmpty( list ) ) {
-            list = new ArrayList<T>( list );
-        }
-        else {
-            list = new ArrayList<T>();
-        }
-        return list;
-    }
-
-
-    public static <T> T dequeue( List<T> list ) {
-        if ( !isEmpty( list ) ) {
-            return list.remove( 0 );
-        }
-        return null;
-    }
-
-
-    public static <T> List<T> queue( List<T> list, T item ) {
-        if ( list == null ) {
-            list = new ArrayList<T>();
-        }
-        list.add( item );
-        return list;
-    }
-
-
-    public static <T> List<T> requeue( List<T> list, T item ) {
-        if ( list == null ) {
-            list = new ArrayList<T>();
-        }
-        list.add( 0, item );
-        return list;
-    }
-
-
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public static List<?> flatten( Collection<?> l ) {
-        boolean hasCollection = false;
-        for ( Object o : l ) {
-            if ( o instanceof Collection ) {
-                hasCollection = true;
-                break;
-            }
-        }
-        if ( !hasCollection && ( l instanceof List ) ) {
-            return ( List<?> ) l;
-        }
-        List newList = new ArrayList();
-        for ( Object o : l ) {
-            if ( o instanceof List ) {
-                newList.addAll( flatten( ( List ) o ) );
-            }
-            else {
-                newList.add( o );
-            }
-        }
-        return newList;
-    }
-
-
-    public static boolean anyNull( List<?> l ) {
-        for ( Object o : l ) {
-            if ( o == null ) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
-    public static boolean anyNull( Object... objects ) {
-        for ( Object o : objects ) {
-            if ( o == null ) {
-                return true;
-            }
-        }
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/MapUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/MapUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/MapUtils.java
deleted file mode 100644
index 12da2e0..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/MapUtils.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import static org.apache.commons.lang.StringUtils.isNotBlank;
-
-import static org.apache.usergrid.utils.ClassUtils.cast;
-
-
-public class MapUtils extends org.apache.commons.collections.MapUtils {
-
-    public static <A, B> void addMapSet( Map<A, Set<B>> map, A a, B b ) {
-        addMapSet( map, false, a, b );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static <A, B> void addMapSet( Map<A, Set<B>> map, boolean ignoreCase, A a, B b ) {
-
-        Set<B> setB = map.get( a );
-        if ( setB == null ) {
-            if ( ignoreCase && ( b instanceof String ) ) {
-                setB = ( Set<B> ) new TreeSet<String>( String.CASE_INSENSITIVE_ORDER );
-            }
-            else {
-                setB = new LinkedHashSet<B>();
-            }
-            map.put( a, setB );
-        }
-        setB.add( b );
-    }
-
-
-    public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, A a, B b, C c ) {
-        addMapMapSet( map, false, a, b, c );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, boolean ignoreCase, A a, B b, C c ) {
-
-        Map<B, Set<C>> mapB = map.get( a );
-        if ( mapB == null ) {
-            if ( ignoreCase && ( b instanceof String ) ) {
-                mapB = ( Map<B, Set<C>> ) new TreeMap<String, Set<C>>( String.CASE_INSENSITIVE_ORDER );
-            }
-            else {
-                mapB = new LinkedHashMap<B, Set<C>>();
-            }
-            map.put( a, mapB );
-        }
-        addMapSet( mapB, ignoreCase, b, c );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static <A, B, C, D> void addMapMapMapSet( Map<A, Map<B, Map<C, Set<D>>>> map, boolean ignoreCase, A a, B b,
-                                                     C c, D d ) {
-        Map<B, Map<C, Set<D>>> mapB = map.get( a );
-        if ( mapB == null ) {
-            if ( ignoreCase && ( b instanceof String ) ) {
-                mapB = ( Map<B, Map<C, Set<D>>> ) new TreeMap<String, Map<C, Set<D>>>( String.CASE_INSENSITIVE_ORDER );
-            }
-            else {
-                mapB = new LinkedHashMap<B, Map<C, Set<D>>>();
-            }
-            map.put( a, mapB );
-        }
-        addMapMapSet( mapB, ignoreCase, b, c, d );
-    }
-
-
-    public static <A, B, C> C getMapMap( Map<A, Map<B, C>> map, A a, B b ) {
-
-        Map<B, C> mapB = map.get( a );
-        if ( mapB == null ) {
-            return null;
-        }
-        return mapB.get( b );
-    }
-
-
-    public static <A, B> void addMapList( Map<A, List<B>> map, A a, B b ) {
-
-        List<B> listB = map.get( a );
-        if ( listB == null ) {
-            listB = new ArrayList<B>();
-            map.put( a, listB );
-        }
-        listB.add( b );
-    }
-
-
-    public static <A, B> void addListToMapList( Map<A, List<B>> map, A a, List<B> b ) {
-
-        List<B> listB = map.get( a );
-        if ( listB == null ) {
-            listB = new ArrayList<B>();
-            map.put( a, listB );
-        }
-        listB.addAll( b );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static <K, V> V getValue( Map<K, ?> map, K k ) {
-        V v = null;
-        try {
-            v = ( V ) map.get( k );
-        }
-        catch ( ClassCastException e ) {
-            //LOG.war( "Map value {} was not the expected class", map.get( k ), e );
-        }
-
-        return v;
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static <K, V> Map<?, ?> map( Object... objects ) {
-        Map<K, V> map = new LinkedHashMap<K, V>();
-        int i = 0;
-        while ( i < objects.length ) {
-            if ( objects[i] instanceof Map.Entry ) {
-                Map.Entry<K, V> entry = ( Entry<K, V> ) objects[i];
-                map.put( entry.getKey(), entry.getValue() );
-                i++;
-            }
-            else if ( objects[i] instanceof Map ) {
-                map.putAll( ( Map<? extends K, ? extends V> ) objects[i] );
-                i++;
-            }
-            else if ( i < ( objects.length - 1 ) ) {
-                K k = ( K ) objects[i];
-                V v = ( V ) objects[i + 1];
-                map.put( k, v );
-                i += 2;
-            }
-            else {
-                break;
-            }
-        }
-        return map;
-    }
-
-
-    private static class SimpleMapEntry<K, V> implements Map.Entry<K, V> {
-
-        private final K k;
-        private V v;
-
-
-        public SimpleMapEntry( K k, V v ) {
-            this.k = k;
-            this.v = v;
-        }
-
-
-        @Override
-        public K getKey() {
-            return k;
-        }
-
-
-        @Override
-        public V getValue() {
-            return v;
-        }
-
-
-        @Override
-        public V setValue( V v ) {
-            V oldV = this.v;
-            this.v = v;
-            return oldV;
-        }
-    }
-
-
-    public static <K, V> Map.Entry<K, V> entry( K k, V v ) {
-        return new SimpleMapEntry<K, V>( k, v );
-    }
-
-
-    public static <K, V> K getFirstKey( Map<K, V> map ) {
-        if ( map == null ) {
-            return null;
-        }
-        Entry<K, V> e = map.entrySet().iterator().next();
-        if ( e != null ) {
-            return e.getKey();
-        }
-        return null;
-    }
-
-
-    public static <V> Map<String, V> filter( Map<String, V> map, String prefix, boolean removePrefix ) {
-        Map<String, V> filteredMap = new LinkedHashMap<String, V>();
-        for ( Entry<String, V> entry : map.entrySet() ) {
-            if ( entry.getKey().startsWith( prefix ) ) {
-                if ( removePrefix ) {
-                    filteredMap.put( entry.getKey().substring( prefix.length() ), entry.getValue() );
-                }
-                else {
-                    filteredMap.put( entry.getKey(), entry.getValue() );
-                }
-            }
-        }
-        return filteredMap;
-    }
-
-
-    public static <V> Map<String, V> filter( Map<String, V> map, String prefix ) {
-        return filter( map, prefix, false );
-    }
-
-
-    public static Properties filter( Properties properties, String prefix, boolean removePrefix ) {
-        Properties filteredProperties = new Properties();
-        for ( Entry<String, String> entry : asMap( properties ).entrySet() ) {
-            if ( entry.getKey().startsWith( prefix ) ) {
-                if ( removePrefix ) {
-                    filteredProperties.put( entry.getKey().substring( prefix.length() ), entry.getValue() );
-                }
-                else {
-                    filteredProperties.put( entry.getKey(), entry.getValue() );
-                }
-            }
-        }
-        return filteredProperties;
-    }
-
-
-    public static Properties filter( Properties properties, String prefix ) {
-        return filter( properties, prefix, false );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static Map<String, String> asMap( Properties properties ) {
-        return cast( properties );
-    }
-
-
-    public static <S, T> HashMapBuilder<S, T> hashMap( S key, T value ) {
-        return new HashMapBuilder<S, T>().map( key, value );
-    }
-
-
-    public static class HashMapBuilder<S, T> extends HashMap<S, T> {
-        private static final long serialVersionUID = 1L;
-
-
-        public HashMapBuilder() {
-        }
-
-
-        public HashMapBuilder<S, T> map( S key, T value ) {
-            put( key, value );
-            return this;
-        }
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static Map<String, List<?>> toMapList( Map<String, ?> m ) {
-        Map<String, List<Object>> mapList = new LinkedHashMap<String, List<Object>>();
-
-        for ( Entry<String, ?> e : m.entrySet() ) {
-            if ( e.getValue() instanceof List ) {
-                addListToMapList( mapList, e.getKey(), ( List<Object> ) e.getValue() );
-            }
-            else {
-                addMapList( mapList, e.getKey(), e.getValue() );
-            }
-        }
-
-        return cast( mapList );
-    }
-
-
-    public static Map<String, ?> putPath( String path, Object value ) {
-        return putPath( null, path, value );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static Map<String, ?> putPath( Map<String, ?> map, String path, Object value ) {
-
-        if ( map == null ) {
-            map = new HashMap<String, Object>();
-        }
-
-        int i = path.indexOf( '.' );
-        if ( i < 0 ) {
-            ( ( Map<String, Object> ) map ).put( path, value );
-            return map;
-        }
-        String segment = path.substring( 0, i ).trim();
-        if ( isNotBlank( segment ) ) {
-            Object o = map.get( segment );
-            if ( ( o != null ) && ( !( o instanceof Map ) ) ) {
-                return map;
-            }
-            Map<String, Object> subMap = ( Map<String, Object> ) o;
-            if ( subMap == null ) {
-                subMap = new HashMap<String, Object>();
-                ( ( Map<String, Object> ) map ).put( segment, subMap );
-            }
-            String subPath = path.substring( i + 1 );
-            if ( isNotBlank( subPath ) ) {
-                putPath( subMap, subPath, value );
-            }
-        }
-
-        return map;
-    }
-
-
-    public static <K, V> Map<K, V> emptyMapWithKeys( Map<K, V> map ) {
-        Map<K, V> newMap = new HashMap<K, V>();
-
-        for ( K k : map.keySet() ) {
-            newMap.put( k, null );
-        }
-
-        return newMap;
-    }
-
-
-    public static boolean hasKeys( Map<?, ?> map, String... keys ) {
-        if ( map == null ) {
-            return false;
-        }
-        for ( String key : keys ) {
-            if ( !map.containsKey( key ) ) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-
-    public static boolean hasKeys( Map<?, ?> map, Set<String> keys ) {
-        if ( map == null ) {
-            return false;
-        }
-        return map.keySet().containsAll( keys );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/StringUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/StringUtils.java
deleted file mode 100644
index 5f64ef3..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/StringUtils.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.util.Arrays;
-
-import org.apache.commons.io.IOUtils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.usergrid.utils.ConversionUtils.string;
-
-
-public class StringUtils extends org.apache.commons.lang.StringUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger( StringUtils.class );
-
-
-    public static Object lower( Object obj ) {
-        if ( !( obj instanceof String ) ) {
-            return obj;
-        }
-        return ( ( String ) obj ).toLowerCase();
-    }
-
-
-    public static String stringOrSubstringAfterLast( String str, char c ) {
-        if ( str == null ) {
-            return null;
-        }
-        int i = str.lastIndexOf( c );
-        if ( i != -1 ) {
-            return str.substring( i + 1 );
-        }
-        return str;
-    }
-
-
-    public static String stringOrSubstringBeforeLast( String str, char c ) {
-        if ( str == null ) {
-            return null;
-        }
-        int i = str.lastIndexOf( c );
-        if ( i != -1 ) {
-            return str.substring( 0, i );
-        }
-        return str;
-    }
-
-
-    public static String stringOrSubstringBeforeFirst( String str, char c ) {
-        if ( str == null ) {
-            return null;
-        }
-        int i = str.indexOf( c );
-        if ( i != -1 ) {
-            return str.substring( 0, i );
-        }
-        return str;
-    }
-
-
-    public static String stringOrSubstringAfterFirst( String str, char c ) {
-        if ( str == null ) {
-            return null;
-        }
-        int i = str.indexOf( c );
-        if ( i != -1 ) {
-            return str.substring( i + 1 );
-        }
-        return str;
-    }
-
-
-    public static String compactWhitespace( String str ) {
-        if ( str == null ) {
-            return null;
-        }
-        boolean prevWS = false;
-        StringBuilder builder = new StringBuilder();
-        for ( int i = 0; i < str.length(); i++ ) {
-            char c = str.charAt( i );
-            if ( Character.isWhitespace( c ) ) {
-                if ( !prevWS ) {
-                    builder.append( ' ' );
-                }
-                prevWS = true;
-            }
-            else {
-                prevWS = false;
-                builder.append( c );
-            }
-        }
-        return builder.toString().trim();
-    }
-
-
-    /** @return new string with replace applied */
-    public static String replaceAll( String source, String find, String replace ) {
-        if ( source == null ) {
-            return null;
-        }
-        while ( true ) {
-            String old = source;
-            source = source.replaceAll( find, replace );
-            if ( source.equals( old ) ) {
-                return source;
-            }
-        }
-    }
-
-
-    public static String toString( Object obj ) {
-        return string( obj );
-    }
-
-
-    public static String toStringFormat( Object obj, String format ) {
-        if ( obj != null ) {
-            if ( format != null ) {
-                if ( obj.getClass().isArray() ) {
-                    return String.format( format, Arrays.toString( ( Object[] ) obj ) );
-                }
-                return String.format( format, string( obj ) );
-            }
-            else {
-                return string( obj );
-            }
-        }
-        return "";
-    }
-
-
-    public static boolean isString( Object obj ) {
-        return obj instanceof String;
-    }
-
-
-    public static boolean isStringOrNull( Object obj ) {
-        if ( obj == null ) {
-            return true;
-        }
-        return obj instanceof String;
-    }
-
-
-    public static String readClasspathFileAsString( String filePath ) {
-        try {
-            return IOUtils.toString( StringUtils.class.getResourceAsStream( filePath ) );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error getting file from classpath: " + filePath, e );
-        }
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b516f578/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/UUIDUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/UUIDUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/UUIDUtils.java
deleted file mode 100644
index 6d8175c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/UUIDUtils.java
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.utils;
-
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.ReentrantLock;
-
-import com.fasterxml.uuid.EthernetAddress;
-import com.fasterxml.uuid.UUIDComparator;
-
-import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_HI;
-import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_LO;
-import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_MID;
-import static com.fasterxml.uuid.impl.UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.commons.codec.binary.Base64.decodeBase64;
-import static org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString;
-
-import static org.apache.usergrid.utils.ConversionUtils.bytes;
-import static org.apache.usergrid.utils.ConversionUtils.uuid;
-
-
-public class UUIDUtils {
-    private static final Logger LOG = LoggerFactory.getLogger( UUIDUtils.class );
-    private static final int[] MICROS = new int[1000];
-
-
-    static {
-        for ( int x = 0; x < 1000; x++ ) {
-            MICROS[x] = x * 10;
-        }
-    }
-
-
-    private static ReentrantLock tsLock = new ReentrantLock( true );
-
-    public static final UUID MIN_TIME_UUID = UUID.fromString( "00000000-0000-1000-8000-000000000000" );
-
-    public static final UUID MAX_TIME_UUID = UUID.fromString( "ffffffff-ffff-1fff-bfff-ffffffffffff" );
-
-    public static final UUID ZERO_UUID = new UUID( 0, 0 );
-
-    private static long timestampMillisNow = System.currentTimeMillis();
-
-    private static AtomicInteger currentMicrosPoint = new AtomicInteger( 0 );
-    private static AtomicInteger customMicrosPointer = new AtomicInteger( 0 );
-
-
-    /**
-     * Return the "next" UUID in micro second resolution. <b>WARNING</b>: this is designed to return the next unique
-     * timestamped UUID for this JVM. Depending on velocity of the call, this method may block internally to insure that
-     * "now" is kept in sync with the UUIDs being generated by this call.
-     * <p/>
-     * In other words, we will intentionally burn CPU insuring that this method is not executed more than 10k -1 times
-     * per millisecond and guarantee that those microseconds held within are sequential.
-     * <p/>
-     * If we did not do this, you would get <b>timestamp collision</b> even though the UUIDs will technically be
-     * 'unique.'
-     */
-    public static java.util.UUID newTimeUUID() {
-        // get & inc counter, but roll on 1k (because we divide by 10 on retrieval)
-        // if count + currentMicro > 1k, block and roll
-        tsLock.lock();
-        long ts = System.currentTimeMillis();
-        if ( ts > timestampMillisNow ) {
-            timestampMillisNow = ts;
-            currentMicrosPoint.set( 0 );
-        }
-        int pointer = currentMicrosPoint.getAndIncrement();
-        try {
-            if ( pointer > 990 ) {
-                TimeUnit.MILLISECONDS.sleep( 1L );
-            }
-        }
-        catch ( Exception ex ) {
-            ex.printStackTrace();
-        }
-        finally {
-            tsLock.unlock();
-        }
-        return newTimeUUID( ts, MICROS[pointer] );
-    }
-
-
-    private static final long KCLOCK_OFFSET = 0x01b21dd213814000L;
-    private static final long KCLOCK_MULTIPLIER_L = 10000L;
-
-    private static final Random CLOCK_SEQ_RANDOM = new Random();
-
-
-    // 14 bits of randomness
-    private static int getRandomClockSequence() {
-        return CLOCK_SEQ_RANDOM.nextInt() & 0x3FFF;
-    }
-
-
-    private static void setTimestamp( long timestamp, byte[] uuidBytes, int clockSeq, int timeOffset ) {
-
-        timestamp *= KCLOCK_MULTIPLIER_L;
-        timestamp += KCLOCK_OFFSET;
-        timestamp += timeOffset;
-
-        // Set random clock sequence
-        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] = ( byte ) ( clockSeq >> 8 );
-        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE + 1] = ( byte ) clockSeq;
-
-        // Set variant
-        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] &= 0x3F;
-        uuidBytes[BYTE_OFFSET_CLOCK_SEQUENCE] |= 0x80;
-        setTime( uuidBytes, timestamp );
-    }
-
-
-    @SuppressWarnings("all")
-    private static void setTime( byte[] uuidBytes, long timestamp ) {
-
-        // Time fields aren't nicely split across the UUID, so can't just
-        // linearly dump the stamp:
-        int clockHi = ( int ) ( timestamp >>> 32 );
-        int clockLo = ( int ) timestamp;
-
-        uuidBytes[BYTE_OFFSET_CLOCK_HI] = ( byte ) ( clockHi >>> 24 );
-        uuidBytes[BYTE_OFFSET_CLOCK_HI + 1] = ( byte ) ( clockHi >>> 16 );
-        uuidBytes[BYTE_OFFSET_CLOCK_MID] = ( byte ) ( clockHi >>> 8 );
-        uuidBytes[BYTE_OFFSET_CLOCK_MID + 1] = ( byte ) clockHi;
-
-        uuidBytes[BYTE_OFFSET_CLOCK_LO] = ( byte ) ( clockLo >>> 24 );
-        uuidBytes[BYTE_OFFSET_CLOCK_LO + 1] = ( byte ) ( clockLo >>> 16 );
-        uuidBytes[BYTE_OFFSET_CLOCK_LO + 2] = ( byte ) ( clockLo >>> 8 );
-        uuidBytes[BYTE_OFFSET_CLOCK_LO + 3] = ( byte ) clockLo;
-
-        // Set version
-        uuidBytes[BYTE_OFFSET_CLOCK_HI] &= 0x0F;
-        uuidBytes[BYTE_OFFSET_CLOCK_HI] |= 0x10;
-    }
-
-
-    /**
-     * Generate a timeuuid with the given timestamp in milliseconds and the time offset. Useful when you need to
-     * generate sequential UUIDs for the same period in time. I.E
-     * <p/>
-     * newTimeUUID(1000, 0) <br/> newTimeUUID(1000, 1) <br /> newTimeUUID(1000, 2) <br />
-     * <p/>
-     * etc.
-     * <p/>
-     * Only use this method if you are absolutely sure you need it. When it doubt use the method without the timestamp
-     * offset
-     *
-     * @param ts The timestamp in milliseconds
-     * @param timeoffset The offset, which should always be <= 10000. If you go beyond this range, the millisecond will
-     * be incremented since this is beyond the possible values when coverrting from millis to 1/10 microseconds stored
-     * in the time uuid.
-     */
-    public static UUID newTimeUUID( long ts, int timeoffset ) {
-        if ( ts == 0 ) {
-            return newTimeUUID();
-        }
-
-        byte[] uuidBytes = new byte[16];
-        // 47 bits of randomness
-        EthernetAddress eth = EthernetAddress.constructMulticastAddress();
-        eth.toByteArray( uuidBytes, 10 );
-        setTimestamp( ts, uuidBytes, getRandomClockSequence(), timeoffset );
-
-        return uuid( uuidBytes );
-    }
-
-
-    /**
-     * Generate a new UUID with the given time stamp in milliseconds. This method guarantees that subsequent calls will
-     * be of increasing value chronologically. If a large number of subsequent calls are made to this method (>1000)
-     * with the same timestamp, you will have non-unique temporal values stored in your UUID.
-     */
-    public static UUID newTimeUUID( long ts ) {
-        tsLock.lock();
-        int pointer = customMicrosPointer.getAndIncrement();
-        try {
-            if ( pointer > 990 ) {
-                customMicrosPointer.set( 0 );
-            }
-        }
-        finally {
-            tsLock.unlock();
-        }
-        return newTimeUUID( ts, MICROS[pointer] );
-    }
-
-
-    public static UUID minTimeUUID( long ts ) {
-        byte[] uuidBytes = new byte[16];
-        setTimestamp( ts, uuidBytes, 0, 0 );
-
-        return uuid( uuidBytes );
-    }
-
-
-    public static UUID maxTimeUUID( long ts ) {
-        byte[] uuidBytes = new byte[16];
-        uuidBytes[10] = ( byte ) 0xFF;
-        uuidBytes[11] = ( byte ) 0xFF;
-        uuidBytes[12] = ( byte ) 0xFF;
-        uuidBytes[13] = ( byte ) 0xFF;
-        uuidBytes[14] = ( byte ) 0xFF;
-        uuidBytes[15] = ( byte ) 0xFF;
-        setTimestamp( ts, uuidBytes, 0x3FFF, 0x1FFF );
-
-        return uuid( uuidBytes );
-    }
-
-
-    /** Returns the minimum UUID */
-    public static UUID min( UUID first, UUID second ) {
-        if ( first == null ) {
-            if ( second == null ) {
-                return null;
-            }
-            return second;
-        }
-
-        if ( second == null ) {
-            return first;
-        }
-
-        if ( compare( first, second ) < 0 ) {
-            return first;
-        }
-        return second;
-    }
-
-
-    /** Returns the minimum UUID */
-    public static UUID max( UUID first, UUID second ) {
-        if ( first == null ) {
-            if ( second == null ) {
-                return null;
-            }
-            return second;
-        }
-
-        if ( second == null ) {
-            return first;
-        }
-
-        if ( compare( first, second ) < 0 ) {
-            return second;
-        }
-        return first;
-    }
-
-
-    /** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */
-    public static UUID decrement( UUID uuid ) {
-        if ( !isTimeBased( uuid ) ) {
-            throw new IllegalArgumentException( "The uuid must be a time type" );
-        }
-
-
-        //timestamp is in the 60 bit timestamp
-        long timestamp = uuid.timestamp();
-        timestamp--;
-
-        if ( timestamp < 0 ) {
-            throw new IllegalArgumentException( "You must specify a time uuid with a timestamp > 0" );
-        }
-
-        //get our bytes, then set the smaller timestamp into it
-        byte[] uuidBytes = bytes( uuid );
-
-        setTime( uuidBytes, timestamp );
-
-        return uuid( uuidBytes );
-    }
-
-
-    public static boolean isTimeBased( UUID uuid ) {
-        if ( uuid == null ) {
-            return false;
-        }
-        return uuid.version() == 1;
-    }
-
-
-    public static long getTimestampInMillis( UUID uuid ) {
-        if ( uuid == null ) {
-            return 0;
-        }
-        long t = uuid.timestamp();
-        return ( t - KCLOCK_OFFSET ) / KCLOCK_MULTIPLIER_L;
-    }
-
-
-    public static long getTimestampInMicros( UUID uuid ) {
-        if ( uuid == null ) {
-            return 0;
-        }
-        long t = uuid.timestamp();
-        return ( t - KCLOCK_OFFSET ) / 10;
-    }
-
-
-    public static UUID tryGetUUID( String s ) {
-        if ( s == null ) {
-            return null;
-        }
-        if ( s.length() != 36 ) {
-            return null;
-        }
-        // 8-4-4-4-12
-        // 0-7,8,9-12,13,14-17,18,19-22,23,24-35
-        if ( s.charAt( 8 ) != '-' ) {
-            return null;
-        }
-        if ( s.charAt( 13 ) != '-' ) {
-            return null;
-        }
-        if ( s.charAt( 18 ) != '-' ) {
-            return null;
-        }
-        if ( s.charAt( 23 ) != '-' ) {
-            return null;
-        }
-        UUID uuid = null;
-        try {
-            uuid = UUID.fromString( s );
-        }
-        catch ( Exception e ) {
-            LOG.info( "Could not convert String {} into a UUID", s, e );
-        }
-        return uuid;
-    }
-
-
-    public static boolean isUUID( String s ) {
-        return tryGetUUID( s ) != null;
-    }
-
-
-    public static UUID tryExtractUUID( String s ) {
-        if ( s == null ) {
-            return null;
-        }
-        if ( s.length() < 36 ) {
-            return null;
-        }
-        return tryGetUUID( s.substring( 0, 36 ) );
-    }
-
-
-    public static UUID tryExtractUUID( String s, int offset ) {
-        if ( s == null ) {
-            return null;
-        }
-        if ( ( s.length() - offset ) < 36 ) {
-            return null;
-        }
-        return tryGetUUID( s.substring( offset, offset + 36 ) );
-    }
-
-
-    public static String toBase64( UUID id ) {
-        if ( id == null ) {
-            return null;
-        }
-        return encodeBase64URLSafeString( bytes( id ) );
-    }
-
-
-    public static UUID fromBase64( String str ) {
-        if ( str == null ) {
-            return null;
-        }
-        byte[] bytes = decodeBase64( str );
-        if ( bytes.length != 16 ) {
-            return null;
-        }
-        return uuid( bytes );
-    }
-
-
-    public static int compare( UUID u1, UUID u2 ) {
-        return UUIDComparator.staticCompare( u1, u2 );
-    }
-
-
-    public static List<UUID> sort( List<UUID> uuids ) {
-        Collections.sort( uuids, new UUIDComparator() );
-        return uuids;
-    }
-}