-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AVRO-4078: [Java] Add the test classes from the reproducer
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
lang/java/avro/src/test/java/org/apache/avro/FullName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.apache.avro; | ||
|
||
import org.apache.avro.AvroRuntimeException; | ||
import org.apache.avro.Schema; | ||
import org.apache.avro.io.DatumReader; | ||
import org.apache.avro.io.DatumWriter; | ||
import org.apache.avro.specific.AvroGenerated; | ||
import org.apache.avro.specific.SpecificDatumReader; | ||
import org.apache.avro.specific.SpecificDatumWriter; | ||
import org.apache.avro.specific.SpecificRecord; | ||
import org.apache.avro.specific.SpecificRecordBase; | ||
|
||
@AvroGenerated | ||
public class FullName extends SpecificRecordBase implements SpecificRecord { | ||
private static final long serialVersionUID = 4560514203639509981L; | ||
public static final Schema SCHEMA$ = (new Schema.Parser()).parse( | ||
"{\"type\":\"record\",\"name\":\"FullName\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"first\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}},{\"name\":\"last\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}]}"); | ||
private String first; | ||
private String last; | ||
private static final DatumWriter WRITER$; | ||
private static final DatumReader READER$; | ||
|
||
public FullName() { | ||
} | ||
|
||
public FullName(String first, String last) { | ||
this.first = first; | ||
this.last = last; | ||
} | ||
|
||
public Schema getSchema() { | ||
return SCHEMA$; | ||
} | ||
|
||
public Object get(int field$) { | ||
switch (field$) { | ||
case 0: | ||
return this.first; | ||
case 1: | ||
return this.last; | ||
default: | ||
throw new AvroRuntimeException("Bad index"); | ||
} | ||
} | ||
|
||
public void put(int field$, Object value$) { | ||
switch (field$) { | ||
case 0: | ||
this.first = (String) value$; | ||
break; | ||
case 1: | ||
this.last = (String) value$; | ||
break; | ||
default: | ||
throw new AvroRuntimeException("Bad index"); | ||
} | ||
|
||
} | ||
|
||
static { | ||
WRITER$ = new SpecificDatumWriter(SCHEMA$); | ||
READER$ = new SpecificDatumReader(SCHEMA$); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
lang/java/avro/src/test/java/org/apache/avro/TestAvro4078.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.apache.avro; | ||
|
||
import org.apache.avro.specific.SpecificData; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for demonstrating specific data potential issue. | ||
*/ | ||
public class TestAvro4078 { | ||
|
||
public static final Schema FULLNAME_SCHEMA = (new Schema.Parser()).parse("{\n" + " \"type\": \"record\",\n" | ||
+ " \"namespace\": \"org.apache.avro\",\n" + " \"name\": \"FullName\",\n" + " \"fields\": [\n" | ||
+ " { \"name\": \"first\", \"type\": \"string\" },\n" | ||
+ " { \"name\": \"last\", \"type\": \"string\" }\n" + " ]\n" + "}"); | ||
|
||
@Test | ||
public void testClassLoad() { | ||
System.err.println(FULLNAME_SCHEMA); | ||
System.err.println(SpecificData.get().getClass(FULLNAME_SCHEMA)); | ||
} | ||
} |