Made the console support managed transactions for :remote This was a small oversight from the original implementation of managed session transactions. CTR
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/23956b22 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/23956b22 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/23956b22 Branch: refs/heads/TINKERPOP-1331 Commit: 23956b2231c79de4b041a030fec11b3f76cd0322 Parents: f30a84a Author: Stephen Mallette <sp...@genoprime.com> Authored: Thu Jun 9 11:30:32 2016 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Thu Jun 9 11:30:32 2016 -0400 ---------------------------------------------------------------------- docs/src/reference/gremlin-applications.asciidoc | 5 ++++- .../gremlin/console/groovy/plugin/DriverRemoteAcceptor.java | 8 ++++++-- .../groovy/plugin/DriverRemoteAcceptorIntegrateTest.java | 8 ++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/23956b22/docs/src/reference/gremlin-applications.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc index 72a5515..0cb875e 100644 --- a/docs/src/reference/gremlin-applications.asciidoc +++ b/docs/src/reference/gremlin-applications.asciidoc @@ -513,7 +513,10 @@ To enable the remote to connect with a session the `connect` argument takes anot ---- With the above command a session gets created with a random UUID for a session identifier. It is also possible to -assign a custom session identifier by adding it as the last argument to `:remote` command above. +assign a custom session identifier by adding it as the last argument to `:remote` command above. There is also the +option to replace "session" with "session-managed" to create a session that will auto-manage transactions (i.e. each +request will occur within the bounds of a transaction). In this way, the state of bound variables between requests are +maintained, but the need to manually managed the transactional scope of the graph is no longer required. [[console-remote-console]] Remote Console http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/23956b22/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptor.java ---------------------------------------------------------------------- diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptor.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptor.java index e60b325..c346540 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptor.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptor.java @@ -72,6 +72,7 @@ public class DriverRemoteAcceptor implements RemoteAcceptor { private static final String TOKEN_TIMEOUT = "timeout"; private static final String TOKEN_ALIAS = "alias"; private static final String TOKEN_SESSION = "session"; + private static final String TOKEN_SESSION_MANAGED = "session-managed"; private static final List<String> POSSIBLE_TOKENS = Arrays.asList(TOKEN_TIMEOUT, TOKEN_ALIAS); private final Groovysh shell; @@ -86,11 +87,14 @@ public class DriverRemoteAcceptor implements RemoteAcceptor { try { this.currentCluster = Cluster.open(args.get(0)); - final boolean useSession = args.size() >= 2 && args.get(1).equals(TOKEN_SESSION); + final boolean useSession = args.size() >= 2 && (args.get(1).equals(TOKEN_SESSION) || args.get(1).equals(TOKEN_SESSION_MANAGED)); if (useSession) { final String sessionName = args.size() == 3 ? args.get(2) : UUID.randomUUID().toString(); session = Optional.of(sessionName); - this.currentClient = this.currentCluster.connect(sessionName); + + final boolean managed = args.get(1).equals(TOKEN_SESSION_MANAGED); + + this.currentClient = this.currentCluster.connect(sessionName, managed); } else { this.currentClient = this.currentCluster.connect(); } http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/23956b22/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptorIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptorIntegrateTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptorIntegrateTest.java index f4d4b5d..1363c26 100644 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptorIntegrateTest.java +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/plugin/DriverRemoteAcceptorIntegrateTest.java @@ -93,6 +93,14 @@ public class DriverRemoteAcceptorIntegrateTest extends AbstractGremlinServerInte } @Test + public void shouldConnectAndSubmitManagedSession() throws Exception { + assertThat(acceptor.connect(Arrays.asList(TestHelper.generateTempFileFromResource(this.getClass(), "remote.yaml", ".tmp").getAbsolutePath(), "session-managed")).toString(), startsWith("Configured ")); + assertEquals("1", ((Iterator) acceptor.submit(Collections.singletonList("x = 1"))).next()); + assertEquals("0", ((Iterator) acceptor.submit(Collections.singletonList("x - 1"))).next()); + assertEquals("0", ((List<Result>) groovysh.getInterp().getContext().getProperty(DriverRemoteAcceptor.RESULT)).iterator().next().getString()); + } + + @Test public void shouldConnectAndSubmitSimple() throws Exception { assertThat(acceptor.connect(Collections.singletonList(TestHelper.generateTempFileFromResource(this.getClass(), "remote.yaml", ".tmp").getAbsolutePath())).toString(), startsWith("Configured ")); assertEquals("2", ((Iterator) acceptor.submit(Collections.singletonList("1+1"))).next());