Repository: ambari Updated Branches: refs/heads/trunk 3024c43bd -> 412af4295
AMBARI-16080. Delete Service: Deleting Hive fails with 500 error - UT fix (smohanty) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/412af429 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/412af429 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/412af429 Branch: refs/heads/trunk Commit: 412af4295842302233a30279f928226e23b7d356 Parents: 3024c43 Author: Sumit Mohanty <[email protected]> Authored: Sun Apr 24 11:03:54 2016 -0700 Committer: Sumit Mohanty <[email protected]> Committed: Sun Apr 24 11:03:54 2016 -0700 ---------------------------------------------------------------------- .../apache/ambari/server/state/ServiceTest.java | 30 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/412af429/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java index a16ac7b..79fe0e9 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java @@ -51,6 +51,7 @@ public class ServiceTest { private Injector injector; private ServiceFactory serviceFactory; private ServiceComponentFactory serviceComponentFactory; + private ServiceComponentHostFactory serviceComponentHostFactory; private AmbariMetaInfo metaInfo; @Before @@ -61,6 +62,8 @@ public class ServiceTest { serviceFactory = injector.getInstance(ServiceFactory.class); serviceComponentFactory = injector.getInstance( ServiceComponentFactory.class); + serviceComponentHostFactory = injector.getInstance( + ServiceComponentHostFactory.class); metaInfo = injector.getInstance(AmbariMetaInfo.class); clusterName = "foo"; clusters.addCluster(clusterName, new StackId("HDP-0.1")); @@ -279,8 +282,14 @@ public class ServiceTest { org.junit.Assert.assertTrue(service.canBeRemoved()); } - // can't remove a STARTED component - component.setDesiredState(State.STARTED); + // can remove a STARTED component as whether a service can be removed + // is ultimately decided based on if the host components can be removed + component.setDesiredState(State.INSTALLED); + addHostToCluster("h1", service.getCluster().getClusterName()); + ServiceComponentHost sch = serviceComponentHostFactory.createNew(component, "h1"); + component.addServiceComponentHost(sch); + sch.setDesiredState(State.STARTED); + sch.setState(State.STARTED); for (State state : State.values()) { service.setDesiredState(state); @@ -353,4 +362,21 @@ public class ServiceTest { } } } + + private void addHostToCluster(String hostname, + String clusterName) throws AmbariException { + clusters.addHost(hostname); + Host h = clusters.getHost(hostname); + h.setIPv4(hostname + "ipv4"); + h.setIPv6(hostname + "ipv6"); + + Map<String, String> hostAttributes = new HashMap<String, String>(); + hostAttributes.put("os_family", "redhat"); + hostAttributes.put("os_release_version", "6.3"); + h.setHostAttributes(hostAttributes); + + + h.persist(); + clusters.mapHostToCluster(hostname, clusterName); + } }
