Skip to content

Conversation

@EdwinIngJ
Copy link
Contributor

Description

The following tests in MySQLInputSourceDatabaseConnectorTest.java have some nondeterminism due to how properties are checked in ConnectionUriUtils.java:

  • org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailWhenNoAllowlistAndHaveProperty
  • org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailOnlyInvalidProperty
  • org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailValidAndInvalidPropertyMariadb

This PR proposes a fix to ensure the tests are robust to nondeterministic behaviors with different JVM and future updates to it.

Problem

When a MySQLInputSourceDatabaseConnector is created, validateConfig is called which then calls ConnectionUriUtils.throwIfPropertiesAreNotAllowed. The util function throwIfPropertiesAreNotAllowed tests membership using these Sets and throws an exception on the first element that is not in the allowedProperties Set. However, if there is more than one element not in the allowedProperties Set, then there may be multiple possible exception messages since a specific ordering of these elements is not guaranteed.

As a result, the tests can fail as such:

[ERROR] org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailWhenNoAllowlistAndHaveProperty
[ERROR]   Run 1: MySQLInputSourceDatabaseConnectorTest.testFailWhenNoAllowlistAndHaveProperty 
Expected: (exception with message a string containing "The property [password] is not in the allowed list" and an instance of java.lang.IllegalArgumentException)                                                                                                                                     
     but: exception with message a string containing "The property [password] is not in the allowed list" message was "The property [user] is not in the allowed list []"                                                                                                                             
Stacktrace was: java.lang.IllegalArgumentException: The property [user] is not in the allowed list []                                              
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:445)                                                              
        at org.apache.druid.utils.ConnectionUriUtils.throwIfPropertiesAreNotAllowed(ConnectionUriUtils.java:69)                                    
        at org.apache.druid.metadata.SQLInputSourceDatabaseConnector.validateConfigs(SQLInputSourceDatabaseConnector.java:99)                      
        at org.apache.druid.metadata.SQLInputSourceDatabaseConnector.getDatasource(SQLInputSourceDatabaseConnector.java:77)                        
        at org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnector.<init>(MySQLInputSourceDatabaseConnector.java:57)                     
        at org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailWhenNoAllowlistAndHaveProperty(MySQLInputSourceDatabaseConnectorTest.java:173)                                                                                                        

Solution

To fix org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailWhenNoAllowlistAndHaveProperty and org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailOnlyInvalidProperty, I enumerated all the possible error messages using:

expectedException.expectMessage(
        anyOf(
                containsString("The property [password] is not in the allowed list"),
                containsString("The property [user] is not in the allowed list")
        )
);

These values are found here:
Screenshot 2025-11-04 003655

To fix org.apache.druid.metadata.input.MySQLInputSourceDatabaseConnectorTest.testFailValidAndInvalidPropertyMariadb, I enumerated all the possible error messages using:

expectedException.expectMessage(
        anyOf(
                containsString("The property [password] is not in the allowed list"),
                containsString("The property [keyonly] is not in the allowed list")
        )
);

These values are found here:
Screenshot 2025-11-04 005634


This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant