Repository: tinkerpop
Updated Branches:
  refs/heads/master 9fd97b455 -> 75502eef2


Unwrap AggregateException for sync io operations


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

Branch: refs/heads/master
Commit: a655e2649ab9a6ba1885dde317d81e845a7507b8
Parents: 51caf77
Author: Jorge Bay Gondra <jorgebaygon...@gmail.com>
Authored: Wed Aug 9 11:46:28 2017 +0200
Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com>
Committed: Wed Aug 9 11:56:22 2017 +0200

----------------------------------------------------------------------
 .../src/Gremlin.Net/Driver/ConnectionPool.cs    |  3 +-
 .../Remote/DriverRemoteTraversalSideEffects.cs  |  3 +-
 .../Process/Remote/RemoteStrategy.cs            |  3 +-
 .../src/Gremlin.Net/Structure/Utils.cs          | 55 ++++++++++++++++++++
 .../Process/Remote/RemoteStrategyTests.cs       | 12 +++++
 5 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a655e264/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs 
b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
index e9ce9a8..98cb547 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
@@ -26,6 +26,7 @@ using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using Gremlin.Net.Structure;
 
 namespace Gremlin.Net.Driver
 {
@@ -92,7 +93,7 @@ namespace Gremlin.Net.Driver
                     {
                         if (_connections != null && !_connections.IsEmpty)
                         {
-                            TeardownAsync().Wait();
+                            TeardownAsync().WaitUnwrap();
 
                             foreach (var conn in _connections)
                                 conn.Dispose();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a655e264/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteTraversalSideEffects.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteTraversalSideEffects.cs
 
b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteTraversalSideEffects.cs
index 8ce495d..e8df942 100644
--- 
a/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteTraversalSideEffects.cs
+++ 
b/gremlin-dotnet/src/Gremlin.Net/Driver/Remote/DriverRemoteTraversalSideEffects.cs
@@ -26,6 +26,7 @@ using System.Collections.Generic;
 using System.Linq;
 using Gremlin.Net.Driver.Messages;
 using Gremlin.Net.Process.Traversal;
+using Gremlin.Net.Structure;
 
 namespace Gremlin.Net.Driver.Remote
 {
@@ -112,7 +113,7 @@ namespace Gremlin.Net.Driver.Remote
 
         private void CloseSideEffects()
         {
-            
_gremlinClient.SubmitAsync<object>(SideEffectCloseMessage()).Wait();
+            
_gremlinClient.SubmitAsync<object>(SideEffectCloseMessage()).WaitUnwrap();
         }
 
         private RequestMessage SideEffectCloseMessage()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a655e264/gremlin-dotnet/src/Gremlin.Net/Process/Remote/RemoteStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Remote/RemoteStrategy.cs 
b/gremlin-dotnet/src/Gremlin.Net/Process/Remote/RemoteStrategy.cs
index b3f8c44..b914063 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Remote/RemoteStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Remote/RemoteStrategy.cs
@@ -23,6 +23,7 @@
 
 using System.Threading.Tasks;
 using Gremlin.Net.Process.Traversal;
+using Gremlin.Net.Structure;
 
 namespace Gremlin.Net.Process.Remote
 {
@@ -46,7 +47,7 @@ namespace Gremlin.Net.Process.Remote
         /// <inheritdoc />
         public void Apply<S, E>(ITraversal<S, E> traversal)
         {
-            ApplyAsync(traversal).Wait();
+            ApplyAsync(traversal).WaitUnwrap();
         }
 
         /// <inheritdoc />

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a655e264/gremlin-dotnet/src/Gremlin.Net/Structure/Utils.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/Utils.cs 
b/gremlin-dotnet/src/Gremlin.Net/Structure/Utils.cs
new file mode 100644
index 0000000..08168ba
--- /dev/null
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/Utils.cs
@@ -0,0 +1,55 @@
+#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 System;
+using System.Runtime.ExceptionServices;
+using System.Threading.Tasks;
+
+namespace Gremlin.Net.Structure
+{
+    /// <summary>
+    /// Contains useful methods that can be reused across the project. 
+    /// </summary>
+    internal static class Utils
+    {
+        /// <summary>
+        /// Waits the completion of the provided Task.
+        /// When an AggregateException is thrown, the inner exception is 
thrown.
+        /// </summary>
+        public static void WaitUnwrap(this Task task)
+        {
+            try
+            {
+                task.Wait();
+            }
+            catch (AggregateException ex)
+            {
+                if (ex.InnerExceptions.Count == 1)
+                {
+                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();  
 
+                }
+                throw;
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a655e264/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
index 7b99371..5c24346 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
@@ -24,6 +24,7 @@
 using System;
 using System.Threading.Tasks;
 using Gremlin.Net.Driver;
+using Gremlin.Net.Driver.Exceptions;
 using Gremlin.Net.Driver.Remote;
 using Gremlin.Net.Process.Remote;
 using Gremlin.Net.Process.Traversal;
@@ -50,6 +51,17 @@ namespace Gremlin.Net.IntegrationTest.Process.Remote
 
             Assert.Equal(expectedResult, actualResult);
         }
+        
+        [Fact]
+        public void ShouldThrowOriginalExceptionWhenByteCodeIsInvalid()
+        {
+            var testBytecode = new Bytecode();
+            testBytecode.AddStep("V");
+            testBytecode.AddStep("this_step_does_not_exist", "test");
+            var testTraversal = 
CreateTraversalWithRemoteStrategy(testBytecode);
+
+            Assert.Throws<ResponseException>(() => testTraversal.Next());
+        }
 
         [Fact]
         public async Task 
ShouldSendBytecodeToGremlinServerAsynchronouslyForTraversalPromise()

Reply via email to