|
@@ -28,9 +28,11 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.LocalFileSystem;
|
|
import org.apache.hadoop.fs.LocalFileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
+import org.apache.hadoop.fs.PathIOException;
|
|
import org.apache.hadoop.test.HadoopTestBase;
|
|
import org.apache.hadoop.test.HadoopTestBase;
|
|
import org.apache.hadoop.test.LambdaTestUtils;
|
|
import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
|
|
|
@@ -151,6 +153,9 @@ public class TestJsonSerialization extends HadoopTestBase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * round trip through both load APIs.
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
public void testFileSystemRoundTrip() throws Throwable {
|
|
public void testFileSystemRoundTrip() throws Throwable {
|
|
File tempFile = File.createTempFile("Keyval", ".json");
|
|
File tempFile = File.createTempFile("Keyval", ".json");
|
|
@@ -159,19 +164,30 @@ public class TestJsonSerialization extends HadoopTestBase {
|
|
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
|
|
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
|
|
try {
|
|
try {
|
|
serDeser.save(fs, tempPath, source, false);
|
|
serDeser.save(fs, tempPath, source, false);
|
|
- assertEquals(source, serDeser.load(fs, tempPath));
|
|
|
|
|
|
+ assertEquals("JSON loaded with load(fs, path)",
|
|
|
|
+ source,
|
|
|
|
+ serDeser.load(fs, tempPath));
|
|
|
|
+ assertEquals("JSON loaded with load(fs, path, status)",
|
|
|
|
+ source,
|
|
|
|
+ serDeser.load(fs, tempPath, fs.getFileStatus(tempPath)));
|
|
} finally {
|
|
} finally {
|
|
fs.delete(tempPath, false);
|
|
fs.delete(tempPath, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 0 byte file through the load(path) API will fail with a wrapped
|
|
|
|
+ * Parser exception.
|
|
|
|
+ * 0 byte file through the load(path, status) API will fail with a wrapped
|
|
|
|
+ * Parser exception.
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
public void testFileSystemEmptyPath() throws Throwable {
|
|
public void testFileSystemEmptyPath() throws Throwable {
|
|
File tempFile = File.createTempFile("Keyval", ".json");
|
|
File tempFile = File.createTempFile("Keyval", ".json");
|
|
Path tempPath = new Path(tempFile.toURI());
|
|
Path tempPath = new Path(tempFile.toURI());
|
|
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
|
|
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
|
|
try {
|
|
try {
|
|
- LambdaTestUtils.intercept(EOFException.class,
|
|
|
|
|
|
+ LambdaTestUtils.intercept(PathIOException.class,
|
|
() -> serDeser.load(fs, tempPath));
|
|
() -> serDeser.load(fs, tempPath));
|
|
fs.delete(tempPath, false);
|
|
fs.delete(tempPath, false);
|
|
LambdaTestUtils.intercept(FileNotFoundException.class,
|
|
LambdaTestUtils.intercept(FileNotFoundException.class,
|
|
@@ -181,5 +197,23 @@ public class TestJsonSerialization extends HadoopTestBase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 0 byte file through the load(path, status) API will fail with an
|
|
|
|
+ * EOFException.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testFileSystemEmptyStatus() throws Throwable {
|
|
|
|
+ File tempFile = File.createTempFile("Keyval", ".json");
|
|
|
|
+ Path tempPath = new Path(tempFile.toURI());
|
|
|
|
+ LocalFileSystem fs = FileSystem.getLocal(new Configuration());
|
|
|
|
+ try {
|
|
|
|
+ final FileStatus st = fs.getFileStatus(tempPath);
|
|
|
|
+ LambdaTestUtils.intercept(EOFException.class,
|
|
|
|
+ () -> serDeser.load(fs, tempPath, st));
|
|
|
|
+ } finally {
|
|
|
|
+ fs.delete(tempPath, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|