avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1056499 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/ipc/src/main/java/org/apache/avro/ipc/ lang/java/ipc/src/main/java/org/apache/avro/specific/ lang/ja...
Date Fri, 07 Jan 2011 20:42:51 GMT
Author: cutting
Date: Fri Jan  7 20:42:51 2011
New Revision: 1056499

URL: http://svn.apache.org/viewvc?rev=1056499&view=rev
Log:
AVRO-723. Java: Pass error messages for unexpected RPC exceptions through to client.  Contributed
by Stephen Gargan.

Added:
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java
    avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/specific/SpecificResponder.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Jan  7 20:42:51 2011
@@ -82,6 +82,9 @@ Avro 1.5.0 (unreleased)
     AVRO-669. Java: Make MapReduce to work with reflection-based data.
     (cutting)
 
+    AVRO-723. Java: Pass error messages for unexpected RPC exceptions
+    through to client. (Stephen Gargan via cutting)
+
   BUG FIXES
 
     AVRO-675. C: Bytes and fixed setters don't update datum size.

Added: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java?rev=1056499&view=auto
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
(added)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
Fri Jan  7 20:42:51 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+
+package org.apache.avro;
+
+/** Thrown when the expected contents of a union cannot be resolved. */
+public class UnresolvedUnionException extends AvroRuntimeException {
+  private Object unresolvedDatum;
+  private Schema unionSchema;
+  
+  public UnresolvedUnionException(Schema unionSchema, Object unresolvedDatum) {
+    super("Not in union "+unionSchema+": "+unresolvedDatum);
+    this.unionSchema = unionSchema;
+    this.unresolvedDatum = unresolvedDatum;
+  }
+
+  public Object getUnresolvedDatum() {
+    return unresolvedDatum;
+  }
+
+  public Schema getUnionSchema() {
+    return unionSchema;
+  }
+}

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Fri Jan
 7 20:42:51 2011
@@ -29,6 +29,7 @@ import org.apache.avro.AvroTypeException
 import org.apache.avro.Schema;
 import org.apache.avro.Schema.Field;
 import org.apache.avro.Schema.Type;
+import org.apache.avro.UnresolvedUnionException;
 import org.apache.avro.io.BinaryData;
 import org.apache.avro.util.Utf8;
 
@@ -442,7 +443,7 @@ public class GenericData {
         return i;
       i++;
     }
-    throw new AvroRuntimeException("Not in union "+union+": "+datum);
+    throw new UnresolvedUnionException(union, datum);
   }
 
   /** Called by {@link #resolveUnion(Schema,Object)}.  May be overridden for

Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java (original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/Responder.java Fri Jan  7 20:42:51
2011
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.avro.AvroRuntimeException;
+import org.apache.avro.UnresolvedUnionException;
 import org.apache.avro.Protocol;
 import org.apache.avro.Schema;
 import org.apache.avro.Protocol.Message;
@@ -159,7 +160,11 @@ public abstract class Responder {
       if (error == null)
         writeResponse(m.getResponse(), response, out);
       else
-        writeError(m.getErrors(), error, out);
+        try {
+          writeError(m.getErrors(), error, out);
+        } catch (UnresolvedUnionException e) {    // unexpected error
+          throw error;
+        }
     } catch (Exception e) {                       // system error
       LOG.warn("system error", e);
       context.setError(e);

Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/specific/SpecificResponder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/specific/SpecificResponder.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/specific/SpecificResponder.java
(original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/specific/SpecificResponder.java
Fri Jan  7 20:42:51 2011
@@ -26,6 +26,7 @@ import org.apache.avro.Schema;
 import org.apache.avro.Protocol;
 import org.apache.avro.Protocol.Message;
 import org.apache.avro.AvroRuntimeException;
+import org.apache.avro.UnresolvedUnionException;
 import org.apache.avro.io.DatumReader;
 import org.apache.avro.io.DatumWriter;
 import org.apache.avro.io.Decoder;

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java Fri Jan
 7 20:42:51 2011
@@ -33,6 +33,7 @@ import org.junit.Before;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -175,6 +176,7 @@ public class TestProtocolGeneric {
       this.throwUndeclaredError = false;
     }
     assertNotNull(error);
+    assertTrue(error.toString().contains("foo"));
   }
 
   @Test

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java Fri Jan
 7 20:42:51 2011
@@ -30,6 +30,7 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.net.InetSocketAddress;
 import java.util.Random;
@@ -134,6 +135,7 @@ public class TestProtocolReflect {
       this.throwUndeclaredError = false;
     }
     assertNotNull(error);
+    assertTrue(error.toString().contains("foo"));
   }
 
   @AfterClass

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java?rev=1056499&r1=1056498&r2=1056499&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java Fri Jan
 7 20:42:51 2011
@@ -38,6 +38,7 @@ import org.junit.After;
 import org.junit.Test;
 import org.junit.Before;
 import org.junit.AfterClass;
+import static org.junit.Assert.assertTrue;
 
 import static org.junit.Assert.*;
 
@@ -190,6 +191,7 @@ public class TestProtocolSpecific {
       this.throwUndeclaredError = false;
     }
     assertNotNull(error);
+    assertTrue(error.toString().contains("foo"));
   }
 
 



Mime
View raw message