This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 7dc8def58e0cf366792379cc4eaeb74a0a1c02fe Author: Stephen Mallette <[email protected]> AuthorDate: Thu Jul 1 14:39:36 2021 -0400 TINKERPOP-2379 Made DriverRemoteConnection init a bit more consistent across implementations They now at least can all be initialized via host/port even if some take urls and others url components. All seem to have the option to change the TraversalSource it is bound to as well. CTR --- CHANGELOG.asciidoc | 2 ++ docs/src/reference/intro.asciidoc | 16 +++++++++++++--- .../Driver/Remote/DriverRemoteConnection.cs | 22 ++++++++++++++++++++++ .../Docs/Reference/IntroTests.cs | 5 ++--- .../driver/driver_remote_connection.py | 2 +- gremlin-python/src/main/jython/tests/conftest.py | 2 +- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index bca2b82..915529c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -28,6 +28,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Changed `IndexStep` to make it easier for providers to determine the type of indexer being used. * Allowed Javascript `Translator` to take `Bytecode` or a `Traversal`. * Addressed CVE-2021-32640 for gremlin-javascript. +* Allowed construction of `DriverRemoteConnection` in .NET to use host and port specification similar to Java syntax. +* Defaulted `DriverRemoteConnection` to "g" if it the `TraversalSource` binding isn't supplied in Python. [[release-3-4-11]] === TinkerPop 3.4.11 (Release Date: May 3, 2021) diff --git a/docs/src/reference/intro.asciidoc b/docs/src/reference/intro.asciidoc index aea28e6..ba8a422 100644 --- a/docs/src/reference/intro.asciidoc +++ b/docs/src/reference/intro.asciidoc @@ -379,15 +379,25 @@ the location of the Gremlin Server to connect to: [source,java,tab] ---- +// gremlin-driver module +import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection; + +// gremlin-core module import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; -GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties"); +GraphTraversalSource g = traversal().withRemote( + DriverRemoteConnection.using("localhost", 8182)); ---- [source,groovy] ---- +// gremlin-driver module +import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection; + +// gremlin-core module import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; -def g = traversal().withRemote('conf/remote-graph.properties') +def g = traversal().withRemote( + DriverRemoteConnection.using('localhost', 8182)) ---- [source,csharp] ---- @@ -407,7 +417,7 @@ const g = traversal().withRemote( from gremlin_python.process.anonymous_traversal_source import traversal g = traversal().withRemote( - DriverRemoteConnection('ws://localhost:8182/gremlin','g')) + DriverRemoteConnection('ws://localhost:8182/gremlin')) ---- As shown in the embedded approach in the previous section, once "g" is defined, writing Gremlin is structurally and diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs index 510a2f4..023fa6e 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteConnection.cs @@ -25,6 +25,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Gremlin.Net.Driver.Messages; +using Gremlin.Net.Driver; using Gremlin.Net.Process.Remote; using Gremlin.Net.Process.Traversal; using Gremlin.Net.Process.Traversal.Strategy.Decoration; @@ -51,6 +52,27 @@ namespace Gremlin.Net.Driver.Remote /// <summary> /// Initializes a new <see cref="IRemoteConnection" /> using "g" as the default remote TraversalSource name. /// </summary> + /// <param name="host">The host to connect to.</param> + /// <param name="port">The port to connect to.</param> + /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> + public DriverRemoteConnection(string host, int port):this(host, port, "g") + { + } + + /// <summary> + /// Initializes a new <see cref="IRemoteConnection" /> using "g" as the default remote TraversalSource name. + /// </summary> + /// <param name="host">The host to connect to.</param> + /// <param name="port">The port to connect to.</param> + /// <param name="traversalSource">The name of the traversal source on the server to bind to.</param> + /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> + public DriverRemoteConnection(string host, int port, string traversalSource):this(new GremlinClient(new GremlinServer(host, port)), traversalSource) + { + } + + /// <summary> + /// Initializes a new <see cref="IRemoteConnection" /> using "g" as the default remote TraversalSource name. + /// </summary> /// <param name="client">The <see cref="IGremlinClient" /> that will be used for the connection.</param> /// <exception cref="ArgumentNullException">Thrown when client is null.</exception> public DriverRemoteConnection(IGremlinClient client):this(client, "g") diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Docs/Reference/IntroTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Docs/Reference/IntroTests.cs index 63bc576..9df167a 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Docs/Reference/IntroTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Docs/Reference/IntroTests.cs @@ -25,10 +25,10 @@ using Gremlin.Net.Driver; using Gremlin.Net.Driver.Remote; using Gremlin.Net.Process.Traversal; // tag::traversalSourceUsing[] +using Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection; using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource; // end::traversalSourceUsing[] using Xunit; -using Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection; namespace Gremlin.Net.IntegrationTest.Docs.Reference { @@ -41,8 +41,7 @@ namespace Gremlin.Net.IntegrationTest.Docs.Reference public void TraversalSourceCreationTest() { // tag::traversalSourceCreation[] -var g = Traversal().WithRemote( - new DriverRemoteConnection(new GremlinClient(new GremlinServer("localhost", 8182)))); +var g = Traversal().WithRemote(new DriverRemoteConnection("localhost", 8182)); // end::traversalSourceCreation[] } diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py index bc7b57b..df6ccd2 100644 --- a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py +++ b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py @@ -28,7 +28,7 @@ __author__ = 'David M. Brown ([email protected])' class DriverRemoteConnection(RemoteConnection): - def __init__(self, url, traversal_source, protocol_factory=None, + def __init__(self, url, traversal_source = "g", protocol_factory=None, transport_factory=None, pool_size=None, max_workers=None, username="", password="", message_serializer=None, graphson_reader=None, graphson_writer=None, diff --git a/gremlin-python/src/main/jython/tests/conftest.py b/gremlin-python/src/main/jython/tests/conftest.py index 110c63c..c2e6376 100644 --- a/gremlin-python/src/main/jython/tests/conftest.py +++ b/gremlin-python/src/main/jython/tests/conftest.py @@ -118,7 +118,7 @@ def remote_connection(request): @pytest.fixture def remote_connection_v2(request): try: - remote_conn = DriverRemoteConnection(gremlin_server_url, 'g', + remote_conn = DriverRemoteConnection(gremlin_server_url, message_serializer=serializer.GraphSONSerializersV2d0()) except OSError: pytest.skip('Gremlin Server is not running')
