You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2014/11/04 18:27:18 UTC
svn commit: r1636657 -
/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java
Author: cutting
Date: Tue Nov 4 17:27:17 2014
New Revision: 1636657
URL: http://svn.apache.org/r1636657
Log:
AVRO-1502. Add a test for SpecificRecordBase's Externalizable implemenatation.
Modified:
avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java
Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java?rev=1636657&r1=1636656&r2=1636657&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificData.java Tue Nov 4 17:27:17 2014
@@ -24,7 +24,11 @@ import static org.junit.Assert.assertNot
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -32,6 +36,7 @@ import java.util.List;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.Schema.Type;
+import org.apache.avro.generic.GenericData;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
@@ -87,12 +92,14 @@ public class TestSpecificData {
public void primitiveWrapper(Integer i) {}
}
- private static class TestRecord extends SpecificRecordBase {
+ public static class TestRecord extends SpecificRecordBase {
private static final Schema SCHEMA = Schema.createRecord("TestRecord", null, null, false);
static {
List<Field> fields = new ArrayList<Field>();
fields.add(new Field("x", Schema.create(Type.INT), null, null));
- fields.add(new Field("y", Schema.create(Type.STRING), null, null));
+ Schema stringSchema = Schema.create(Type.STRING);
+ GenericData.setStringType(stringSchema, GenericData.StringType.String);
+ fields.add(new Field("y", stringSchema, null, null));
SCHEMA.setFields(fields);
}
private int x;
@@ -121,12 +128,6 @@ public class TestSpecificData {
return SCHEMA;
}
- @Override public void writeExternal(java.io.ObjectOutput out) {
- throw new UnsupportedOperationException();
- }
- @Override public void readExternal(java.io.ObjectInput in) {
- throw new UnsupportedOperationException();
- }
}
@Test
@@ -138,6 +139,22 @@ public class TestSpecificData {
assertEquals("str", record.get("y"));
}
+ @Test public void testExternalizeable() throws Exception {
+ final TestRecord before = new TestRecord();
+ before.put("x", 1);
+ before.put("y", "str");
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bytes);
+ out.writeObject(before);
+ out.close();
+
+ ObjectInputStream in =
+ new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
+ TestRecord after = (TestRecord)in.readObject();
+
+ assertEquals(before, after);
+ }
+
/** Tests that non Stringable datum are rejected by specific writers. */
@Test
public void testNonStringable() throws Exception {