tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [12/22] tinkerpop git commit: status attribute for gremlin dotnet
Date Tue, 25 Sep 2018 00:08:02 GMT
status attribute for gremlin dotnet


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

Branch: refs/heads/master
Commit: fe5ae5c369d4724e2c44d74de5357bf894126b9a
Parents: 7fca7af
Author: Ashwini Singh <ashwini.mnnit@gmail.com>
Authored: Mon May 14 11:42:54 2018 -0700
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Tue Sep 18 12:58:42 2018 -0400

----------------------------------------------------------------------
 .../src/Gremlin.Net/Driver/Connection.cs        | 13 ++-
 .../src/Gremlin.Net/Driver/ResultSet.cs         | 87 ++++++++++++++++++++
 .../Driver/GremlinClientTests.cs                | 20 +++++
 3 files changed, 117 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe5ae5c3/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 279c708..3663191 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -80,6 +80,7 @@ namespace Gremlin.Net.Driver
 
         private async Task<IReadOnlyCollection<T>> ReceiveAsync<T>()
         {
+            ResultSet<T> resultSet = new ResultSet<T>();
             ResponseStatus status;
             IAggregator aggregator = null;
             var isAggregatingSideEffects = false;
@@ -114,11 +115,17 @@ namespace Gremlin.Net.Driver
                             result.Add(d);
                         }
                 }
+
+                if (status.Code == ResponseStatusCode.Success || status.Code == ResponseStatusCode.NoContent)
+                {
+                    resultSet.StatusAttributes = receivedMsg.Status.Attributes;
+                }
+
             } while (status.Code == ResponseStatusCode.PartialContent || status.Code == ResponseStatusCode.Authenticate);
 
-            if (isAggregatingSideEffects)
-                return new List<T> {(T) aggregator.GetAggregatedResult()};
-            return result;
+            resultSet.Data = isAggregatingSideEffects ? new List<T> {(T) aggregator.GetAggregatedResult()}
: result;
+                
+            return resultSet;
         }
 
         private async Task AuthenticateAsync()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe5ae5c3/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
new file mode 100644
index 0000000..1dd4d7b
--- /dev/null
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs
@@ -0,0 +1,87 @@
+#region License
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#endregion
+
+using Gremlin.Net.Driver.Exceptions;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Gremlin.Net.Driver
+{
+    /// <summary>
+    /// Ashiwni
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public sealed class ResultSet<T> : IReadOnlyCollection<T>
+    {
+        /// <summary>
+        ///  Gets and Sets the read only collection
+        /// </summary>
+        public IReadOnlyCollection<T> Data { get; set; }
+
+        /// <summary>
+        /// Gets or Sets the status attributes from the gremlin response
+        /// </summary>
+        public Dictionary<string, object> StatusAttributes { get; set; }
+
+        /// <summary>Returns an enumerator that iterates through the collection.</summary>
+        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
+        public IEnumerator<T> GetEnumerator()
+        {
+            return this.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();
+        }
+
+        /// <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;
+    }
+
+    /// <summary>
+    /// Extension for IReadOnlyCollection 
+    /// </summary>
+    public static class ResultSetExtensions
+    {
+        /// <summary>
+        /// Casts a IReadOnlyCollection to ResultSet
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="data"></param>
+        /// <returns></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/fe5ae5c3/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..a7e191f 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
@@ -29,6 +29,7 @@ using Gremlin.Net.Driver.Exceptions;
 using Gremlin.Net.Driver.Messages;
 using Gremlin.Net.IntegrationTest.Util;
 using Xunit;
+using Gremlin.Net.Structure.IO.GraphSON;
 
 namespace Gremlin.Net.IntegrationTest.Driver
 {
@@ -168,6 +169,25 @@ namespace Gremlin.Net.IntegrationTest.Driver
         }
 
         [Fact]
+        public async Task ShouldReturnResponseAttributes()
+        {
+            var gremlinServer = new GremlinServer(TestHost, TestPort);
+            using (var gremlinClient = new GremlinClient(gremlinServer))
+            {
+                var expectedResult = new List<int> { 1, 2, 3, 4, 5 };
+                var requestMsg = $"{nameof(expectedResult)}";
+                var bindings = new Dictionary<string, object> { { nameof(expectedResult),
expectedResult } };
+
+                var response = await gremlinClient.SubmitAsync<int>(requestMsg, bindings);
+
+                var resultSet = response.AsResultSet();
+
+                Assert.NotNull(resultSet.StatusAttributes);
+
+            }
+        }
+
+        [Fact]
         public async Task ShouldThrowOnExecutionOfSimpleInvalidScript()
         {
             var gremlinServer = new GremlinServer(TestHost, TestPort);


Mime
View raw message