Skip to content

Commit

Permalink
AVRO-4078: [Java] Add the test classes from the reproducer
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Oct 17, 2024
1 parent 6f119ef commit 6d00e35
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lang/java/avro/src/test/java/org/apache/avro/FullName.java
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 lang/java/avro/src/test/java/org/apache/avro/TestAvro4078.java
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));
}
}

0 comments on commit 6d00e35

Please sign in to comment.