NightOwl888 commented on code in PR #1129:
URL: https://github.com/apache/lucenenet/pull/1129#discussion_r1957252159


##########
src/Lucene.Net.Tests/Support/TestConcurrentSet.cs:
##########
@@ -0,0 +1,42 @@
+// Some tests adapted from Apache Harmony:
+// 
https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/concurrent/src/test/java/ConcurrentHashMapTest.java
+// 
https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
+
+using Lucene.Net.Support;
+using System.Collections.Generic;
+
+namespace Lucene.Net
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+    /// <summary>
+    /// Tests for <see cref="ConcurrentSet{T}"/>.
+    /// </summary>
+    /// <remarks>
+    /// See the <see cref="TestConcurrentSetBase"/> class for most of the test 
cases.
+    /// This class specializes the tests for the <see 
cref="ConcurrentSet{T}"/> class.
+    /// </remarks>
+    public class TestConcurrentSet : TestConcurrentSetBase
+    {
+        protected override ISet<T> NewSet<T>()
+            => new ConcurrentSet<T>(new HashSet<T>());

Review Comment:
   There are 2 main benefits for having `ConcurrentSet<T>`:
   
   1. It enables concurrency on alternative set implementations, such as 
`LinkedHashSet<T>` or `OrderedHashSet<T>`.
   2. It exposes the shared lock (through the `SyncRoot` property), so external 
operations (such as atomic enumeration) can be synchronized with the rest of 
the set.
   
   > NOTE: Something smells funny about the implementation of the 
`ConcurentSet<T>.SyncRoot` property. It seems like the 
`System.Threading.Interlocked.CompareExchange<object?>(ref syncRoot, new 
object(), null);` line shouldn't be there or it should be setup to correctly 
update the value of `syncRoot` atomically.
   
   The `ConcurrentHashSet<T>` has the advantage of not locking the entire set 
so in theory, will perform better.
   
   All of that said, it seems like it would be a more useful test if the 
[`OrderedHashSet<T>`](https://github.com/NightOwl888/J2N/issues/95) were tested 
here. But since it doesn't yet exist, perhaps we could settle for 
`LinkedHashSet<T>` for now. 
   
   Better still, create another base class to provide the `ISet<T>` 
implementation to wrap with multiple subclasses to test each wrapped instance 
separately.



-- 
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: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to