소스 검색

AMBARI-16080. Delete Service: Deleting Hive fails with 500 error - UT fix (smohanty)

Sumit Mohanty 9 년 전
부모
커밋
412af42958
1개의 변경된 파일28개의 추가작업 그리고 2개의 파일을 삭제
  1. 28 2
      ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java

+ 28 - 2
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);
+  }
 }