Fix test flakniess due to order dependency from getDeclaredMethods()
#70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The tests in
CachingObjectStorage.javadealing with multiple cached requests can fail nondeterministically when running in different JVMs. The issue is found using the commandmvn edu.illinois:nondex-maven-plugin:1.1.2:nondexunder thehdfs-connectordirectory after building dependencies.Reason for Flakiness
The tests call
Mockito.verify()to assure that the mock client calls the routinegetObject()only once when same requests are cached. However, when running in different environments, these verifications may occassionally fail. The reason is that inCachingObjectStorage.getObject(), the code callsCache.put()with a key-value pair to update the cache. The method will create a new key-value pair ( rather than replacing the old value with the input value) if the input key (hashcode-wise) is not equal to any keys in the cache. However, in thehashcode()method, the final object to be hashed is anArray, which preserves order. While the output ofgetDeclaredMethods()does not guarantee any order, the array for hashing (line 779 at CachingObjectStorage.java) may have nondeterministic element orders. As a result, thehashcodeof two same keys can be different, leading to "duplicated" entries in the cache, and the mock client can then callgetObject()more times than desired.List of flaky tests in
CachingObjectStorage.javaSample Failure
Proposed Fix
Convert the array into a normal
HashSetbefore hashing to avoid unwanted order dependency.OCA signed
https://oca.opensource.oracle.com/api/v1/oca-requests/6710/documents/6730/download
(approved)