EdwinIngJ opened a new pull request, #18734: URL: https://github.com/apache/druid/pull/18734
### Description The following tests in `MySQLInputSourceDatabaseConnectorTest.java` have some nondeterminism due to how properties are checked in [`ConnectionUriUtils.java`](https://github.com/apache/druid/blob/9106cb049692722866e66e42b28bd0f8f7898ab5/processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java#L58): - 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`](https://github.com/apache/druid/blob/9106cb049692722866e66e42b28bd0f8f7898ab5/server/src/main/java/org/apache/druid/metadata/SQLInputSourceDatabaseConnector.java#L77) is called which then calls [`ConnectionUriUtils.throwIfPropertiesAreNotAllowed`](https://github.com/apache/druid/blob/9106cb049692722866e66e42b28bd0f8f7898ab5/processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java#L58). The util function `throwIfPropertiesAreNotAllowed` tests membership using these `Set`s 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: <img width="1079" height="447" alt="Screenshot 2025-11-04 003655" src="https://github.com/user-attachments/assets/9ebd9b6c-bd0a-429f-8238-0a55320ac9af" /> 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: <img width="1070" height="440" alt="Screenshot 2025-11-04 005634" src="https://github.com/user-attachments/assets/0dc72e3f-c2ca-4bf8-92bb-25a8ad20b803" /> --- This PR has: - [x] been self-reviewed. - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
