Return-Path: X-Original-To: apmail-tinkerpop-commits-archive@minotaur.apache.org Delivered-To: apmail-tinkerpop-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EC58718634 for ; Wed, 28 Oct 2015 19:21:01 +0000 (UTC) Received: (qmail 69970 invoked by uid 500); 28 Oct 2015 19:21:01 -0000 Delivered-To: apmail-tinkerpop-commits-archive@tinkerpop.apache.org Received: (qmail 69945 invoked by uid 500); 28 Oct 2015 19:21:01 -0000 Mailing-List: contact commits-help@tinkerpop.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.incubator.apache.org Delivered-To: mailing list commits@tinkerpop.incubator.apache.org Received: (qmail 69936 invoked by uid 99); 28 Oct 2015 19:21:01 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Oct 2015 19:21:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 6ACD0C410C for ; Wed, 28 Oct 2015 19:21:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.8 X-Spam-Level: X-Spam-Status: No, score=0.8 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id s1GueLtAfb5x for ; Wed, 28 Oct 2015 19:20:46 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 2804F259A4 for ; Wed, 28 Oct 2015 19:20:30 +0000 (UTC) Received: (qmail 67925 invoked by uid 99); 28 Oct 2015 19:20:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Oct 2015 19:20:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 29DF0E176E; Wed, 28 Oct 2015 19:20:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: okram@apache.org To: commits@tinkerpop.incubator.apache.org Date: Wed, 28 Oct 2015 19:21:01 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [37/50] [abbrv] incubator-tinkerpop git commit: added tests around single channel in session and sessionless requests 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 Authored: Mon Oct 26 11:18:50 2015 +0100 Committer: Dylan Millikin 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 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 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()); + } + + }