From fb59f5077a7d91dd7eebb23dae62eec4d71c4084 Mon Sep 17 00:00:00 2001 From: shivzone Date: Mon, 9 Oct 2017 14:41:29 -0700 Subject: [PATCH] HAWQ-1536. Fix PXF Json no seek unit test --- .../PartitionedJsonParserNoSeekTest.java | 20 ++++++++++------ .../array_objects_complex_ordering.json | 24 +++++++++++++++++++ ...jects_complex_ordering.json.expected1.json | 4 ++++ ...jects_complex_ordering.json.expected2.json | 4 ++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json create mode 100644 pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected1.json create mode 100644 pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected2.json diff --git a/pxf/pxf-json/src/test/java/org/apache/hawq/pxf/plugins/json/parser/PartitionedJsonParserNoSeekTest.java b/pxf/pxf-json/src/test/java/org/apache/hawq/pxf/plugins/json/parser/PartitionedJsonParserNoSeekTest.java index cdc876b96a..f2fdeeb403 100644 --- a/pxf/pxf-json/src/test/java/org/apache/hawq/pxf/plugins/json/parser/PartitionedJsonParserNoSeekTest.java +++ b/pxf/pxf-json/src/test/java/org/apache/hawq/pxf/plugins/json/parser/PartitionedJsonParserNoSeekTest.java @@ -19,14 +19,13 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; +import java.util.HashSet; +import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -34,6 +33,8 @@ import org.apache.commons.logging.LogFactory; import org.junit.Test; +import static org.junit.Assert.*; + public class PartitionedJsonParserNoSeekTest { private static final Log LOG = LogFactory.getLog(PartitionedJsonParserNoSeekTest.class); @@ -64,11 +65,16 @@ public boolean accept(File file, String s) { } }); - for (File jsonObjectFile : jsonOjbectFiles) { - String expected = trimWhitespaces(FileUtils.readFileToString(jsonObjectFile)); + Set resultElements = new HashSet(); + for(int i=0; i < jsonOjbectFiles.length; i++) { String result = parser.nextObjectContainingMember("name"); - assertNotNull(jsonFile.getName() + "/" + jsonObjectFile.getName(), result); - assertEquals(jsonFile.getName() + "/" + jsonObjectFile.getName(), expected, trimWhitespaces(result)); + assertNotNull(jsonFile.getName() + " invalid object", result); + resultElements.add(trimWhitespaces(result)); + } + + for(File jsonObjectFile : jsonOjbectFiles) { + String expected = trimWhitespaces(FileUtils.readFileToString(jsonObjectFile)); + assertTrue(jsonFile.getName() + "/" + jsonObjectFile.getName(), resultElements.contains(expected)); LOG.info("File " + jsonFile.getName() + "/" + jsonObjectFile.getName() + " passed"); } diff --git a/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json new file mode 100644 index 0000000000..e7fca846de --- /dev/null +++ b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json @@ -0,0 +1,24 @@ +[ + { + "color": "red", + "v": "vv", + "a": true, + "b": false, + "c": 123.45, + "d": null, + "e": { + "e1":"", + "":"" + }, + "f": [ + { + "f1":"", + "name":"" + }, + { + "name":"", + "f2":"" + } + ] + } +] \ No newline at end of file diff --git a/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected1.json b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected1.json new file mode 100644 index 0000000000..c485b8b54e --- /dev/null +++ b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected1.json @@ -0,0 +1,4 @@ +{ + "name":"", + "f2":"" + } diff --git a/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected2.json b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected2.json new file mode 100644 index 0000000000..ceee973584 --- /dev/null +++ b/pxf/pxf-json/src/test/resources/parser-tests/noseek/array_objects_complex_ordering.json.expected2.json @@ -0,0 +1,4 @@ +{ + "f1":"", + "name":"" + } \ No newline at end of file