diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..c752d9d
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,18 @@
+name: Java CI
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-java@v3
+ with:
+ distribution: 'temurin'
+ java-version: '11'
+ - name: Build with Maven
+ run: mvn -B test
diff --git a/pom.xml b/pom.xml
index a71145f..71fae57 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,6 +17,11 @@
7
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
@@ -46,5 +51,11 @@
avro
1.10.0
+
+ junit
+ junit
+ 4.13.2
+ test
+
-
\ No newline at end of file
+
diff --git a/src/main/java/com.instarsocial.parquet/App.java b/src/main/java/com/instarsocial/parquet/App.java
similarity index 65%
rename from src/main/java/com.instarsocial.parquet/App.java
rename to src/main/java/com/instarsocial/parquet/App.java
index b6e870b..a97048e 100644
--- a/src/main/java/com.instarsocial.parquet/App.java
+++ b/src/main/java/com/instarsocial/parquet/App.java
@@ -23,35 +23,37 @@ public static void main(String[] args) {
DateTime dateTime = new DateTime(2020, 6, 1, 0, 0, 0, 0, DateTimeZone.UTC);
for(int i = 0; i < 2; i++) {
- generateParquetFileFor(dateTime.plusDays(i));
+ try {
+ generateParquetFileFor(dateTime.plusDays(i));
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
}
}
- private static void generateParquetFileFor(DateTime dateTime) {
- try {
- Schema schema = parseSchema();
- DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
- Path path = new Path("data_" + dateTime.toString(fmt) + ".parquet");
-
- List recordList = generateRecords(schema, dateTime);
-
- try (ParquetWriter writer = AvroParquetWriter.builder(path)
- .withSchema(schema)
- .withCompressionCodec(CompressionCodecName.SNAPPY)
- .withRowGroupSize(ParquetWriter.DEFAULT_BLOCK_SIZE)
- .withPageSize(ParquetWriter.DEFAULT_PAGE_SIZE)
- .withConf(new Configuration())
- .withValidation(false)
- .withDictionaryEncoding(false)
- .build()) {
-
- for (GenericData.Record record : recordList) {
- writer.write(record);
- }
+ public static Path generateParquetFileFor(DateTime dateTime) throws Exception {
+ Schema schema = parseSchema();
+ DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
+ Path path = new Path("data_" + dateTime.toString(fmt) + ".parquet");
+
+ List recordList = generateRecords(schema, dateTime);
+
+ try (ParquetWriter writer = AvroParquetWriter.builder(path)
+ .withSchema(schema)
+ .withCompressionCodec(CompressionCodecName.SNAPPY)
+ .withRowGroupSize(ParquetWriter.DEFAULT_BLOCK_SIZE)
+ .withPageSize(ParquetWriter.DEFAULT_PAGE_SIZE)
+ .withConf(new Configuration())
+ .withValidation(false)
+ .withDictionaryEncoding(false)
+ .build()) {
+
+ for (GenericData.Record record : recordList) {
+ writer.write(record);
}
- } catch (Exception ex) {
- ex.printStackTrace(System.out);
}
+
+ return path;
}
private static Schema parseSchema() {
@@ -87,4 +89,4 @@ private static List generateRecords(Schema schema, DateTime
return recordList;
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/com/instarsocial/parquet/AppTest.java b/src/test/java/com/instarsocial/parquet/AppTest.java
new file mode 100644
index 0000000..e0a408f
--- /dev/null
+++ b/src/test/java/com/instarsocial/parquet/AppTest.java
@@ -0,0 +1,55 @@
+package com.instarsocial.parquet;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.charset.StandardCharsets;
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link App} using the Arrange-Act-Assert pattern.
+ */
+
+public class AppTest {
+
+ /** Temporary file generated by the test. */
+ private static File generatedFile;
+
+ @BeforeClass
+ public static void beforeAll() {
+ generatedFile = null;
+ }
+
+ @AfterClass
+ public static void afterAll() {
+ if (generatedFile != null && generatedFile.exists()) {
+ generatedFile.delete();
+ }
+ }
+
+ @Test
+ public void Should_CreateParquetFile_When_CallingGenerateParquetFileFor() throws Exception {
+ // Arrange
+ DateTime dateTime = new DateTime(2020, 6, 1, 0, 0, 0, 0, DateTimeZone.UTC);
+
+ // Act
+ org.apache.hadoop.fs.Path actual = App.generateParquetFileFor(dateTime);
+
+ // Assert
+ assertNotNull("Path should not be null", actual);
+ generatedFile = new File(actual.toString());
+ assertTrue("Generated file should exist", generatedFile.exists());
+
+ try (FileInputStream fis = new FileInputStream(generatedFile)) {
+ byte[] magic = new byte[4];
+ int read = fis.read(magic);
+ assertEquals(4, read);
+ assertEquals("PAR1", new String(magic, StandardCharsets.US_ASCII));
+ }
+ }
+}