tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [37/50] [abbrv] incubator-tinkerpop git commit: added tests around single channel in session and sessionless requests
Date Wed, 28 Oct 2015 19:21:01 GMT
added tests around single channel in session and sessionless requests


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

Branch: refs/heads/TINKERPOP3-857
Commit: 0b573712c58c3f115a19b4c7542add3d7bbeb8fe
Parents: 43f64c2
Author: Dylan Millikin <dylan.millikin@brightzone.fr>
Authored: Mon Oct 26 11:18:50 2015 +0100
Committer: Dylan Millikin <dylan.millikin@brightzone.fr>
Committed: Mon Oct 26 13:48:12 2015 +0100

----------------------------------------------------------------------
 .../server/GremlinDriverIntegrateTest.java      |  28 ++++++
 .../server/GremlinServerIntegrateTest.java      | 100 +++++++++++++++++++
 2 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0b573712/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index 575f96e..3e0f821 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -99,6 +99,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
             case "shouldExecuteScriptInSessionOnTransactionalGraph":
             case "shouldExecuteSessionlessScriptOnTransactionalGraph":
             case "shouldExecuteScriptInSessionOnTransactionalWithManualTransactionsGraph":
+            case "shouldExecuteInSessionAndSessionlessWithoutOpeningTransaction":
                 deleteDirectory(new File("/tmp/neo4j"));
                 settings.graphs.put("graph", "conf/neo4j-empty.properties");
                 break;
@@ -616,6 +617,33 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
     }
 
     @Test
+    public void shouldExecuteInSessionAndSessionlessWithoutOpeningTransaction() throws Exception
{
+        assumeNeo4jIsPresent();
+        
+        final Cluster cluster = Cluster.build().create();
+        final Client sessionClient = cluster.connect(name.getMethodName());
+        final Client sessionlessClient = cluster.connect();
+        
+        //open transaction in session, then add vertex and commit
+        sessionClient.submit("graph.tx().open()").all().get();
+        final Vertex vertexBeforeTx = sessionClient.submit("v=graph.addVertex(\"name\",\"stephen\")").all().get().get(0).getVertex();
+        assertEquals("stephen", vertexBeforeTx.values("name").next());
+        sessionClient.submit("graph.tx().commit()").all().get();
+        
+        // check that session transaction is closed
+        final boolean isOpen = sessionClient.submit("graph.tx().isOpen()").all().get().get(0).getBoolean();
+        assertTrue("Transaction should be closed", !isOpen);
+        
+        //run a sessionless read
+        sessionlessClient.submit("graph.traversal().V()").all().get();
+        
+        // check that session transaction is still closed
+        final boolean isOpenAfterSessionless = sessionClient.submit("graph.tx().isOpen()").all().get().get(0).getBoolean();
+        assertTrue("Transaction should stil be closed", !isOpenAfterSessionless);
+        
+    }
+
+    @Test
     public void shouldExecuteSessionlessScriptOnTransactionalGraph() throws Exception {
         assumeNeo4jIsPresent();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0b573712/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index 2e65a56..77dccd5 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.server;
 
+import java.io.File;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.log4j.Logger;
 import org.apache.tinkerpop.gremlin.driver.Client;
@@ -41,6 +42,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.nio.channels.ClosedChannelException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
@@ -119,6 +121,10 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
                 processorSettings.config.put(SessionOpProcessor.CONFIG_SESSION_TIMEOUT, 3000l);
                 settings.processors.add(processorSettings);
                 break;
+            case "shouldExecuteInSessionAndSessionlessWithoutOpeningTransactionWithSingleClient":
+                deleteDirectory(new File("/tmp/neo4j"));
+                settings.graphs.put("graph", "conf/neo4j-empty.properties");
+                break;
         }
 
         return settings;
@@ -562,4 +568,98 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
             cluster.close();
         }
     }
+    
+    @Test
+    public void shouldExecuteInSessionAndSessionlessWithoutOpeningTransactionWithSingleClient()
throws Exception {
+        assumeNeo4jIsPresent();
+        
+        final SimpleClient client = new WebSocketClient();
+        
+        //open a transaction, create a vertex, commit
+        final CountDownLatch latch = new CountDownLatch(1);
+        final RequestMessage OpenRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .processor("session")
+                .addArg(Tokens.ARGS_SESSION, name.getMethodName())
+                .addArg(Tokens.ARGS_GREMLIN, "graph.tx().open()")
+                .create();
+        client.submit(OpenRequest, (r) -> {
+            latch.countDown();
+        });
+        assertTrue(latch.await(1500, TimeUnit.MILLISECONDS));
+        
+        final CountDownLatch latch2 = new CountDownLatch(1);
+        final RequestMessage AddRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .processor("session")
+                .addArg(Tokens.ARGS_SESSION, name.getMethodName())
+                .addArg(Tokens.ARGS_GREMLIN, "v=graph.addVertex(\"name\",\"stephen\")")
+                .create();
+        client.submit(AddRequest, (r) -> {
+            latch2.countDown();
+        });
+        assertTrue(latch2.await(1500, TimeUnit.MILLISECONDS));
+        
+        final CountDownLatch latch3 = new CountDownLatch(1);
+        final RequestMessage CommitRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .processor("session")
+                .addArg(Tokens.ARGS_SESSION, name.getMethodName())
+                .addArg(Tokens.ARGS_GREMLIN, "graph.tx().commit()")
+                .create();
+        client.submit(CommitRequest, (r) -> {
+            latch3.countDown();
+            
+        });
+        latch3.await(1500, TimeUnit.MILLISECONDS);
+        
+        // Check to see if the transaction is closed.
+        final CountDownLatch latch4 = new CountDownLatch(1);
+        final AtomicBoolean isOpen = new AtomicBoolean(false);
+        final RequestMessage CheckRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .processor("session")
+                .addArg(Tokens.ARGS_SESSION, name.getMethodName())
+                .addArg(Tokens.ARGS_GREMLIN, "graph.tx().isOpen()")
+                .create();
+        client.submit(CheckRequest, (r) -> {
+            ArrayList<Boolean> response = (ArrayList) r.getResult().getData();
+            isOpen.set(response.get(0));
+            latch4.countDown();
+        });
+        assertTrue(latch4.await(1500, TimeUnit.MILLISECONDS));
+        
+        // make sure no extra message sneak in
+        Thread.sleep(1000);
+        
+        assertTrue("Transaction should be closed", !isOpen.get());
+        
+        //lets run a sessionless read
+        final CountDownLatch latch5 = new CountDownLatch(1);
+        final RequestMessage sessionlessRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .addArg(Tokens.ARGS_GREMLIN, "graph.traversal().V()")
+                .create();
+        client.submit(sessionlessRequest, (r) -> {
+            latch5.countDown();
+        });
+        assertTrue(latch5.await(1500, TimeUnit.MILLISECONDS));
+        
+        // Check to see if the transaction is still closed.
+        final CountDownLatch latch6 = new CountDownLatch(1);
+        final AtomicBoolean isStillOpen = new AtomicBoolean(false);
+        final RequestMessage CheckAgainRequest = RequestMessage.build(Tokens.OPS_EVAL)
+                .processor("session")
+                .addArg(Tokens.ARGS_SESSION, name.getMethodName())
+                .addArg(Tokens.ARGS_GREMLIN, "graph.tx().isOpen()")
+                .create();
+        client.submit(CheckAgainRequest, (r) -> {
+            ArrayList<Boolean> response = (ArrayList) r.getResult().getData();
+            isStillOpen.set(response.get(0));
+            latch6.countDown();
+        });
+        assertTrue(latch6.await(1500, TimeUnit.MILLISECONDS));
+        
+        // make sure no extra message sneak in
+        Thread.sleep(1000);
+        
+        assertTrue("Transaction should still be closed", !isStillOpen.get());
+    }
+ 
+    
 }


Mime
View raw message