usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/2] git commit: Added max version tests and impl
Date Tue, 04 Feb 2014 18:20:37 GMT
Updated Branches:
  refs/heads/two-dot-o 804e2df0e -> ef9f0f2c7


Added max version tests and impl


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

Branch: refs/heads/two-dot-o
Commit: f6b358a48c40835e4d3a434ab2e5f2ef25008849
Parents: 804e2df
Author: Todd Nine <tnine@apigee.com>
Authored: Tue Feb 4 09:43:59 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Tue Feb 4 09:59:18 2014 -0700

----------------------------------------------------------------------
 .../graph/serialization/EdgeSerialization.java  |   9 +-
 .../impl/EdgeSerializationImpl.java             |  10 +-
 .../serialization/EdgeSerializationTest.java    | 236 ++++++++++++++++++-
 3 files changed, 245 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f6b358a4/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 6c336c2..7b53985 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
@@ -57,7 +57,9 @@ public interface EdgeSerialization {
 
     /**
      * Search for specific versions of the edge from source->target. Will return all versions
-     *
+     * @param scope
+     * @param search
+     * @return
      */
     Iterator<Edge> getEdgeFromSource( OrganizationScope scope, SearchByEdge search
);
 
@@ -79,7 +81,7 @@ public interface EdgeSerialization {
     Iterator<Edge> getEdgesFromSourceByTargetType( OrganizationScope scope, SearchByIdType
edgeType );
 
     /**
-     * Get an iterator of all edges by edge type pointing to the target node
+     * Get an iterator of all edges by edge type pointing to the target node.  Returns all
versions
      *
      * @param scope The org scope of the graph
      * @param edgeType The search edge
@@ -88,6 +90,9 @@ public interface EdgeSerialization {
 
     /**
      * Search for specific versions of the edge from source->target. Will return all versions
+     * @param scope
+     * @param search
+     * @return
      */
     Iterator<Edge> getEdgeToTarget( OrganizationScope scope, SearchByEdge search );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f6b358a4/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 beb730a..03175ca 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
@@ -174,7 +174,6 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration
{
     }
 
 
-
     private void doWrite( final OrganizationScope scope, final Edge edge, final RowOp op
) {
         ValidationUtils.validateOrganizationScope( scope );
         EdgeUtils.validateEdge( edge );
@@ -218,7 +217,6 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration
{
     }
 
 
-
     @Override
     public Iterator<Edge> getEdgeFromSource( final OrganizationScope scope, final SearchByEdge
search ) {
         ValidationUtils.validateOrganizationScope( scope );
@@ -245,9 +243,9 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration
{
                 }
 
 
-                //                final DirectedEdge last = new DirectedEdge( targetId, maxVersion
);
-                //                final ByteBuffer colValue = EDGE_SERIALIZER.createSearchEdgeInclusive(
last );
-                //                builder.setEnd( colValue );
+                final DirectedEdge last = new DirectedEdge( targetId, maxVersion );
+                final ByteBuffer colValue = EDGE_SERIALIZER.createSearchEdgeInclusive( last
);
+                builder.setEnd( colValue );
             }
 
 
@@ -524,7 +522,7 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration
{
             public Edge parseColumn( final Column<DirectedEdge> column ) {
                 final DirectedEdge edge = column.getName();
 
-                return new SimpleEdge( targetId, type, edge.id, edge.version );
+                return new SimpleEdge(edge.id, type,  targetId, edge.version );
             }
         } );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f6b358a4/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 6548ab0..a15dc4d 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
@@ -26,7 +26,9 @@ 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;
@@ -38,8 +40,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith(JukitoRunner.class)
-@UseModules({ GraphModule.class })
+@RunWith( JukitoRunner.class )
+@UseModules( { GraphModule.class } )
 public class EdgeSerializationTest {
 
     @ClassRule
@@ -229,5 +231,235 @@ public class EdgeSerializationTest {
         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 );
+
+        assertEquals( edgev1, results.next() );
+        assertFalse( "Max version was honored", results.hasNext() );
+    }
+
+
+    /**
+     * 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 mixedIdTypes() throws ConnectionException {
+        final Edge edge1 = createEdge( "source", "edge", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId1 = edge1.getTargetNode();
+
+
+        final Edge edge2 = createEdge( sourceId, "edge", createId( "target2" ) );
+
+        final Id targetId2 = edge2.getTargetNode();
+
+        serialization.writeEdge( scope, edge1 ).execute();
+        serialization.writeEdge( scope, edge2 ).execute();
+
+
+        UUID now = UUIDGenerator.newTimeUUID();
+
+        //get our edges out by name
+
+        Iterator<Edge> results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null
) );
+
+        assertEquals( edge1, results.next() );
+        assertFalse( results.hasNext() );
+
+        //test getting the next edge
+        results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId2.getType(), null
) );
+
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+
+        //test getting source edges from the target
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), null
) );
+        assertEquals( edge1, results.next() );
+        assertFalse( results.hasNext() );
+
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), null
) );
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+    }
+
+
+    /**
+     * Test paging by resuming the search from the edge
+     */
+    @Test
+    public void idTypesPaging() throws ConnectionException {
+        final Edge edge1 = createEdge( "source", "edge", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId1 = edge1.getTargetNode();
+
+
+        final Edge edge2 = createEdge( sourceId, "edge", createId( "target" ) );
+
+        final Id targetId2 = edge2.getTargetNode();
+
+        serialization.writeEdge( scope, edge1 ).execute();
+        serialization.writeEdge( scope, edge2 ).execute();
+
+
+        UUID now = UUIDGenerator.newTimeUUID();
+
+        //get our edges out by name
+
+        Iterator<Edge> results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null
) );
+
+        assertEquals( edge1, results.next() );
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+
+        //test getting the next edge
+        results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge1
) );
+
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+
+        results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), edge2
) );
+
+        assertFalse( results.hasNext() );
+
+        //test getting source edges from the target
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), edge1
) );
+        assertFalse( results.hasNext() );
+
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), edge2
) );
+        assertFalse( results.hasNext() );
+    }
+
+
+    /**
+     * Test paging by resuming the search from the edge
+     */
+    @Test
+    public void delete() throws ConnectionException {
+        final Edge edge1 = createEdge( "source", "edge", "target" );
+
+        final Id sourceId = edge1.getSourceNode();
+        final Id targetId1 = edge1.getTargetNode();
+
+
+        final Edge edge2 = createEdge( sourceId, "edge", createId( "target" ) );
+
+        final Id targetId2 = edge2.getTargetNode();
+
+        serialization.writeEdge( scope, edge1 ).execute();
+        serialization.writeEdge( scope, edge2 ).execute();
+
+
+        UUID now = UUIDGenerator.newTimeUUID();
+
+        //get our edges out by name
+        Iterator<Edge> results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null
) );
+
+        assertEquals( edge1, results.next() );
+        assertEquals( edge2, 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() );
+        assertFalse( results.hasNext() );
+
+
+        //validate we get from target
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), null
) );
+
+        assertEquals( edge1, results.next() );
+        assertFalse( results.hasNext() );
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), null
) );
+
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+
+
+        //validate we get from target
+        results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId1, "edge",
now, null ) );
+
+        assertEquals( edge1, results.next() );
+        assertFalse( results.hasNext() );
+
+
+        results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId2, "edge",
now, null ) );
+
+        assertEquals( edge2, results.next() );
+        assertFalse( results.hasNext() );
+
+        //now we've validated everything exists, lets blitz the data and ensure it's removed
+
+        serialization.deleteEdge( scope, edge1 ).execute();
+        serialization.deleteEdge( scope, edge2 ).execute();
+
+
+        //now we should get nothing for the same queries
+        results = serialization.getEdgesFromSourceByTargetType( scope,
+                createSearchByEdgeAndId( sourceId, "edge", now, targetId1.getType(), null
) );
+
+        assertFalse( results.hasNext() );
+
+        //get them out by type
+        results = serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId,
"edge", now, null ) );
+
+        assertFalse( results.hasNext() );
+
+
+        //validate we get from target
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId1, "edge", now, sourceId.getType(), null
) );
+
+        assertFalse( results.hasNext() );
+
+        results = serialization.getEdgesToTargetBySourceType( scope,
+                createSearchByEdgeAndId( targetId2, "edge", now, sourceId.getType(), null
) );
+
+        assertFalse( results.hasNext() );
+
+
+        //validate we get from target
+        results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId1, "edge",
now, null ) );
+
+        assertFalse( results.hasNext() );
+
+
+        results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId2, "edge",
now, null ) );
+
+        assertFalse( results.hasNext() );
     }
 }


Mime
View raw message