avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1561874 - in /avro/trunk: ./ lang/csharp/src/apache/ipc/ lang/csharp/src/apache/ipc/Specific/ lang/csharp/src/apache/main/Protocol/ lang/csharp/src/apache/test/Ipc/
Date Mon, 27 Jan 2014 22:05:54 GMT
Author: cutting
Date: Mon Jan 27 22:05:53 2014
New Revision: 1561874

URL: http://svn.apache.org/r1561874
Log:
AVRO-1446. C#: Correctly handle system errors in RPC.  Contributed by David Taylor.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/csharp/src/apache/ipc/Responder.cs
    avro/trunk/lang/csharp/src/apache/ipc/Specific/SpecificRequestor.cs
    avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs
    avro/trunk/lang/csharp/src/apache/test/Ipc/SocketServerWithCallbacksTest.cs

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1561874&r1=1561873&r2=1561874&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Jan 27 22:05:53 2014
@@ -10,6 +10,9 @@ Trunk (not yet released)
 
   BUG FIXES
 
+    AVRO-1446. C#: Correctly handle system errors in RPC.
+    (David Taylor via cutting)
+
 Avro 1.7.6 (15 January 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/csharp/src/apache/ipc/Responder.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/ipc/Responder.cs?rev=1561874&r1=1561873&r2=1561874&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/ipc/Responder.cs (original)
+++ avro/trunk/lang/csharp/src/apache/ipc/Responder.cs Mon Jan 27 22:05:53 2014
@@ -181,7 +181,15 @@ namespace Avro.ipc
                     WriteResponse(m.Response, response, output);
                 else
                 {
-                    WriteError(m.Error, error, output);
+                    try 
+                    {
+                        WriteError(m.SupportedErrors, error, output);
+                    } 
+                    catch (Exception)
+                    {    
+                        // Presumably no match on the exception, throw the original
+                        throw error;
+                    }
                 }
             }
             catch (Exception e)
@@ -215,18 +223,6 @@ namespace Avro.ipc
             return bbo.GetBufferList();
         }
 
-        static StringSchema errorSchema = new StringSchema();
-          private class StringSchema : Schema {
-              
-              public StringSchema() : base(Type.String, new PropertyMap())
-              {
-              }
-
-              public override string Name
-              {
-                  get { return "String"; }
-              }
-          }
-
+        static Schema errorSchema = Schema.Parse("[\"string\"]");
     }
 }
\ No newline at end of file

Modified: avro/trunk/lang/csharp/src/apache/ipc/Specific/SpecificRequestor.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/ipc/Specific/SpecificRequestor.cs?rev=1561874&r1=1561873&r2=1561874&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/ipc/Specific/SpecificRequestor.cs (original)
+++ avro/trunk/lang/csharp/src/apache/ipc/Specific/SpecificRequestor.cs Mon Jan 27 22:05:53
2014
@@ -87,9 +87,13 @@ namespace Avro.ipc.Specific
 
         public override Exception ReadError(Schema writer, Schema reader, Decoder decoder)
         {
-            var response = new SpecificReader<object>(writer, reader).Read(null, decoder);
+            var response = new SpecificReader<object>(writer, reader).Read(null, decoder);
+
+            var error = response as Exception;
+            if(error != null)
+                return error;
 
-            throw (Exception) response;
+            return new Exception(response.ToString());
         }
 
         private static bool LastArgumentIsCallback(object o)

Modified: avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs?rev=1561874&r1=1561873&r2=1561874&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs (original)
+++ avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs Mon Jan 27 22:05:53 2014
@@ -78,7 +78,7 @@ namespace Avro
             this.Doc = doc;
             this.Oneway = oneway;
 
-            if (error != null && error.CanRead(Schema.Parse("[\"string\"]")))
+            if (error != null && error.CanRead(Schema.Parse("string")))
             {
                 this.SupportedErrors = error;
             }

Modified: avro/trunk/lang/csharp/src/apache/test/Ipc/SocketServerWithCallbacksTest.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/test/Ipc/SocketServerWithCallbacksTest.cs?rev=1561874&r1=1561873&r2=1561874&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/test/Ipc/SocketServerWithCallbacksTest.cs (original)
+++ avro/trunk/lang/csharp/src/apache/test/Ipc/SocketServerWithCallbacksTest.cs Mon Jan 27
22:05:53 2014
@@ -557,24 +557,33 @@ namespace Avro.Test.Ipc
 
             Assert.AreEqual(byteBuffer, future2.WaitForResult(2000));
             Assert.IsNull(future2.Error);
-        }
+        }
+
+        [Test, TestCase(false, TestName = "Specific error"), TestCase(true, TestName = "System
error")]
+        public void Error(bool systemError)
+        {
+            Type expected;
+            
+            if(systemError)
+            {
+                expected = typeof(Exception);
+                SimpleImpl.throwSystemError = true;
+            }
+            else
+            {
+                expected = typeof(TestError);
+                SimpleImpl.throwSystemError = false;
+            }
 
-        [Test]
-        public void Error()
-        {
             // Test synchronous RPC:
             try
             {
-                simpleClient.error();
-                Assert.Fail("Expected " + typeof (TestError).Name + " to be thrown");
-            }
-            catch (TestError)
-            {
-                // Expected
+                simpleClient.error();
+                Assert.Fail("Expected " + expected.Name + " to be thrown");
             }
             catch (Exception e)
             {
-                Assert.Fail("Unexpected error: " + e);
+                Assert.AreEqual(expected, e.GetType());
             }
 
             // Test asynchronous RPC (future):
@@ -583,21 +592,22 @@ namespace Avro.Test.Ipc
             try
             {
                 future.WaitForResult(2000);
-                Assert.Fail("Expected " + typeof (TestError).Name + " to be thrown");
-            }
-            catch (TestError)
-            {
+                Assert.Fail("Expected " + expected.Name + " to be thrown");
+            }
+            catch (Exception e)
+            {
+                Assert.AreEqual(expected, e.GetType());
             }
 
             Assert.IsNotNull(future.Error);
-            Assert.AreEqual(typeof (TestError), future.Error.GetType());
+            Assert.AreEqual(expected, future.Error.GetType());
             Assert.IsNull(future.Result);
 
             // Test asynchronous RPC (callback):
             Exception errorRef = null;
             var latch = new CountdownLatch(1);
             simpleClient.error(new CallbackCallFuture<object>(
-                                   result => Assert.Fail("Expected " + typeof (TestError).Name),
+                                   result => Assert.Fail("Expected " + expected.Name),
                                    exception =>
                                        {
                                            errorRef = exception;
@@ -606,9 +616,9 @@ namespace Avro.Test.Ipc
 
             Assert.IsTrue(latch.Wait(2000), "Timed out waiting for error");
             Assert.IsNotNull(errorRef);
-            Assert.AreEqual(typeof (TestError), errorRef.GetType());
-        }
-
+            Assert.AreEqual(expected, errorRef.GetType());
+        }
+
         [Test]
         public void Greeting()
         {
@@ -754,7 +764,9 @@ namespace Avro.Test.Ipc
         }
 
         private class SimpleImpl : Simple
-        {
+        {
+            public static bool throwSystemError = false;
+
             public override string hello(string greeting)
             {
                 return "Hello, " + greeting;
@@ -777,7 +789,10 @@ namespace Avro.Test.Ipc
 
             public override object error()
             {
-                throw new TestError { message = "Test Message" };
+                if(throwSystemError)
+                    throw new SystemException("System error");
+                else
+                    throw new TestError { message = "Test Message" };
             }
 
             public override void ack()



Mime
View raw message