ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [1/8] ambari git commit: Merge branch 'branch-feature-AMBARI-18456' into trunk
Date Wed, 19 Oct 2016 19:06:05 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 68d4da47b -> f64fa7220


http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
index 434948c..4fdcc22 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
@@ -18,6 +18,21 @@
 
 package org.apache.ambari.server.state.cluster;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ServiceComponentNotFoundException;
+import org.apache.ambari.server.ServiceNotFoundException;
+import org.apache.ambari.server.events.listeners.upgrade.HostVersionOutOfSyncListener;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -34,22 +49,6 @@ import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.testing.DeadlockWarningThread;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ServiceComponentNotFoundException;
-import org.apache.ambari.server.ServiceNotFoundException;
-import org.apache.ambari.server.events.listeners.upgrade.HostVersionOutOfSyncListener;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.OrmTestHelper;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Assert;
@@ -63,8 +62,6 @@ import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.persist.PersistService;
 import com.google.inject.util.Modules;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Tests AMBARI-9368 and AMBARI-9761 which produced a deadlock during read and
@@ -144,7 +141,6 @@ public class ClusterDeadlockTest {
 
       clusters.addHost(hostName);
       setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-      clusters.getHost(hostName).persist();
       clusters.mapHostToCluster(hostName, "c1");
     }
 
@@ -256,10 +252,6 @@ public class ClusterDeadlockTest {
           "DATANODE", hostName));
     }
 
-    // !!! needed to populate some maps; without this, the cluster report
-    // won't do anything and this test will be worthless
-    ((ClusterImpl) cluster).loadServiceHostComponents();
-
     List<Thread> threads = new ArrayList<Thread>();
     for (int i = 0; i < NUMBER_OF_THREADS; i++) {
       ClusterReaderThread clusterReaderThread = new ClusterReaderThread();
@@ -590,7 +582,6 @@ public class ClusterDeadlockTest {
     sch.setDesiredStackVersion(stackId);
     sch.setStackVersion(stackId);
 
-    sch.persist();
     return sch;
   }
 
@@ -602,7 +593,6 @@ public class ClusterDeadlockTest {
     } catch (ServiceNotFoundException e) {
       service = serviceFactory.createNew(cluster, serviceName);
       cluster.addService(service);
-      service.persist();
     }
 
     return service;
@@ -618,7 +608,6 @@ public class ClusterDeadlockTest {
           componentName);
       service.addServiceComponent(serviceComponent);
       serviceComponent.setDesiredState(State.INSTALLED);
-      serviceComponent.persist();
     }
 
     return serviceComponent;

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
index 2aaa2cf..f40e0a1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
@@ -39,7 +39,9 @@ import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
+import org.apache.ambari.server.orm.entities.ConfigGroupEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.RequestScheduleEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.scheduler.ExecutionScheduler;
@@ -75,6 +77,7 @@ import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Module;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
 
 import junit.framework.Assert;
 
@@ -99,11 +102,10 @@ public class ClusterEffectiveVersionTest extends EasyMockSupport {
 
     expectClusterEntityMocks();
 
-    AmbariEventPublisher eventPublisher = createNiceMock(AmbariEventPublisher.class);
-
     replayAll();
 
-    m_cluster = new ClusterImpl(m_clusterEntity, m_injector, eventPublisher);
+    ClusterFactory clusterFactory = m_injector.getInstance(ClusterFactory.class);
+    m_cluster = clusterFactory.create(m_clusterEntity);
 
     verifyAll();
   }
@@ -227,6 +229,12 @@ public class ClusterEffectiveVersionTest extends EasyMockSupport {
         new ArrayList<ClusterServiceEntity>()).anyTimes();
     EasyMock.expect(m_clusterEntity.getClusterConfigEntities()).andReturn(
         new ArrayList<ClusterConfigEntity>()).anyTimes();
+
+    EasyMock.expect(m_clusterEntity.getConfigGroupEntities()).andReturn(
+        new ArrayList<ConfigGroupEntity>()).anyTimes();
+
+    EasyMock.expect(m_clusterEntity.getRequestScheduleEntities()).andReturn(
+        new ArrayList<RequestScheduleEntity>()).anyTimes();
   }
 
   /**
@@ -262,13 +270,16 @@ public class ClusterEffectiveVersionTest extends EasyMockSupport {
       binder.bind(PasswordEncoder.class).toInstance(EasyMock.createNiceMock(PasswordEncoder.class));
       binder.bind(KerberosHelper.class).toInstance(EasyMock.createNiceMock(KerberosHelper.class));
       binder.bind(Users.class).toInstance(EasyMock.createNiceMock(Users.class));
+      binder.bind(AmbariEventPublisher.class).toInstance(createNiceMock(AmbariEventPublisher.class));
 
+      binder.install(new FactoryModuleBuilder().implement(
+          Cluster.class, ClusterImpl.class).build(ClusterFactory.class));
 
       try {
         AmbariMetaInfo ambariMetaInfo = EasyMock.createNiceMock(AmbariMetaInfo.class);
         EasyMock.expect(
             ambariMetaInfo.getServices(EasyMock.anyString(), EasyMock.anyString())).andReturn(
-                new HashMap<String, ServiceInfo>());
+                new HashMap<String, ServiceInfo>()).anyTimes();
 
         EasyMock.replay(ambariMetaInfo);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
index aca32e4..aad074e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
@@ -18,11 +18,20 @@
 
 package org.apache.ambari.server.state.cluster;
 
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.controller.AmbariSessionManager;
@@ -35,26 +44,13 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.createMockBuilder;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.verify;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
 
 public class ClusterImplTest {
 
@@ -67,7 +63,7 @@ public class ClusterImplTest {
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
   }
-  
+
   @Test
   public void testAddSessionAttributes() throws Exception {
     Map<String, Object> attributes = new HashMap<String, Object>();
@@ -211,40 +207,30 @@ public class ClusterImplTest {
 
     Host host1 = clusters.getHost(hostName1);
     host1.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host1.persist();
 
     Host host2 = clusters.getHost(hostName2);
     host2.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host2.persist();
 
     clusters.mapHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
 
     ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
-    nameNode.persist();
-    nameNode.addServiceComponentHost(hostName1).persist();
+    nameNode.addServiceComponentHost(hostName1);
 
     ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE");
-    dataNode.persist();
-    dataNode.addServiceComponentHost(hostName1).persist();
-    dataNode.addServiceComponentHost(hostName2).persist();
+    dataNode.addServiceComponentHost(hostName1);
+    dataNode.addServiceComponentHost(hostName2);
 
     ServiceComponent hdfsClient = hdfs.addServiceComponent("HDFS_CLIENT");
-    hdfsClient.persist();
-    hdfsClient.addServiceComponentHost(hostName1).persist();
-    hdfsClient.addServiceComponentHost(hostName2).persist();
+    hdfsClient.addServiceComponentHost(hostName1);
+    hdfsClient.addServiceComponentHost(hostName2);
 
     Service tez = cluster.addService(serviceToDelete);
-    tez.persist();
 
     ServiceComponent tezClient = tez.addServiceComponent("TEZ_CLIENT");
-    tezClient.persist();
     ServiceComponentHost tezClientHost1 =  tezClient.addServiceComponentHost(hostName1);
-    tezClientHost1.persist();
     ServiceComponentHost tezClientHost2 = tezClient.addServiceComponentHost(hostName2);
-    tezClientHost2.persist();
 
     // When
     cluster.deleteService(serviceToDelete);
@@ -279,11 +265,9 @@ public class ClusterImplTest {
 
     Host host1 = clusters.getHost(hostName1);
     host1.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host1.persist();
 
     Host host2 = clusters.getHost(hostName2);
     host2.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host2.persist();
 
     clusters.mapHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
 
@@ -320,11 +304,9 @@ public class ClusterImplTest {
 
     Host host1 = clusters.getHost(hostName1);
     host1.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host1.persist();
 
     Host host2 = clusters.getHost(hostName2);
     host2.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
-    host2.persist();
 
     clusters.mapHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/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 b99277d..dcbc435 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
@@ -79,11 +79,8 @@ import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostStateEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
-import org.apache.ambari.server.orm.entities.ResourceEntity;
-import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.state.AgentVersion;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -232,41 +229,24 @@ public class ClusterTest {
 
     String clusterName = "c1";
 
-    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
-    if (resourceTypeEntity == null) {
-      resourceTypeEntity = new ResourceTypeEntity();
-      resourceTypeEntity.setId(ResourceType.CLUSTER.getId());
-      resourceTypeEntity.setName(ResourceType.CLUSTER.name());
-      resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity);
-    }
-    ResourceEntity resourceEntity = new ResourceEntity();
-    resourceEntity.setResourceType(resourceTypeEntity);
-
-    ClusterEntity clusterEntity = new ClusterEntity();
-    clusterEntity.setClusterName(clusterName);
-    clusterEntity.setResource(resourceEntity);
-    clusterEntity.setDesiredStack(stackEntity);
-    clusterDAO.create(clusterEntity);
+    clusters.addCluster(clusterName, stackId);
 
     Map<String, String> hostAttributes = new HashMap<String, String>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "5.9");
 
-    List<HostEntity> hostEntities = new ArrayList<HostEntity>();
     Set<String> hostNames = new HashSet<String>() {{ add("h1"); add("h2"); }};
     for (String hostName : hostNames) {
-      HostEntity hostEntity = new HostEntity();
-      hostEntity.setHostName(hostName);
+      clusters.addHost(hostName);
+
+      HostEntity hostEntity = hostDAO.findByName(hostName);
       hostEntity.setIpv4("ipv4");
       hostEntity.setIpv6("ipv6");
       hostEntity.setHostAttributes(gson.toJson(hostAttributes));
-      hostEntity.setClusterEntities(Arrays.asList(clusterEntity));
-      hostEntities.add(hostEntity);
-      hostDAO.create(hostEntity);
+      hostDAO.merge(hostEntity);
     }
 
-    clusterEntity.setHostEntities(hostEntities);
-    clusterDAO.merge(clusterEntity);
+    clusters.mapHostsToCluster(hostNames, clusterName);
     c1 = clusters.getCluster(clusterName);
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -403,9 +383,6 @@ public class ClusterTest {
     cluster.addService(s1);
     cluster.addService(s2);
     cluster.addService(s3);
-    s1.persist();
-    s2.persist();
-    s3.persist();
 
     // Add HDFS components
     ServiceComponent sc1CompA = serviceComponentFactory.createNew(s1, "NAMENODE");
@@ -414,25 +391,18 @@ public class ClusterTest {
     s1.addServiceComponent(sc1CompA);
     s1.addServiceComponent(sc1CompB);
     s1.addServiceComponent(sc1CompC);
-    sc1CompA.persist();
-    sc1CompB.persist();
-    sc1CompC.persist();
 
     // Add ZK
     ServiceComponent sc2CompA = serviceComponentFactory.createNew(s2, "ZOOKEEPER_SERVER");
     ServiceComponent sc2CompB = serviceComponentFactory.createNew(s2, "ZOOKEEPER_CLIENT");
     s2.addServiceComponent(sc2CompA);
     s2.addServiceComponent(sc2CompB);
-    sc2CompA.persist();
-    sc2CompB.persist();
 
     // Add Ganglia
     ServiceComponent sc3CompA = serviceComponentFactory.createNew(s3, "GANGLIA_SERVER");
     ServiceComponent sc3CompB = serviceComponentFactory.createNew(s3, "GANGLIA_MONITOR");
     s3.addServiceComponent(sc3CompA);
     s3.addServiceComponent(sc3CompB);
-    sc3CompA.persist();
-    sc3CompB.persist();
 
     // Host 1 will have all components
     ServiceComponentHost schHost1Serv1CompA = serviceComponentHostFactory.createNew(sc1CompA, "h-1");
@@ -449,26 +419,16 @@ public class ClusterTest {
     sc2CompB.addServiceComponentHost(schHost1Serv2CompB);
     sc3CompA.addServiceComponentHost(schHost1Serv3CompA);
     sc3CompB.addServiceComponentHost(schHost1Serv3CompB);
-    schHost1Serv1CompA.persist();
-    schHost1Serv1CompB.persist();
-    schHost1Serv1CompC.persist();
-    schHost1Serv2CompA.persist();
-    schHost1Serv2CompB.persist();
-    schHost1Serv3CompA.persist();
-    schHost1Serv3CompB.persist();
 
     // Host 2 will have ZK_CLIENT and GANGLIA_MONITOR
     ServiceComponentHost schHost2Serv2CompB = serviceComponentHostFactory.createNew(sc2CompB, "h-2");
     ServiceComponentHost schHost2Serv3CompB = serviceComponentHostFactory.createNew(sc3CompB, "h-2");
     sc2CompB.addServiceComponentHost(schHost2Serv2CompB);
     sc3CompB.addServiceComponentHost(schHost2Serv3CompB);
-    schHost2Serv2CompB.persist();
-    schHost2Serv3CompB.persist();
 
     // Host 3 will have GANGLIA_MONITOR
     ServiceComponentHost schHost3Serv3CompB = serviceComponentHostFactory.createNew(sc3CompB, "h-3");
     sc3CompB.addServiceComponentHost(schHost3Serv3CompB);
-    schHost3Serv3CompB.persist();
 
     // Verify count of components
     List<ServiceComponentHost> scHost1 = cluster.getServiceComponentHosts("h-1");
@@ -528,7 +488,6 @@ public class ClusterTest {
     host.setIPv4("ipv4");
     host.setIPv6("ipv6");
     host.setHostAttributes(hostAttributes);
-    host.persist();
   }
 
   /**
@@ -687,9 +646,6 @@ public class ClusterTest {
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
 
-    s1.persist();
-    s2.persist();
-
     Service s = c1.getService("HDFS");
     Assert.assertNotNull(s);
     Assert.assertEquals("HDFS", s.getName());
@@ -717,14 +673,12 @@ public class ClusterTest {
 
     Service s = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s);
-    s.persist();
     ServiceComponent sc = serviceComponentFactory.createNew(s, "NAMENODE");
     s.addServiceComponent(sc);
-    sc.persist();
+
     ServiceComponentHost sch =
         serviceComponentHostFactory.createNew(sc, "h1");
     sc.addServiceComponentHost(sch);
-    sch.persist();
 
     List<ServiceComponentHost> scHosts = c1.getServiceComponentHosts("h1");
     Assert.assertEquals(1, scHosts.size());
@@ -737,13 +691,10 @@ public class ClusterTest {
         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");
         sc1.addServiceComponentHost(sch1);
-        sch1.persist();
       }
     } catch (ConcurrentModificationException e ) {
       Assert.assertTrue("Failed to work concurrently with sch", false);
@@ -759,24 +710,18 @@ public class ClusterTest {
 
     Service s = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s);
-    s.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
     s.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE");
     s.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     List<ServiceComponentHost> scHosts;
 
@@ -793,24 +738,18 @@ public class ClusterTest {
 
     Service s = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s);
-    s.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
     s.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE");
     s.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     List<ServiceComponentHost> scHosts;
 
@@ -833,24 +772,18 @@ public class ClusterTest {
 
     Service s = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s);
-    s.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
     s.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE");
     s.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     Map<String, Set<String>> componentHostMap;
 
@@ -871,35 +804,26 @@ public class ClusterTest {
 
     Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
     c1.addService(sfHDFS);
-    sfHDFS.persist();
 
     Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
     c1.addService(sfMR);
-    sfMR.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
     sfHDFS.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE");
     sfHDFS.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER");
     sfMR.addServiceComponent(scJT);
-    scJT.persist();
     ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1");
     scJT.addServiceComponentHost(schJTH1);
-    schJTH1.persist();
 
     Map<String, Set<String>> componentHostMap;
 
@@ -936,35 +860,26 @@ public class ClusterTest {
 
     Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
     c1.addService(sfHDFS);
-    sfHDFS.persist();
 
     Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
     c1.addService(sfMR);
-    sfMR.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
     sfHDFS.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE");
     sfHDFS.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER");
     sfMR.addServiceComponent(scJT);
-    scJT.persist();
     ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1");
     scJT.addServiceComponentHost(schJTH1);
-    schJTH1.persist();
 
     Map<String, Set<String>> componentHostMap;
 
@@ -1002,35 +917,26 @@ public class ClusterTest {
 
     Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
     c1.addService(sfHDFS);
-    sfHDFS.persist();
 
     Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
     c1.addService(sfMR);
-    sfMR.persist();
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
     sfHDFS.addServiceComponent(scNN);
-    scNN.persist();
     ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1");
     scNN.addServiceComponentHost(schNNH1);
-    schNNH1.persist();
 
     ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE");
     sfHDFS.addServiceComponent(scDN);
-    scDN.persist();
     ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1");
     scDN.addServiceComponentHost(scDNH1);
-    scDNH1.persist();
     ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2");
     scDN.addServiceComponentHost(scDNH2);
-    scDNH2.persist();
 
     ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER");
     sfMR.addServiceComponent(scJT);
-    scJT.persist();
     ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1");
     scJT.addServiceComponentHost(schJTH1);
-    schJTH1.persist();
 
     Map<String, Set<String>> componentHostMap;
 
@@ -1180,7 +1086,6 @@ public class ClusterTest {
     host.setState(HostState.HEALTHY);
     host.setHealthStatus(new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, ""));
     host.setStatus(host.getHealthStatus().getHealthStatus().name());
-    host.persist();
     c1.setDesiredStackVersion(new StackId("HDP-2.0.6"));
     clusters.mapHostToCluster("h3", "c1");
 
@@ -1207,13 +1112,10 @@ public class ClusterTest {
   public void testDeleteService() throws Exception {
     createDefaultCluster();
 
-    c1.addService("MAPREDUCE").persist();
+    c1.addService("MAPREDUCE");
 
     Service hdfs = c1.addService("HDFS");
-    hdfs.persist();
     ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
-    nameNode.persist();
-
 
     assertEquals(2, c1.getServices().size());
     assertEquals(2, injector.getProvider(EntityManager.class).get().
@@ -1230,7 +1132,7 @@ public class ClusterTest {
   public void testDeleteServiceWithConfigHistory() throws Exception {
     createDefaultCluster();
 
-    c1.addService("HDFS").persist();
+    c1.addService("HDFS");
 
     Config config1 = configFactory.createNew(c1, "hdfs-site",
       new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>());
@@ -2159,9 +2061,6 @@ public class ClusterTest {
     sc2CompA.addServiceComponentHost(schHost4Serv2CompA);
     sc2CompB.addServiceComponentHost(schHost4Serv2CompB);
     sc3CompB.addServiceComponentHost(schHost4Serv3CompB);
-    schHost4Serv2CompA.persist();
-    schHost4Serv2CompB.persist();
-    schHost4Serv3CompB.persist();
 
     simulateStackVersionListener(stackId, v1, cluster, hostComponentStateDAO.findByHost("h-4"));
 
@@ -2193,7 +2092,6 @@ public class ClusterTest {
     clusters.mapHostToCluster("h-5", clusterName);
     ServiceComponentHost schHost5Serv3CompB = serviceComponentHostFactory.createNew(sc3CompB, "h-5");
     sc3CompB.addServiceComponentHost(schHost5Serv3CompB);
-    schHost5Serv3CompB.persist();
 
     // Host 5 will be in OUT_OF_SYNC, so redistribute bits to it so that it reaches a state of INSTALLED
     HostVersionEntity h5Version2 = hostVersionDAO.findByClusterStackVersionAndHost(clusterName, stackId, v2, "h-5");
@@ -2334,7 +2232,6 @@ public class ClusterTest {
       hostAttributes.put("os_family", "redhat");
       hostAttributes.put("os_release_version", "5.9");
       h.setHostAttributes(hostAttributes);
-      h.persist();
     }
 
     String v1 = "2.0.5-1";
@@ -2405,7 +2302,6 @@ public class ClusterTest {
       hostAttributes.put("os_family", "redhat");
       hostAttributes.put("os_release_version", "5.9");
       h.setHostAttributes(hostAttributes);
-      h.persist();
     }
 
     String v1 = "2.0.5-1";

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
index 190f64d..27e6e13 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
@@ -25,9 +25,6 @@ import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import com.google.inject.Provider;
-import junit.framework.Assert;
-
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ServiceComponentNotFoundException;
 import org.apache.ambari.server.ServiceNotFoundException;
@@ -57,9 +54,12 @@ import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Module;
+import com.google.inject.Provider;
 import com.google.inject.persist.PersistService;
 import com.google.inject.util.Modules;
 
+import junit.framework.Assert;
+
 /**
  * Tests AMBARI-9738 which produced a deadlock during read and writes between
  * {@link ClustersImpl} and {@link ClusterImpl}.
@@ -294,7 +294,6 @@ public class ClustersDeadlockTest {
           String hostName = "c64-" + hostNameCounter.getAndIncrement();
           clusters.addHost(hostName);
           setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-          clusters.getHost(hostName).persist();
           clusters.mapHostToCluster(hostName, CLUSTER_NAME);
 
           Thread.sleep(10);
@@ -322,7 +321,6 @@ public class ClustersDeadlockTest {
           String hostName = "c64-" + hostNameCounter.getAndIncrement();
           clusters.addHost(hostName);
           setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-          clusters.getHost(hostName).persist();
           clusters.mapHostToCluster(hostName, CLUSTER_NAME);
 
           // create DATANODE on this host so that we end up exercising the
@@ -357,7 +355,6 @@ public class ClustersDeadlockTest {
 
           clusters.addHost(hostName);
           setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-          clusters.getHost(hostName).persist();
           clusters.mapHostToCluster(hostName, CLUSTER_NAME);
         }
 
@@ -388,7 +385,6 @@ public class ClustersDeadlockTest {
     } catch (ServiceNotFoundException e) {
       service = serviceFactory.createNew(cluster, serviceName);
       cluster.addService(service);
-      service.persist();
     }
 
     return service;
@@ -404,7 +400,6 @@ public class ClustersDeadlockTest {
           componentName);
       service.addServiceComponent(serviceComponent);
       serviceComponent.setDesiredState(State.INSTALLED);
-      serviceComponent.persist();
     }
 
     return serviceComponent;
@@ -425,7 +420,6 @@ public class ClustersDeadlockTest {
     sch.setDesiredStackVersion(stackId);
     sch.setStackVersion(stackId);
 
-    sch.persist();
     return sch;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
index bb3db03..5886234 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
@@ -296,9 +296,6 @@ public class ClustersTest {
     setOsFamily(clusters.getHost(h1), "redhat", "6.4");
     setOsFamily(clusters.getHost(h2), "redhat", "5.9");
     setOsFamily(clusters.getHost(h3), "redhat", "6.4");
-    clusters.getHost(h1).persist();
-    clusters.getHost(h2).persist();
-    clusters.getHost(h3).persist();
 
     try {
         clusters.getClustersForHost(h4);
@@ -381,9 +378,6 @@ public class ClustersTest {
     setOsFamily(clusters.getHost(h1), "redhat", "6.4");
     setOsFamily(clusters.getHost(h2), "redhat", "5.9");
     setOsFamily(clusters.getHost(h3), "redhat", "6.4");
-    clusters.getHost(h1).persist();
-    clusters.getHost(h2).persist();
-    clusters.getHost(h3).persist();
     clusters.mapHostToCluster(h1, c1);
     clusters.mapHostToCluster(h2, c1);
 
@@ -435,8 +429,6 @@ public class ClustersTest {
     Host host2 = clusters.getHost(h2);
     setOsFamily(clusters.getHost(h1), "centos", "5.9");
     setOsFamily(clusters.getHost(h2), "centos", "5.9");
-    host1.persist();
-    host2.persist();
 
     clusters.mapHostsToCluster(new HashSet<String>() {
       {
@@ -446,31 +438,23 @@ public class ClustersTest {
 
     // host config override
     host1.addDesiredConfig(cluster.getClusterId(), true, "_test", config2);
-    host1.persist();
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
 
     Assert.assertNotNull(injector.getInstance(ClusterServiceDAO.class).findByClusterAndServiceNames(c1, "HDFS"));
 
     ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
-    nameNode.persist();
     ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE");
-    dataNode.persist();
 
     ServiceComponent serviceCheckNode = hdfs.addServiceComponent("HDFS_CLIENT");
-    serviceCheckNode.persist();
 
     ServiceComponentHost nameNodeHost = nameNode.addServiceComponentHost(h1);
-    nameNodeHost.persist();
     HostEntity nameNodeHostEntity = hostDAO.findByName(nameNodeHost.getHostName());
     Assert.assertNotNull(nameNodeHostEntity);
 
     ServiceComponentHost dataNodeHost = dataNode.addServiceComponentHost(h2);
-    dataNodeHost.persist();
 
     ServiceComponentHost serviceCheckNodeHost = serviceCheckNode.addServiceComponentHost(h2);
-    serviceCheckNodeHost.persist();
     serviceCheckNodeHost.setState(State.UNKNOWN);
 
     HostComponentDesiredStateEntityPK hkdspk = new HostComponentDesiredStateEntityPK();
@@ -705,7 +689,6 @@ public class ClustersTest {
 
     Host host = clusters.getHost(hostName);
     setOsFamily(clusters.getHost(hostName), "centos", "5.9");
-    host.persist();
 
     Set<String> hostnames = new HashSet<>();
     hostnames.add(hostName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
index ff5cbe8..2500a16 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
@@ -115,7 +115,6 @@ public class ConcurrentServiceConfigVersionTest {
     String hostName = "c6401.ambari.apache.org";
     clusters.addHost(hostName);
     setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-    clusters.getHost(hostName).persist();
     clusters.mapHostToCluster(hostName, "c1");
 
     Service service = installService("HDFS");
@@ -213,7 +212,6 @@ public class ConcurrentServiceConfigVersionTest {
     sch.setDesiredStackVersion(stackId);
     sch.setStackVersion(stackId);
 
-    sch.persist();
     return sch;
   }
 
@@ -225,7 +223,6 @@ public class ConcurrentServiceConfigVersionTest {
     } catch (ServiceNotFoundException e) {
       service = serviceFactory.createNew(cluster, serviceName);
       cluster.addService(service);
-      service.persist();
     }
 
     return service;
@@ -241,7 +238,6 @@ public class ConcurrentServiceConfigVersionTest {
           componentName);
       service.addServiceComponent(serviceComponent);
       serviceComponent.setDesiredState(State.INSTALLED);
-      serviceComponent.persist();
     }
 
     return serviceComponent;

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
index 7d2ba4d..1f09002 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
@@ -130,7 +130,6 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     String hostName = "c6401";
     clusters.addHost(hostName);
     setOsFamily(clusters.getHost(hostName), "redhat", "6.4");
-    clusters.getHost(hostName).persist();
     clusters.mapHostToCluster(hostName, "c1");
 
     Service service = installService("HDFS");
@@ -242,7 +241,6 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     sch.setDesiredStackVersion(stackId);
     sch.setStackVersion(stackId);
 
-    sch.persist();
     return sch;
   }
 
@@ -254,7 +252,6 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     } catch (ServiceNotFoundException e) {
       service = serviceFactory.createNew(cluster, serviceName);
       cluster.addService(service);
-      service.persist();
     }
 
     return service;
@@ -270,7 +267,6 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
           componentName);
       service.addServiceComponent(serviceComponent);
       serviceComponent.setDesiredState(State.INSTALLED);
-      serviceComponent.persist();
     }
 
     return serviceComponent;

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
index 4ff9bf4..fa8622d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
@@ -17,25 +17,21 @@
  */
 package org.apache.ambari.server.state.host;
 
-import com.google.gson.Gson;
-import com.google.inject.Injector;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostStateDAO;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostStateEntity;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.HostHealthStatus;
+import org.easymock.EasyMockSupport;
 import org.junit.Test;
 
-import java.util.Map;
-
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.*;
+import com.google.gson.Gson;
 
-public class HostImplTest {
+public class HostImplTest extends EasyMockSupport {
 
   @Test
   public void testGetHostAttributes() throws Exception {
@@ -43,36 +39,30 @@ public class HostImplTest {
     HostEntity hostEntity = createNiceMock(HostEntity.class);
     HostStateEntity hostStateEntity = createNiceMock(HostStateEntity.class);
     HostDAO hostDAO  = createNiceMock(HostDAO.class);
-    Injector injector = createNiceMock(Injector.class);
     HostStateDAO hostStateDAO  = createNiceMock(HostStateDAO.class);
 
-
     Gson gson = new Gson();
 
-    expect(injector.getInstance(Gson.class)).andReturn(gson).anyTimes();
-    expect(injector.getInstance(HostDAO.class)).andReturn(hostDAO).anyTimes();
-    expect(injector.getInstance(HostStateDAO.class)).andReturn(hostStateDAO).anyTimes();
     expect(hostEntity.getHostAttributes()).andReturn("{\"foo\": \"aaa\", \"bar\":\"bbb\"}").anyTimes();
     expect(hostEntity.getHostId()).andReturn(1L).anyTimes();
     expect(hostEntity.getHostName()).andReturn("host1").anyTimes();
     expect(hostEntity.getHostStateEntity()).andReturn(hostStateEntity).anyTimes();
-    expect(hostDAO.findById(1L)).andReturn(hostEntity).once();
-    expect(hostStateDAO.findByHostId(1L)).andReturn(hostStateEntity).once();
+    expect(hostDAO.findById(1L)).andReturn(hostEntity).atLeastOnce();
 
-    replay(hostEntity, hostStateEntity, injector, hostDAO);
-    HostImpl host = new HostImpl(hostEntity, false, injector);
+    replayAll();
+    HostImpl host = new HostImpl(hostEntity, gson, hostDAO, hostStateDAO);
 
     Map<String, String> hostAttributes = host.getHostAttributes();
     assertEquals("aaa", hostAttributes.get("foo"));
     assertEquals("bbb", hostAttributes.get("bar"));
 
-    host = new HostImpl(hostEntity, true, injector);
+    host = new HostImpl(hostEntity, gson, hostDAO, hostStateDAO);
 
     hostAttributes = host.getHostAttributes();
     assertEquals("aaa", hostAttributes.get("foo"));
     assertEquals("bbb", hostAttributes.get("bar"));
 
-    verify(hostEntity, hostStateEntity, injector, hostDAO);
+    verifyAll();
   }
 
   @Test
@@ -82,29 +72,25 @@ public class HostImplTest {
     HostStateEntity hostStateEntity = createNiceMock(HostStateEntity.class);
     HostDAO hostDAO  = createNiceMock(HostDAO.class);
     HostStateDAO hostStateDAO  = createNiceMock(HostStateDAO.class);
-    Injector injector = createNiceMock(Injector.class);
 
     Gson gson = new Gson();
 
-    expect(injector.getInstance(Gson.class)).andReturn(gson).anyTimes();
-    expect(injector.getInstance(HostDAO.class)).andReturn(hostDAO).anyTimes();
-    expect(injector.getInstance(HostStateDAO.class)).andReturn(hostStateDAO).anyTimes();
     expect(hostEntity.getHostAttributes()).andReturn("{\"foo\": \"aaa\", \"bar\":\"bbb\"}").anyTimes();
     expect(hostEntity.getHostName()).andReturn("host1").anyTimes();
     expect(hostEntity.getHostId()).andReturn(1L).anyTimes();
     expect(hostEntity.getHostStateEntity()).andReturn(hostStateEntity).anyTimes();
     expect(hostDAO.findById(1L)).andReturn(hostEntity).anyTimes();
-    expect(hostStateDAO.findByHostId(1L)).andReturn(hostStateEntity).once();
+    expect(hostStateDAO.findByHostId(1L)).andReturn(hostStateEntity).atLeastOnce();
 
-    replay(hostEntity, hostStateEntity, injector, hostDAO);
-    HostImpl host = new HostImpl(hostEntity, false, injector);
+    replayAll();
+    HostImpl host = new HostImpl(hostEntity, gson, hostDAO, hostStateDAO);
 
     host.getHealthStatus();
 
-    host = new HostImpl(hostEntity, true, injector);
+    host = new HostImpl(hostEntity, gson, hostDAO, hostStateDAO);
 
     host.getHealthStatus();
 
-    verify(hostEntity, hostStateEntity, injector, hostDAO);
+    verifyAll();
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
index 99fc0a1..596f381 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
@@ -164,9 +164,11 @@ public class HostTest {
     HostRegistrationRequestEvent e =
         new HostRegistrationRequestEvent("foo", agentVersion, currentTime,
             info, agentEnv);
+
     if (!firstReg) {
-      Assert.assertTrue(host.isPersisted());
+      Assert.assertNotNull(host.getHostId());
     }
+
     host.handleEvent(e);
     Assert.assertEquals(currentTime, host.getLastRegistrationTime());
 
@@ -378,7 +380,6 @@ public class HostTest {
     hostAttributes.put("os_release_version", "6.3");
     host.setHostAttributes(hostAttributes);
 
-    host.persist();
     c1.setDesiredStackVersion(stackId);
     clusters.mapHostToCluster("h1", "c1");
 
@@ -437,8 +438,6 @@ public class HostTest {
     hostAttributes.put("os_release_version", "6.3");
     host.setHostAttributes(hostAttributes);
 
-    host.persist();
-
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
     c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
         RepositoryVersionState.INSTALLING);
@@ -457,4 +456,19 @@ public class HostTest {
     Assert.assertNotNull(stateEntity.getMaintenanceState());
     Assert.assertEquals(MaintenanceState.ON, host.getMaintenanceState(c1.getClusterId()));
   }
+
+  @Test
+  public void testHostPersist() throws Exception {
+    clusters.addHost("foo");
+    Host host = clusters.getHost("foo");
+
+    String rackInfo = "rackInfo";
+    long lastRegistrationTime = System.currentTimeMillis();
+
+    host.setRackInfo(rackInfo);
+    host.setLastRegistrationTime(lastRegistrationTime);
+
+    Assert.assertEquals(rackInfo, host.getRackInfo());
+    Assert.assertEquals(lastRegistrationTime, host.getLastRegistrationTime());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index 243cb4f..14a8de6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -150,7 +150,6 @@ public class ServiceComponentHostTest {
       clusters.addHost(hostName);
       Host host = clusters.getHost(hostName);
       host.setHostAttributes(hostAttributes);
-      host.persist();
     }
 
     clusterEntity.setHostEntities(hostEntities);
@@ -183,7 +182,6 @@ public class ServiceComponentHostTest {
           + ", serviceName=" + svc);
       s = serviceFactory.createNew(c, svc);
       c.addService(s);
-      s.persist();
     }
 
     ServiceComponent sc = null;
@@ -192,14 +190,11 @@ public class ServiceComponentHostTest {
     } catch (ServiceComponentNotFoundException e) {
       sc = serviceComponentFactory.createNew(s, svcComponent);
       s.addServiceComponent(sc);
-      sc.persist();
     }
 
     ServiceComponentHost impl = serviceComponentHostFactory.createNew(
         sc, hostName);
 
-    impl.persist();
-
     Assert.assertEquals(State.INIT, impl.getState());
     Assert.assertEquals(State.INIT, impl.getDesiredState());
     Assert.assertEquals(SecurityState.UNSECURED, impl.getSecurityState());

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
index 387205d..f9dd5d1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java
@@ -18,12 +18,18 @@
 package org.apache.ambari.server.update;
 
 
-import com.google.gson.JsonObject;
-import com.google.gson.JsonPrimitive;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import junit.framework.Assert;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -51,18 +57,13 @@ import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.junit.Test;
 
-import javax.persistence.EntityManager;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
 
-import static org.easymock.EasyMock.anyString;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
+import junit.framework.Assert;
 
 public class HostUpdateHelperTest {
 
@@ -217,8 +218,6 @@ public class HostUpdateHelperTest {
     ClusterConfigEntity mockClusterConfigEntity3 = easyMockSupport.createNiceMock(ClusterConfigEntity.class);
     ClusterConfigEntity mockClusterConfigEntity4 = easyMockSupport.createNiceMock(ClusterConfigEntity.class);
     StackEntity mockStackEntity = easyMockSupport.createNiceMock(StackEntity.class);
-    ReadWriteLock mockReadWriteLock = easyMockSupport.createNiceMock(ReadWriteLock.class);
-    Lock mockLock = easyMockSupport.createNiceMock(Lock.class);
     Map<String, Map<String, String>> clusterHostsToChange = new HashMap<>();
     Map<String, String> hosts = new HashMap<>();
     List<ClusterConfigEntity> clusterConfigEntities1 = new ArrayList<>();
@@ -254,11 +253,8 @@ public class HostUpdateHelperTest {
     expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
 
     expect(mockClusters.getCluster("cl1")).andReturn(mockCluster).once();
-    expect(mockCluster.getClusterGlobalLock()).andReturn(mockReadWriteLock).atLeastOnce();
     expect(mockCluster.getClusterId()).andReturn(1L).atLeastOnce();
 
-    expect(mockReadWriteLock.writeLock()).andReturn(mockLock).atLeastOnce();
-
     expect(mockClusterEntity1.getClusterConfigEntities()).andReturn(clusterConfigEntities1).atLeastOnce();
     expect(mockClusterEntity2.getClusterConfigEntities()).andReturn(clusterConfigEntities2).atLeastOnce();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f64fa722/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
index 5d39841..29f40fb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
@@ -73,7 +73,6 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.cluster.ClusterFactory;
-import org.apache.ambari.server.state.cluster.ClustersImpl;
 import org.apache.ambari.server.state.host.HostFactory;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.ambari.server.topology.PersistedState;
@@ -117,7 +116,7 @@ public class StageUtilsTest extends EasyMockSupport {
         bind(CredentialStoreService.class).toInstance(createNiceMock(CredentialStoreService.class));
         bind(TopologyManager.class).toInstance(createNiceMock(TopologyManager.class));
         bind(AmbariMetaInfo.class).toInstance(createMock(AmbariMetaInfo.class));
-        bind(Clusters.class).toInstance(createNiceMock(ClustersImpl.class));
+        bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
         bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
         bind(ServiceComponentHostFactory.class).toInstance(createNiceMock(ServiceComponentHostFactory.class));
         bind(StageFactory.class).to(StageFactoryImpl.class);


Mime
View raw message