tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From florianhockm...@apache.org
Subject [1/8] tinkerpop git commit: Expose WebSocket configuration TINKERPOP-2015
Date Wed, 03 Oct 2018 10:33:43 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/master 7ac00a13b -> 21d2444c6
  refs/heads/tp32 76c9aba94 -> fcbce509f
  refs/heads/tp33 650f31f1b -> 1faf7629c


Expose WebSocket configuration TINKERPOP-2015

Users can now provide a delegate to the Gremlin.Net driver that will be
used to configure WebSocket connections.


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

Branch: refs/heads/master
Commit: b440742393135fdd88d4af18b09ade5f5011133e
Parents: e7af98b
Author: Florian Hockmann <fh@florian-hockmann.de>
Authored: Sun Sep 9 14:49:03 2018 +0200
Committer: Florian Hockmann <fh@florian-hockmann.de>
Committed: Wed Oct 3 12:08:14 2018 +0200

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../src/Gremlin.Net/Driver/Connection.cs        |  6 +++--
 .../src/Gremlin.Net/Driver/ConnectionFactory.cs |  8 +++++--
 .../src/Gremlin.Net/Driver/GremlinClient.cs     |  9 +++++--
 .../Gremlin.Net/Driver/WebSocketConnection.cs   |  9 +++++--
 .../Driver/GremlinClientTests.cs                | 25 ++++++++++++++++++++
 6 files changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e93c1c9..36a34f2 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 * Removed conflicting non-indy groovy core dependency
 * Bumped jython-standalone 2.7.1
+* Added a delegate to the Gremlin.Net driver that can be used to configure the WebSocket
connection.
 * SSL security enhancements
 * Added Gremlin version to Gremlin Server startup logging output.
 * Fixed problem with Gremlin Server sometimes returning an additional message after a failure.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index dbbd375..f63e20b 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -23,6 +23,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Net.WebSockets;
 using System.Text;
 using System.Threading.Tasks;
 using Gremlin.Net.Driver.Messages;
@@ -38,18 +39,19 @@ namespace Gremlin.Net.Driver
         private readonly GraphSONWriter _graphSONWriter;
         private readonly JsonMessageSerializer _messageSerializer = new JsonMessageSerializer();
         private readonly Uri _uri;
-        private readonly WebSocketConnection _webSocketConnection = new WebSocketConnection();
+        private readonly WebSocketConnection _webSocketConnection;
         private readonly string _username;
         private readonly string _password;
 
         public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
-            GraphSONWriter graphSONWriter)
+            GraphSONWriter graphSONWriter, Action<ClientWebSocketOptions> webSocketConfiguration)
         {
             _uri = uri;
             _username = username;
             _password = password;
             _graphSONReader = graphSONReader;
             _graphSONWriter = graphSONWriter;
+            _webSocketConnection = new WebSocketConnection(webSocketConfiguration);
         }
 
         public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage
requestMessage)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
index 0041a67..8b14ed9 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
@@ -21,6 +21,8 @@
 
 #endregion
 
+using System;
+using System.Net.WebSockets;
 using Gremlin.Net.Structure.IO.GraphSON;
 
 namespace Gremlin.Net.Driver
@@ -29,20 +31,22 @@ namespace Gremlin.Net.Driver
     {
         private readonly GraphSONReader _graphSONReader;
         private readonly GraphSONWriter _graphSONWriter;
+        private readonly Action<ClientWebSocketOptions> _webSocketConfiguration;
         private readonly GremlinServer _gremlinServer;
 
         public ConnectionFactory(GremlinServer gremlinServer, GraphSONReader graphSONReader,
-            GraphSONWriter graphSONWriter)
+            GraphSONWriter graphSONWriter, Action<ClientWebSocketOptions> webSocketConfiguration)
         {
             _gremlinServer = gremlinServer;
             _graphSONReader = graphSONReader;
             _graphSONWriter = graphSONWriter;
+            _webSocketConfiguration = webSocketConfiguration;
         }
 
         public Connection CreateConnection()
         {
             return new Connection(_gremlinServer.Uri, _gremlinServer.Username, _gremlinServer.Password,
_graphSONReader,
-                _graphSONWriter);
+                _graphSONWriter, _webSocketConfiguration);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
index 46dd8a6..a5cb46c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
@@ -23,6 +23,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Net.WebSockets;
 using System.Threading.Tasks;
 using Gremlin.Net.Driver.Messages;
 using Gremlin.Net.Structure.IO.GraphSON;
@@ -42,12 +43,16 @@ namespace Gremlin.Net.Driver
         /// <param name="gremlinServer">The <see cref="GremlinServer" /> the
requests should be sent to.</param>
         /// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance
to read received GraphSON data.</param>
         /// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance
to write GraphSON data.</param>
+        /// <param name="webSocketConfiguration">
+        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions"
/>
+        ///     object used to configure WebSocket connections.
+        /// </param>
         public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader =
null,
-            GraphSONWriter graphSONWriter = null)
+            GraphSONWriter graphSONWriter = null, Action<ClientWebSocketOptions> webSocketConfiguration
= null)
         {
             var reader = graphSONReader ?? new GraphSONReader();
             var writer = graphSONWriter ?? new GraphSONWriter();
-            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer);
+            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer,
webSocketConfiguration);
             _connectionPool = new ConnectionPool(connectionFactory);
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
index b5a4cc8..aefa32a 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
@@ -33,11 +33,16 @@ namespace Gremlin.Net.Driver
     {
         private const int ReceiveBufferSize = 1024;
         private const WebSocketMessageType MessageType = WebSocketMessageType.Binary;
-        private ClientWebSocket _client;
+        private readonly ClientWebSocket _client;
 
-        public async Task ConnectAsync(Uri uri)
+        public WebSocketConnection(Action<ClientWebSocketOptions> webSocketConfiguration)
         {
             _client = new ClientWebSocket();
+            webSocketConfiguration?.Invoke(_client.Options);
+        }
+
+        public async Task ConnectAsync(Uri uri)
+        {
             await _client.ConnectAsync(uri, CancellationToken.None).ConfigureAwait(false);
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
index 351b83d..9a421d5 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
@@ -23,6 +23,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Net.WebSockets;
 using System.Threading.Tasks;
 using Gremlin.Net.Driver;
 using Gremlin.Net.Driver.Exceptions;
@@ -208,5 +209,29 @@ namespace Gremlin.Net.IntegrationTest.Driver
                 Assert.Equal(a + b, response);
             }
         }
+
+        [Fact]
+        public async Task ShouldConfigureWebSocketOptionsAsSpecified()
+        {
+            var gremlinServer = new GremlinServer(TestHost, TestPort);
+            ClientWebSocketOptions optionsSet = null;
+            var expectedKeepAliveInterval = TimeSpan.FromMilliseconds(11);
+            var webSocketConfiguration =
+                new Action<ClientWebSocketOptions>(options =>
+                {
+                    options.UseDefaultCredentials = false;
+                    options.KeepAliveInterval = expectedKeepAliveInterval;
+                    optionsSet = options;
+                });
+            using (var gremlinClient = new GremlinClient(gremlinServer, webSocketConfiguration:
webSocketConfiguration))
+            {
+                // send dummy message to create at least one connection
+                await gremlinClient.SubmitAsync(_requestMessageProvider.GetDummyMessage());
+                
+                Assert.NotNull(optionsSet);
+                Assert.False(optionsSet.UseDefaultCredentials);
+                Assert.Equal(expectedKeepAliveInterval, optionsSet.KeepAliveInterval);
+            }
+        }
     }
 }
\ No newline at end of file


Mime
View raw message