Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support unit tests for ConcurrentHashSet, #1117 #1128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Add support unit tests for ConcurrentHashSet

Fixes #1117

Description

This ports tests from Harmony for Collections.synchronizedSet and ConcurrentHashMap and adapts them to our ConcurrentHashSet.

This also adds nullable reference type checking to ConcurrentHashSet, which exposed some nullability issues. Given that our current use of this type is for values that should never be null (or would otherwise throw an NRE upon use as null is not checked-for), this adds a generic type constraint of notnull to ensure that it cannot be used with nullable reference types. Work would need to be done (under proper unit test coverage) to make this null-friendly if that is needed in the future.

@paulirwin paulirwin added the notes:improvement An enhancement to an existing feature label Feb 11, 2025
Copy link
Contributor

@NightOwl888 NightOwl888 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I have been considering phasing out the SystemTypesHelpers class (or at least most of the extension methods in it), so ideally any new tests we add would not have any dependencies on those extension methods (.add(), .contains(), .size(), etc.).

If we do keep them, they will definitely need a review. Some of the methods perform poorly or have better alternatives (.toString(), removeAll(), retainAll(), and ToByteArray() to name a few). The .append() overloads are generally there to allow culture invariant numbers to be appended, since .NET doesn't have that built-in. However, I am adding optional parameters to allow passing format and IFormatProvider on OpenStringBuilder in J2N. So, we should probably hold off on the review/removal of SystemTypesHelpers until after J2N has a build with OpenStringBuilder where those can be replaced directly by swapping in OpenStringBuilder for StringBuilder.

src/Lucene.Net/Support/ConcurrentHashSet.cs Outdated Show resolved Hide resolved
smallSet.add(objArray[i]);
}
// LUCENENET TODO: could port this class and all of the classes it uses
// new Support_SetTest(new ConcurrentHashSet<object>(smallSet))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do note that some of these Support_ tests from Harmony have been ported in J2N. https://github.com/NightOwl888/J2N/blob/main/tests/NUnit/J2N.Tests/Collections/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That code appears to be GPL licensed, based on the license in the test project (and that there is no other license listed in this file). Would that be an issue? How would I do the license header in that case?

But we could always leave as a future TODO to port those tests. This test class gives very good test coverage already without them.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Support_ classes were ported from Apache Harmony, so no issue with those:

https://github.com/apache/harmony/blob/trunk/classlib/support/src/test/java/tests/support/Support_SetTest.java
https://github.com/apache/harmony/blob/trunk/classlib/support/src/test/java/tests/support/Support_CollectionTest.java

The GPL license was put there because some of the test code is directly from the JDK and it is the most restrictive license. But we don't ship the test projects. J2N is made up from Apache 2.0 and MIT licenses and should all have headers, but I haven't gone through all of the test files to add license headers.

src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests/Support/TestConcurrentHashSet.cs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:improvement An enhancement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support unit tests for ConcurrentHashSet
2 participants