Skip to content

Fixed flaky tests in CompatParquetReaderTest.java with ObjectMapper#2

Open
CaseyPan wants to merge 1 commit intomasterfrom
fix-CompatParquetReaderTest
Open

Fixed flaky tests in CompatParquetReaderTest.java with ObjectMapper#2
CaseyPan wants to merge 1 commit intomasterfrom
fix-CompatParquetReaderTest

Conversation

@CaseyPan
Copy link
Copy Markdown
Owner

@CaseyPan CaseyPan commented Oct 27, 2023

Description

Fixed flaky tests in CompatParquetReaderTest.java with ObjectMapper

Test: testBinaryAsString, testParquetThriftCompat, testReadNestedArrayStruct, testProtoStructWithArray

Steps to Reproduce:

  1. Clone the repo
    git clone git clone https://github.com/apache/druid.git
    
  2. Install the package
    mvn install -pl extensions-core/parquet-extensions -am -DskipTests
    
  3. Run the test in regular runs
    mvn -pl extensions-core/parquet-extensions test -Dtest=org.apache.druid.data.input.parquet.CompatParquetReaderTest#testname
    
  4. The test failed by running the test with Non-Dex tool.
    mvn -pl extensions-core/parquet-extensions edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dcheckstyle.skip -Dtest=org.apache.druid.data.input.parquet.CompatParquetReaderTest#testname
    

The following is an example error message from testReadNestedArrayStruct

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.732 s <<< FAILURE! -- in org.apache.druid.data.input.parquet.CompatParquetReaderTest
[ERROR] org.apache.druid.data.input.parquet.CompatParquetReaderTest.testReadNestedArrayStruct -- Time elapsed: 0.052 s <<< FAILURE!
org.junit.ComparisonFailure: 
expected:<{
  "[primitive" : 2,
  "myComplex" : [ {
    "id" : 1,
    "repeatedMessage" : [ 3 ]
  } ]]
}> but was:<{
  "[myComplex" : [ {
    "id" : 1,
    "repeatedMessage" : [ 3 ]
  } ],
  "primitive" : 2]
}>
        at org.junit.Assert.assertEquals(Assert.java:117)
        at org.junit.Assert.assertEquals(Assert.java:146)
        at org.apache.druid.data.input.parquet.CompatParquetReaderTest.testReadNestedArrayStruct(CompatParquetReaderTest.java:392)

Reason of flakiness:
These tests check the equality of two JSON strings. The data reading methods used createReader() in those tests do not retrieve data in a consistent order, which can possibly lead to different JSON representations of the same data during test runs.

Changes:

  • Imported fasterxml.jackson package, and changed from using standard assertion method Assert to using JSONNode and ObjectMapper, which parse two JSON strings and convert them to a tree structure and each node in the trees are compared. Thus, the order of the elements in JSON strings is deterministic and the test passes.

Release note

Fixed: CompatParquetReaderTest tests no longer fail when running with the NonDex tool.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@zzjas
Copy link
Copy Markdown

zzjas commented Oct 31, 2023

Have you checked if any existing dependency has the ability to compare JSON strings? I saw com.fasterxml.jackson in the pom file and you might want to check that.

try {
JSONAssert.assertEquals(expectedJson, DEFAULT_JSON_WRITER.writeValueAsString(sampled.get(0).getRawValues()), false);
}
catch (JSONException jse) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for adding try-catch blocks? I see that you are any way throwing RuntimeException in catch block, what is the use of changing the type of exception

@CaseyPan CaseyPan changed the title Fixed flaky tests in CompatParquetReaderTest.java with JSONAssert Fixed flaky tests in CompatParquetReaderTest.java with ObjectMapper Nov 8, 2023
@CaseyPan CaseyPan force-pushed the fix-CompatParquetReaderTest branch from f221526 to 44eaeb7 Compare November 8, 2023 05:14
@CaseyPan CaseyPan force-pushed the fix-CompatParquetReaderTest branch 2 times, most recently from d3b51aa to ffb77be Compare November 17, 2023 23:54
@CaseyPan CaseyPan force-pushed the fix-CompatParquetReaderTest branch from ffb77be to b8c57d5 Compare November 18, 2023 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants