You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/09/18 16:27:42 UTC

[4/8] tinkerpop git commit: Exposes ResultSet on GremlinClient. Adds StatusAttributes property on ResponseException. Removed explicit this from ResultSet to align with existing style.

Exposes ResultSet<T> on GremlinClient.
Adds StatusAttributes property on ResponseException.
Removed explicit this from ResultSet<T> to align with existing style.


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

Branch: refs/heads/TINKERPOP-1913
Commit: 8e456068e7670fbdca057ced72baff7e02e9c255
Parents: 7d50798
Author: Patrik Husfloen <re...@redoz.com>
Authored: Wed Sep 5 23:40:57 2018 +0200
Committer: Patrik Husfloen <re...@redoz.com>
Committed: Thu Sep 13 22:33:42 2018 +0200

----------------------------------------------------------------------
 .../src/Gremlin.Net/Driver/Connection.cs        |  2 +-
 .../Driver/Exceptions/ResponseException.cs      | 10 ++++-
 .../src/Gremlin.Net/Driver/GremlinClient.cs     |  2 +-
 .../src/Gremlin.Net/Driver/IConnection.cs       |  2 +-
 .../src/Gremlin.Net/Driver/IGremlinClient.cs    |  4 +-
 .../Driver/Messages/ResponseStatus.cs           |  2 +-
 .../src/Gremlin.Net/Driver/ProxyConnection.cs   |  2 +-
 .../src/Gremlin.Net/Driver/ResultSet.cs         | 41 ++++----------------
 .../Driver/GremlinClientTests.cs                |  3 +-
 9 files changed, 24 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/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 5b4be20..822fc65 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -53,7 +53,7 @@ namespace Gremlin.Net.Driver
             _messageSerializer = new JsonMessageSerializer(mimeType);
         }
 
-        public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage)
+        public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage)
         {
             await SendAsync(requestMessage).ConfigureAwait(false);
             return await ReceiveAsync<T>().ConfigureAwait(false);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/Exceptions/ResponseException.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Exceptions/ResponseException.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Exceptions/ResponseException.cs
index 8d26106..3c0d927 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Exceptions/ResponseException.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Exceptions/ResponseException.cs
@@ -22,6 +22,7 @@
 #endregion
 
 using System;
+using System.Collections.Generic;
 
 namespace Gremlin.Net.Driver.Exceptions
 {
@@ -33,9 +34,16 @@ namespace Gremlin.Net.Driver.Exceptions
         /// <summary>
         ///     Initializes a new instance of the <see cref="ResponseException" /> class.
         /// </summary>
+        /// <param name="statusAttributes">The status attributes as returned by the server.</param>
         /// <param name="message">The error message string.</param>
-        public ResponseException(string message) : base(message)
+        public ResponseException(IReadOnlyDictionary<string, object> statusAttributes, string message) : base(message)
         {
+            StatusAttributes = statusAttributes;
         }
+
+        /// <summary>
+        /// Gets or sets the status attributes from the gremlin response
+        /// </summary>
+        public IReadOnlyDictionary<string, object> StatusAttributes { get; }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/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 2b47cbc..b933b37 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
@@ -68,7 +68,7 @@ namespace Gremlin.Net.Driver
         public int NrConnections => _connectionPool.NrConnections;
 
         /// <inheritdoc />
-        public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage)
+        public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage)
         {
             using (var connection = await _connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))
             {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/IConnection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/IConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/IConnection.cs
index e1651a6..b5ef52c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/IConnection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/IConnection.cs
@@ -30,6 +30,6 @@ namespace Gremlin.Net.Driver
 {
     internal interface IConnection : IDisposable
     {
-        Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage);
+        Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/IGremlinClient.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/IGremlinClient.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/IGremlinClient.cs
index 7a7048a..9bef4be 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/IGremlinClient.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/IGremlinClient.cs
@@ -38,11 +38,11 @@ namespace Gremlin.Net.Driver
         /// </summary>
         /// <typeparam name="T">The type of the expected results.</typeparam>
         /// <param name="requestMessage">The <see cref="RequestMessage" /> to send.</param>
-        /// <returns>A collection of the data returned from the server.</returns>
+        /// <returns>A <see cref="ResultSet{T}"/> containing the data and status attributes returned from the server.</returns>
         /// <exception cref="Exceptions.ResponseException">
         ///     Thrown when a response is received from Gremlin Server that indicates
         ///     that an error occurred.
         /// </exception>
-        Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage);
+        Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/Messages/ResponseStatus.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Messages/ResponseStatus.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Messages/ResponseStatus.cs
index e3c1797..c436662 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Messages/ResponseStatus.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Messages/ResponseStatus.cs
@@ -44,7 +44,7 @@ namespace Gremlin.Net.Driver.Messages
         public static void ThrowIfStatusIndicatesError(this ResponseStatus status)
         {
             if (status.Code.IndicatesError())
-                throw new ResponseException($"{status.Code}: {status.Message}");
+                throw new ResponseException(status.Attributes, $"{status.Code}: {status.Message}");
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/ProxyConnection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ProxyConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/ProxyConnection.cs
index cbe15ec..fef6ede 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ProxyConnection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ProxyConnection.cs
@@ -39,7 +39,7 @@ namespace Gremlin.Net.Driver
             _releaseAction = releaseAction;
         }
 
-        public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage)
+        public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage)
         {
             return await _realConnection.SubmitAsync<T>(requestMessage).ConfigureAwait(false);
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs
index 5d4a145..00a24d3 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs
@@ -21,7 +21,6 @@
 
 #endregion
 
-using Gremlin.Net.Driver.Exceptions;
 using System.Collections;
 using System.Collections.Generic;
 
@@ -34,24 +33,21 @@ namespace Gremlin.Net.Driver
     /// <typeparam name="T">Type of the result elements</typeparam>
     public sealed class ResultSet<T> : IReadOnlyCollection<T>
     {
-        /// <summary>
-        ///  Gets or sets the data from the response
-        /// </summary>
-        public IReadOnlyCollection<T> Data { get; }
+        private readonly IReadOnlyCollection<T> _data;
 
         /// <summary>
         /// Gets or sets the status attributes from the gremlin response
         /// </summary>
-        public Dictionary<string, object> StatusAttributes { get; }
+        public IReadOnlyDictionary<string, object> StatusAttributes { get; }
 
         /// <summary>
         /// Initializes a new instance of the ResultSet class for the specified data and status attributes.
         /// </summary>
         /// <param name="data"></param>
         /// <param name="attributes"></param>
-        public ResultSet(IReadOnlyCollection<T> data, Dictionary<string, object> attributes)
+        public ResultSet(IReadOnlyCollection<T> data, IReadOnlyDictionary<string, object> attributes)
         {
-            this.Data = data;
+            _data = data;
             this.StatusAttributes = attributes;
         }
 
@@ -59,41 +55,18 @@ namespace Gremlin.Net.Driver
         /// <returns>An enumerator that can be used to iterate through the collection.</returns>
         public IEnumerator<T> GetEnumerator()
         {
-            return this.Data.GetEnumerator();
+            return _data.GetEnumerator();
         }
 
         /// <summary>Returns an enumerator that iterates through a collection.</summary>
         /// <returns>An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.</returns>
         IEnumerator IEnumerable.GetEnumerator()
         {
-            return this.GetEnumerator();
+            return _data.GetEnumerator();
         }
 
         /// <summary>Gets the number of elements in the collection.</summary>
         /// <returns>The number of elements in the collection. </returns>
-        public int Count => this.Data.Count;
+        public int Count => _data.Count;
     }
-
-    /// <summary>
-    /// Extension for IReadOnlyCollection 
-    /// </summary>
-    public static class ResultSetExtensions
-    {
-        /// <summary>
-        /// Casts a IReadOnlyCollection to ResultSet
-        /// </summary>
-        /// <typeparam name="T">Type of the result elements</typeparam>
-        /// <param name="data"> result data</param>
-        /// <returns>IReadOnlyCollection as ResultSet</returns>
-        public static ResultSet<T> AsResultSet<T>(this IReadOnlyCollection<T> data)
-        {
-            if (!(data is ResultSet<T> resultSet))
-            {
-                throw new ResponseException($"IReadOnlyCollection is not of type ResultSet");
-            }
-
-            return resultSet;
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e456068/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 bcb76e7..6470924 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
@@ -177,9 +177,8 @@ namespace Gremlin.Net.IntegrationTest.Driver
             using (var gremlinClient = new GremlinClient(gremlinServer))
             {
                 var requestMsg = _requestMessageProvider.GetDummyMessage();
-                var response = await gremlinClient.SubmitAsync<int>(requestMsg);
+                var resultSet = await gremlinClient.SubmitAsync<int>(requestMsg);
 
-                var resultSet = response.AsResultSet();
                 Assert.NotNull(resultSet.StatusAttributes);
 
                 var values= resultSet.StatusAttributes["@value"] as JArray;