pkuwm commented on a change in pull request #785: Fix the 
ConcurrentModificationException in ClusterEvent.java
URL: https://github.com/apache/helix/pull/785#discussion_r382803570
 
 

 ##########
 File path: 
helix-core/src/test/java/org/apache/helix/controller/stages/TestClusterEvent.java
 ##########
 @@ -19,16 +19,51 @@
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.List;
+
+import org.testng.Assert;
 import org.testng.AssertJUnit;
 import org.testng.annotations.Test;
 
-@Test
+
 public class TestClusterEvent {
+
   @Test
-  public void testSimplePutandGet() {
+  public void testSimplePutAndGet() {
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
     AssertJUnit.assertEquals(event.getEventType(), ClusterEventType.Unknown);
     event.addAttribute("attr1", "value");
     AssertJUnit.assertEquals(event.getAttribute("attr1"), "value");
   }
+
+  @Test
+  public void testThreadSafeClone() throws InterruptedException {
+    String clusterName = "TestCluster";
+    ClusterEvent event = new ClusterEvent(clusterName, 
ClusterEventType.Unknown, "testId");
+    for (int i = 0; i < 100; i++) {
+      event.addAttribute(String.valueOf(i), i);
+    }
+    List<Thread> threads = new ArrayList<>();
+    for (int i = 0; i < 10; i++) {
+      threads.add(new Thread(() -> {
+        String threadName = Thread.currentThread().getName();
+        event.addAttribute(threadName, threadName);
 
 Review comment:
   This is a reasonable test. Maybe to make it more accurate in this test, we 
can use a CountDownLatch as a signal right before clone().
   ```
   latch.countDown(); // Tell 10 threads to modify this the attributeMap.
   clone();
   ```
   And also add more attributes (say, 20) in each thread just to make the time 
a bit longer.
   This CountDownLatch and more attributes make sure that the attribute adding 
is not completed yet before clone().
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to