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

 ##########
 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:
   Actually, one additional thread is good enough if it's adding, say, 100 
items into the map. It reduces the cost of thread consumptions by test class.

----------------------------------------------------------------
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