ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject git commit: AMBARI-3703. ConcurrentModificationException in Ambari Server log. (odiachenko)
Date Wed, 06 Nov 2013 14:34:36 GMT
Updated Branches:
  refs/heads/trunk a13cb6247 -> 08d5fcff9


AMBARI-3703. ConcurrentModificationException in Ambari Server log. (odiachenko)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/08d5fcff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/08d5fcff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/08d5fcff

Branch: refs/heads/trunk
Commit: 08d5fcff9bf02c75424d7c02aeb802bbbba4ad26
Parents: a13cb62
Author: Oleksandr Diachenko <odiachenko@hortonworks.com>
Authored: Wed Nov 6 16:34:10 2013 +0200
Committer: Oleksandr Diachenko <odiachenko@hortonworks.com>
Committed: Wed Nov 6 16:34:10 2013 +0200

----------------------------------------------------------------------
 .../server/state/cluster/ClusterImpl.java       |  4 +--
 .../server/state/cluster/ClusterTest.java       | 27 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/08d5fcff/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 5d97691..fb897c9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -68,6 +68,7 @@ import java.util.TreeMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 public class ClusterImpl implements Cluster {
 
@@ -621,8 +622,7 @@ public class ClusterImpl implements Cluster {
       readLock.lock();
       try {
         if (serviceComponentHostsByHost.containsKey(hostname)) {
-          return Collections.unmodifiableList(
-              serviceComponentHostsByHost.get(hostname));
+          return new CopyOnWriteArrayList<ServiceComponentHost>(serviceComponentHostsByHost.get(hostname));
         }
         return new ArrayList<ServiceComponentHost>();
       } finally {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/08d5fcff/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index 548ee45..e55b280 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -27,7 +27,9 @@ import static org.mockito.Mockito.when;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.ConcurrentModificationException;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -44,10 +46,8 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ClusterResponse;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
 import org.apache.ambari.server.orm.entities.*;
 import org.apache.ambari.server.state.*;
-import org.apache.ambari.server.state.DesiredConfig.HostOverride;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
 import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
@@ -272,6 +272,29 @@ public class ClusterTest {
 
     List<ServiceComponentHost> scHosts = c1.getServiceComponentHosts("h1");
     Assert.assertEquals(1, scHosts.size());
+    
+    Iterator<ServiceComponentHost> iterator = scHosts.iterator();
+    
+    //Try to iterate on sch and modify it in loop
+    try {
+      while (iterator.hasNext()) {
+        iterator.next();
+        Service s1 = serviceFactory.createNew(c1, "PIG");
+        c1.addService(s1);
+        s1.persist();
+        ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "PIG");
+        s1.addServiceComponent(sc1);
+        sc1.persist();
+        ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, "h1", false);
+        sc1.addServiceComponentHost(sch1);
+        sch1.persist();
+      }
+    } catch (ConcurrentModificationException e ) {
+      Assert.assertTrue("Failed to work concurrently with sch", false);
+    }
+    
+    scHosts = c1.getServiceComponentHosts("h1");
+    Assert.assertEquals(2, scHosts.size());
   }
 
 


Mime
View raw message