32
32
import org .testng .Assert ;
33
33
import org .testng .annotations .AfterClass ;
34
34
import org .testng .annotations .BeforeClass ;
35
+ import org .testng .annotations .DataProvider ;
35
36
import org .testng .annotations .Test ;
36
37
37
38
import com .google .gson .Gson ;
@@ -54,7 +55,6 @@ public class AvroHdfsDataWriterTest {
54
55
private static final Type FIELD_ENTRY_TYPE = new TypeToken <Map <String , Object >>() {}.getType ();
55
56
56
57
private Schema schema ;
57
- private DataWriter <GenericRecord > writer ;
58
58
private String filePath ;
59
59
private State properties ;
60
60
@@ -83,24 +83,31 @@ public void setUp() throws Exception {
83
83
properties .setProp (ConfigurationKeys .WRITER_OUTPUT_DIR , TestConstants .TEST_OUTPUT_DIR );
84
84
properties .setProp (ConfigurationKeys .WRITER_FILE_PATH , this .filePath );
85
85
properties .setProp (ConfigurationKeys .WRITER_FILE_NAME , TestConstants .TEST_FILE_NAME );
86
+ }
86
87
87
- // Build a writer to write test records
88
- this .writer = new AvroDataWriterBuilder ().writeTo (Destination .of (Destination .DestinationType .HDFS , properties ))
89
- .writeInFormat (WriterOutputFormat .AVRO ).withWriterId (TestConstants .TEST_WRITER_ID ).withSchema (this .schema )
90
- .withBranches (1 ).forBranch (0 ).build ();
88
+ @ DataProvider (name = "codecs" )
89
+ private String [] codecs () {
90
+ return new String []{"null" , "deflate" , "snappy" , "bzip2" , "xz" , "zstandard" };
91
91
}
92
92
93
- @ Test
94
- public void testWrite () throws IOException {
93
+ @ Test (dataProvider = "codecs" )
94
+ public void testWrite (String codec ) throws IOException {
95
+ properties .setProp (ConfigurationKeys .WRITER_CODEC_TYPE , codec );
96
+ DataWriterBuilder <Schema , GenericRecord > builder = new AvroDataWriterBuilder ()
97
+ .writeTo (Destination .of (Destination .DestinationType .HDFS , properties ))
98
+ .writeInFormat (WriterOutputFormat .AVRO ).withWriterId (TestConstants .TEST_WRITER_ID )
99
+ .withSchema (this .schema ).withBranches (1 ).forBranch (0 );
100
+ DataWriter <GenericRecord > writer = builder .build ();
101
+
95
102
// Write all test records
96
103
for (String record : TestConstants .JSON_RECORDS ) {
97
- this . writer .write (convertRecord (record ));
104
+ writer .write (convertRecord (record ));
98
105
}
99
106
100
- Assert .assertEquals (this . writer .recordsWritten (), 3 );
107
+ Assert .assertEquals (writer .recordsWritten (), 3 );
101
108
102
- this . writer .close ();
103
- this . writer .commit ();
109
+ writer .close ();
110
+ writer .commit ();
104
111
105
112
File outputFile =
106
113
new File (TestConstants .TEST_OUTPUT_DIR + Path .SEPARATOR + this .filePath , TestConstants .TEST_FILE_NAME );
0 commit comments