-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8465329
commit b66ab0f
Showing
3 changed files
with
51 additions
and
33 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
avro/src/test/java/com/fasterxml/jackson/dataformat/avro/FileFormatTest.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,42 @@ | ||
package com.fasterxml.jackson.dataformat.avro; | ||
|
||
import org.apache.avro.file.DataFileReader; | ||
import org.apache.avro.file.SeekableByteArrayInput; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.io.DatumReader; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
// for [dataformats-binary#16] | ||
public class FileFormatTest extends AvroTestBase | ||
{ | ||
public void testFileFormatOutput() throws Exception | ||
{ | ||
Employee empl = new Employee(); | ||
empl.name = "Bobbee"; | ||
empl.age = 39; | ||
empl.emails = new String[] { "[email protected]", "[email protected]" }; | ||
empl.boss = null; | ||
|
||
AvroFactory af = new AvroFactory(); | ||
ObjectMapper mapper = new ObjectMapper(af); | ||
|
||
af.enable(AvroGenerator.Feature.AVRO_FILE_OUTPUT); | ||
|
||
AvroSchema schema = getEmployeeSchema(); | ||
byte[] bytes = mapper.writer(schema).writeValueAsBytes(empl); | ||
|
||
assertNotNull(bytes); | ||
assertEquals(301, bytes.length); | ||
|
||
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema.getAvroSchema()); | ||
@SuppressWarnings("resource") | ||
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(new SeekableByteArrayInput(bytes), | ||
datumReader); | ||
GenericRecord output = dataFileReader.next(); | ||
|
||
assertNotNull(output); | ||
assertEquals(output.get("name").toString(), empl.name); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,11 +3,6 @@ | |
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.apache.avro.file.DataFileReader; | ||
import org.apache.avro.file.SeekableByteArrayInput; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.io.DatumReader; | ||
import org.junit.Assert; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
@@ -165,31 +160,4 @@ public void testIgnoringOfUnknownObject() throws Exception | |
BinaryAndNumber output = mapper.reader(SCHEMA_WITH_BINARY_JSON).forType(BinaryAndNumber.class).readValue(bytes); | ||
assertEquals("Bob", output.name); | ||
} | ||
|
||
public void testFileOutput() throws Exception | ||
{ | ||
Employee empl = new Employee(); | ||
empl.name = "Bobbee"; | ||
empl.age = 39; | ||
empl.emails = new String[] { "[email protected]", "[email protected]" }; | ||
empl.boss = null; | ||
|
||
AvroFactory af = new AvroFactory(); | ||
ObjectMapper mapper = new ObjectMapper(af); | ||
|
||
af.enable(AvroGenerator.Feature.AVRO_FILE_OUTPUT); | ||
|
||
AvroSchema schema = getEmployeeSchema(); | ||
byte[] bytes = mapper.writer(schema).writeValueAsBytes(empl); | ||
|
||
assertNotNull(bytes); | ||
assertEquals(301, bytes.length); | ||
|
||
DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(schema.getAvroSchema()); | ||
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new SeekableByteArrayInput(bytes), datumReader); | ||
GenericRecord output = dataFileReader.next(); | ||
|
||
assertNotNull(output); | ||
assertEquals(output.get("name").toString(), empl.name); | ||
} | ||
} |